001 /*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License"). You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.types;
028
029
030
031 import org.opends.server.protocols.asn1.ASN1OctetString;
032
033
034
035
036 /**
037 * This class defines a data structure that holds information about a
038 * control that can be included in a request or response.
039 */
040 @org.opends.server.types.PublicAPI(
041 stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
042 mayInstantiate=true,
043 mayExtend=true,
044 mayInvoke=true)
045 public class Control
046 {
047 // The value for this control.
048 private ASN1OctetString value;
049
050 // The criticality for this control.
051 private boolean isCritical;
052
053 // The OID for this control.
054 private String oid;
055
056
057
058 /**
059 * Creates a new control with no value.
060 *
061 * @param oid The OID for this control.
062 * @param isCritical Indicates whether this control should be
063 * considered critical in processing the
064 * request.
065 */
066 public Control(String oid, boolean isCritical)
067 {
068 this.oid = oid;
069 this.isCritical = isCritical;
070 this.value = null;
071 }
072
073
074
075 /**
076 * Creates a new control with the specified information.
077 *
078 * @param oid The OID for this control.
079 * @param isCritical Indicates whether this control should be
080 * considered critical in processing the
081 * request.
082 * @param value The value for this control.
083 */
084 public Control(String oid, boolean isCritical,
085 ASN1OctetString value)
086 {
087 this.oid = oid;
088 this.isCritical = isCritical;
089 this.value = value;
090 }
091
092
093
094 /**
095 * Retrieves the OID for this control.
096 *
097 * @return The OID for this control.
098 */
099 public final String getOID()
100 {
101 return oid;
102 }
103
104
105
106 /**
107 * Specifies the OID for this control.
108 *
109 * @param oid The OID for this control.
110 */
111 public final void setOID(String oid)
112 {
113 this.oid = oid;
114 }
115
116
117
118 /**
119 * Indicates whether this control should be considered critical in
120 * processing the request.
121 *
122 * @return <CODE>true</CODE> if this code should be considered
123 * critical, or <CODE>false</CODE> if not.
124 */
125 public final boolean isCritical()
126 {
127 return isCritical;
128 }
129
130
131
132 /**
133 * Specifies whether this control should be considered critical in
134 * processing the request.
135 *
136 * @param isCritical Specifies whether this control should be
137 * considered critical in processing the
138 * request.
139 */
140 public final void setCritical(boolean isCritical)
141 {
142 this.isCritical = isCritical;
143 }
144
145
146
147 /**
148 * Retrieves the value for this control.
149 *
150 * @return The value for this control, or <CODE>null</CODE> if
151 * there is no value.
152 */
153 public final ASN1OctetString getValue()
154 {
155 return value;
156 }
157
158
159
160 /**
161 * Indicates whether this control has a value.
162 *
163 * @return <CODE>true</CODE> if this control has a value, or
164 * <CODE>false</CODE> if it does not.
165 */
166 public final boolean hasValue()
167 {
168 return (value != null);
169 }
170
171
172
173 /**
174 * Specifies the value for this control.
175 *
176 * @param value The value for this control.
177 */
178 public final void setValue(ASN1OctetString value)
179 {
180 this.value = value;
181 }
182
183
184
185 /**
186 * Retrieves a string representation of this control.
187 *
188 * @return A string representation of this control.
189 */
190 public String toString()
191 {
192 StringBuilder buffer = new StringBuilder();
193 toString(buffer);
194 return buffer.toString();
195 }
196
197
198
199 /**
200 * Appends a string representation of this control to the provided
201 * buffer.
202 *
203 * @param buffer The buffer to which the information should be
204 * appended.
205 */
206 public void toString(StringBuilder buffer)
207 {
208 buffer.append("Control(oid=");
209 buffer.append(oid);
210 buffer.append(",isCritical=");
211 buffer.append(isCritical);
212
213 if (value != null)
214 {
215 buffer.append(",value=");
216 value.toString(buffer);
217 }
218
219 buffer.append(")");
220 }
221 }
222