001 /*
002 * Copyright 2009-2015 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2015 UnboundID Corp.
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 */
021 package com.unboundid.ldap.sdk.unboundidds.extensions;
022
023
024
025 import java.io.Serializable;
026
027 import com.unboundid.asn1.ASN1OctetString;
028 import com.unboundid.asn1.ASN1Element;
029 import com.unboundid.asn1.ASN1Sequence;
030 import com.unboundid.ldap.sdk.LDAPException;
031 import com.unboundid.ldap.sdk.ResultCode;
032 import com.unboundid.util.NotMutable;
033 import com.unboundid.util.ThreadSafety;
034 import com.unboundid.util.ThreadSafetyLevel;
035
036 import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
037 import static com.unboundid.util.Debug.*;
038 import static com.unboundid.util.StaticUtils.*;
039 import static com.unboundid.util.Validator.*;
040
041
042
043 /**
044 * <BLOCKQUOTE>
045 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID
046 * LDAP SDK for Java. It is not available for use in applications that
047 * include only the Standard Edition of the LDAP SDK, and is not supported for
048 * use in conjunction with non-UnboundID products.
049 * </BLOCKQUOTE>
050 * This class provides a data structure for holding a value included in the
051 * stream proxy values intermediate response. It contains the value, and the ID
052 * of the backend set with which the value is associated.
053 */
054 @NotMutable()
055 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
056 public final class StreamProxyValuesBackendSetValue
057 implements Serializable
058 {
059 /**
060 * The serial version UID for this serializable class.
061 */
062 private static final long serialVersionUID = -799860937140238448L;
063
064
065
066 // The backend set ID for this backend set value.
067 private final ASN1OctetString backendSetID;
068
069 // The value for this backend set value.
070 private final ASN1OctetString value;
071
072
073
074 /**
075 * Creates a new stream proxy values backend set value object with the
076 * provided information.
077 *
078 * @param backendSetID The backend set ID for this backend set value. It
079 * must not be {@code null}.
080 * @param value The value for this backend set value. It must not be
081 * {@code null}.
082 */
083 public StreamProxyValuesBackendSetValue(final ASN1OctetString backendSetID,
084 final ASN1OctetString value)
085 {
086 ensureNotNull(backendSetID, value);
087
088 this.backendSetID = backendSetID;
089 this.value = value;
090 }
091
092
093
094 /**
095 * Retrieves the backend set ID for this backend set value.
096 *
097 * @return The backend set ID for this backend set value.
098 */
099 public ASN1OctetString getBackendSetID()
100 {
101 return backendSetID;
102 }
103
104
105
106 /**
107 * Retrieves the value for this backend set value.
108 *
109 * @return The value for this backend set value.
110 */
111 public ASN1OctetString getValue()
112 {
113 return value;
114 }
115
116
117
118 /**
119 * Encodes this backend set value in a form suitable for inclusion in a stream
120 * proxy values intermediate response.
121 *
122 * @return An ASN.1 element containing the encoded representation of this
123 * stream proxy values backend set value.
124 */
125 public ASN1Element encode()
126 {
127 return new ASN1Sequence(backendSetID, value);
128 }
129
130
131
132 /**
133 * Decodes the provided ASN.1 element as a stream proxy values backend set
134 * value.
135 *
136 * @param element The ASN.1 element to be decoded as a stream proxy values
137 * backend set value.
138 *
139 * @return The decoded stream proxy values backend set value.
140 *
141 * @throws LDAPException If a problem occurs while attempting to decode the
142 * provided ASN.1 element as a stream proxy values
143 * backend set value.
144 */
145 public static StreamProxyValuesBackendSetValue decode(
146 final ASN1Element element)
147 throws LDAPException
148 {
149 try
150 {
151 final ASN1Element[] elements =
152 ASN1Sequence.decodeAsSequence(element).elements();
153 return new StreamProxyValuesBackendSetValue(
154 ASN1OctetString.decodeAsOctetString(elements[0]),
155 ASN1OctetString.decodeAsOctetString(elements[1]));
156 }
157 catch (Exception e)
158 {
159 debugException(e);
160 throw new LDAPException(ResultCode.DECODING_ERROR,
161 ERR_STREAM_PROXY_VALUES_BACKEND_SET_VALUE_CANNOT_DECODE.get(
162 getExceptionMessage(e)), e);
163 }
164 }
165
166
167
168 /**
169 * Retrieves a string representation of this backend set value.
170 *
171 * @return A string representation of this backend set value.
172 */
173 @Override()
174 public String toString()
175 {
176 final StringBuilder buffer = new StringBuilder();
177 toString(buffer);
178 return buffer.toString();
179 }
180
181
182
183 /**
184 * Appends a string representation of this backend set value to the provided
185 * buffer.
186 *
187 * @param buffer The buffer to which the string representation should be
188 * appended.
189 */
190 public void toString(final StringBuilder buffer)
191 {
192 buffer.append("StreamProxyValuesBackendSetValue(backendSetID=");
193 backendSetID.toString(buffer);
194 buffer.append(", value=");
195 value.toString(buffer);
196 buffer.append(')');
197 }
198 }