001/*
002 * Copyright 2009-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2009-2024 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) 2009-2024 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.NotNull;
050import com.unboundid.util.StaticUtils;
051import com.unboundid.util.ThreadSafety;
052import com.unboundid.util.ThreadSafetyLevel;
053import com.unboundid.util.Validator;
054
055import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
056
057
058
059/**
060 * This class provides a data structure for holding a value included in the
061 * stream proxy values intermediate response.  It contains the value, and the ID
062 * of the backend set with which the value is associated.
063 * <BR>
064 * <BLOCKQUOTE>
065 *   <B>NOTE:</B>  This class, and other classes within the
066 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
067 *   supported for use against Ping Identity, UnboundID, and
068 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
069 *   for proprietary functionality or for external specifications that are not
070 *   considered stable or mature enough to be guaranteed to work in an
071 *   interoperable way with other types of LDAP servers.
072 * </BLOCKQUOTE>
073 */
074@NotMutable()
075@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
076public final class StreamProxyValuesBackendSetValue
077       implements Serializable
078{
079  /**
080   * The serial version UID for this serializable class.
081   */
082  private static final long serialVersionUID = -799860937140238448L;
083
084
085
086  // The backend set ID for this backend set value.
087  @NotNull private final ASN1OctetString backendSetID;
088
089  // The value for this backend set value.
090  @NotNull private final ASN1OctetString value;
091
092
093
094  /**
095   * Creates a new stream proxy values backend set value object with the
096   * provided information.
097   *
098   * @param  backendSetID  The backend set ID for this backend set value.  It
099   *                       must not be {@code null}.
100   * @param  value         The value for this backend set value.  It must not be
101   *                       {@code null}.
102   */
103  public StreamProxyValuesBackendSetValue(
104              @NotNull final ASN1OctetString backendSetID,
105              @NotNull final ASN1OctetString value)
106  {
107    Validator.ensureNotNull(backendSetID, value);
108
109    this.backendSetID = backendSetID;
110    this.value        = value;
111  }
112
113
114
115  /**
116   * Retrieves the backend set ID for this backend set value.
117   *
118   * @return  The backend set ID for this backend set value.
119   */
120  @NotNull()
121  public ASN1OctetString getBackendSetID()
122  {
123    return backendSetID;
124  }
125
126
127
128  /**
129   * Retrieves the value for this backend set value.
130   *
131   * @return  The value for this backend set value.
132   */
133  @NotNull()
134  public ASN1OctetString getValue()
135  {
136    return value;
137  }
138
139
140
141  /**
142   * Encodes this backend set value in a form suitable for inclusion in a stream
143   * proxy values intermediate response.
144   *
145   * @return  An ASN.1 element containing the encoded representation of this
146   *          stream proxy values backend set value.
147   */
148  @NotNull()
149  public ASN1Element encode()
150  {
151    return new ASN1Sequence(backendSetID, value);
152  }
153
154
155
156  /**
157   * Decodes the provided ASN.1 element as a stream proxy values backend set
158   * value.
159   *
160   * @param  element  The ASN.1 element to be decoded as a stream proxy values
161   *                  backend set value.
162   *
163   * @return  The decoded stream proxy values backend set value.
164   *
165   * @throws  LDAPException  If a problem occurs while attempting to decode the
166   *                         provided ASN.1 element as a stream proxy values
167   *                         backend set value.
168   */
169  @NotNull()
170  public static StreamProxyValuesBackendSetValue decode(
171                     @NotNull final ASN1Element element)
172         throws LDAPException
173  {
174    try
175    {
176      final ASN1Element[] elements =
177           ASN1Sequence.decodeAsSequence(element).elements();
178      return new StreamProxyValuesBackendSetValue(
179           ASN1OctetString.decodeAsOctetString(elements[0]),
180           ASN1OctetString.decodeAsOctetString(elements[1]));
181    }
182    catch (final Exception e)
183    {
184      Debug.debugException(e);
185      throw new LDAPException(ResultCode.DECODING_ERROR,
186           ERR_STREAM_PROXY_VALUES_BACKEND_SET_VALUE_CANNOT_DECODE.get(
187                StaticUtils.getExceptionMessage(e)), e);
188    }
189  }
190
191
192
193  /**
194   * Retrieves a string representation of this backend set value.
195   *
196   * @return  A string representation of this backend set value.
197   */
198  @Override()
199  @NotNull()
200  public String toString()
201  {
202    final StringBuilder buffer = new StringBuilder();
203    toString(buffer);
204    return buffer.toString();
205  }
206
207
208
209  /**
210   * Appends a string representation of this backend set value to the provided
211   * buffer.
212   *
213   * @param  buffer  The buffer to which the string representation should be
214   *                 appended.
215   */
216  public void toString(@NotNull final StringBuilder buffer)
217  {
218    buffer.append("StreamProxyValuesBackendSetValue(backendSetID=");
219    backendSetID.toString(buffer);
220    buffer.append(", value=");
221    value.toString(buffer);
222    buffer.append(')');
223  }
224}