001/*
002 * Copyright 2009-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.unboundidds.extensions;
022
023
024
025import java.io.Serializable;
026
027import com.unboundid.asn1.ASN1OctetString;
028import com.unboundid.asn1.ASN1Element;
029import com.unboundid.asn1.ASN1Sequence;
030import com.unboundid.ldap.sdk.LDAPException;
031import com.unboundid.ldap.sdk.ResultCode;
032import com.unboundid.util.NotMutable;
033import com.unboundid.util.ThreadSafety;
034import com.unboundid.util.ThreadSafetyLevel;
035
036import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
037import static com.unboundid.util.Debug.*;
038import static com.unboundid.util.StaticUtils.*;
039import static com.unboundid.util.Validator.*;
040
041
042
043/**
044 * This class provides a data structure for holding a value included in the
045 * stream proxy values intermediate response.  It contains the value, and the ID
046 * of the backend set with which the value is associated.
047 * <BR>
048 * <BLOCKQUOTE>
049 *   <B>NOTE:</B>  This class, and other classes within the
050 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
051 *   supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661
052 *   server products.  These classes provide support for proprietary
053 *   functionality or for external specifications that are not considered stable
054 *   or mature enough to be guaranteed to work in an interoperable way with
055 *   other types of LDAP servers.
056 * </BLOCKQUOTE>
057 */
058@NotMutable()
059@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
060public final class StreamProxyValuesBackendSetValue
061       implements Serializable
062{
063  /**
064   * The serial version UID for this serializable class.
065   */
066  private static final long serialVersionUID = -799860937140238448L;
067
068
069
070  // The backend set ID for this backend set value.
071  private final ASN1OctetString backendSetID;
072
073  // The value for this backend set value.
074  private final ASN1OctetString value;
075
076
077
078  /**
079   * Creates a new stream proxy values backend set value object with the
080   * provided information.
081   *
082   * @param  backendSetID  The backend set ID for this backend set value.  It
083   *                       must not be {@code null}.
084   * @param  value         The value for this backend set value.  It must not be
085   *                       {@code null}.
086   */
087  public StreamProxyValuesBackendSetValue(final ASN1OctetString backendSetID,
088                                          final ASN1OctetString value)
089  {
090    ensureNotNull(backendSetID, value);
091
092    this.backendSetID = backendSetID;
093    this.value        = value;
094  }
095
096
097
098  /**
099   * Retrieves the backend set ID for this backend set value.
100   *
101   * @return  The backend set ID for this backend set value.
102   */
103  public ASN1OctetString getBackendSetID()
104  {
105    return backendSetID;
106  }
107
108
109
110  /**
111   * Retrieves the value for this backend set value.
112   *
113   * @return  The value for this backend set value.
114   */
115  public ASN1OctetString getValue()
116  {
117    return value;
118  }
119
120
121
122  /**
123   * Encodes this backend set value in a form suitable for inclusion in a stream
124   * proxy values intermediate response.
125   *
126   * @return  An ASN.1 element containing the encoded representation of this
127   *          stream proxy values backend set value.
128   */
129  public ASN1Element encode()
130  {
131    return new ASN1Sequence(backendSetID, value);
132  }
133
134
135
136  /**
137   * Decodes the provided ASN.1 element as a stream proxy values backend set
138   * value.
139   *
140   * @param  element  The ASN.1 element to be decoded as a stream proxy values
141   *                  backend set value.
142   *
143   * @return  The decoded stream proxy values backend set value.
144   *
145   * @throws  LDAPException  If a problem occurs while attempting to decode the
146   *                         provided ASN.1 element as a stream proxy values
147   *                         backend set value.
148   */
149  public static StreamProxyValuesBackendSetValue decode(
150                                                      final ASN1Element element)
151         throws LDAPException
152  {
153    try
154    {
155      final ASN1Element[] elements =
156           ASN1Sequence.decodeAsSequence(element).elements();
157      return new StreamProxyValuesBackendSetValue(
158           ASN1OctetString.decodeAsOctetString(elements[0]),
159           ASN1OctetString.decodeAsOctetString(elements[1]));
160    }
161    catch (final Exception e)
162    {
163      debugException(e);
164      throw new LDAPException(ResultCode.DECODING_ERROR,
165           ERR_STREAM_PROXY_VALUES_BACKEND_SET_VALUE_CANNOT_DECODE.get(
166                getExceptionMessage(e)), e);
167    }
168  }
169
170
171
172  /**
173   * Retrieves a string representation of this backend set value.
174   *
175   * @return  A string representation of this backend set value.
176   */
177  @Override()
178  public String toString()
179  {
180    final StringBuilder buffer = new StringBuilder();
181    toString(buffer);
182    return buffer.toString();
183  }
184
185
186
187  /**
188   * Appends a string representation of this backend set value to the provided
189   * buffer.
190   *
191   * @param  buffer  The buffer to which the string representation should be
192   *                 appended.
193   */
194  public void toString(final StringBuilder buffer)
195  {
196    buffer.append("StreamProxyValuesBackendSetValue(backendSetID=");
197    backendSetID.toString(buffer);
198    buffer.append(", value=");
199    value.toString(buffer);
200    buffer.append(')');
201  }
202}