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