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 java.util.ArrayList;
032    import java.util.Iterator;
033    import java.util.List;
034    
035    import org.opends.server.protocols.asn1.ASN1OctetString;
036    
037    
038    
039    
040    /**
041     * This class defines a data structure for holding information that
042     * may be sent to the client in the form of an intermediate response.
043     * It may contain an OID, value, and/or set of controls.
044     */
045    @org.opends.server.types.PublicAPI(
046         stability=org.opends.server.types.StabilityLevel.VOLATILE,
047         mayInstantiate=true,
048         mayExtend=false,
049         mayInvoke=true)
050    public final class IntermediateResponse
051    {
052      // The value for this intermediate response.
053      private ASN1OctetString value;
054    
055      // The set of controls for this intermediate response.
056      private List<Control> controls;
057    
058      // The operation with which this intermediate response is
059      // associated.
060      private Operation operation;
061    
062      // The OID for this intermediate response.
063      private String oid;
064    
065    
066    
067      /**
068       * Creates a new intermediate response with the provided
069       * information.
070       *
071       * @param  operation  The operation with which this intermediate
072       *                    response is associated.
073       * @param  oid        The OID for this intermediate response.
074       * @param  value      The value for this intermediate response.
075       * @param  controls   The set of controls to for this intermediate
076       *                    response.
077       */
078      public IntermediateResponse(Operation operation, String oid,
079                                  ASN1OctetString value,
080                                  List<Control> controls)
081      {
082        this.operation = operation;
083        this.oid       = oid;
084        this.value     = value;
085    
086        if (controls == null)
087        {
088          this.controls = new ArrayList<Control>(0);
089        }
090        else
091        {
092          this.controls = controls;
093        }
094      }
095    
096    
097    
098      /**
099       * Retrieves the operation with which this intermediate response
100       * message is associated.
101       *
102       * @return  The operation with which this intermediate response
103       *          message is associated.
104       */
105      public Operation getOperation()
106      {
107        return operation;
108      }
109    
110    
111    
112      /**
113       * Retrieves the OID for this intermediate response.
114       *
115       * @return  The OID for this intermediate response, or
116       *          <CODE>null</CODE> if there is none.
117       */
118      public String getOID()
119      {
120        return oid;
121      }
122    
123    
124    
125      /**
126       * Specifies the OID for this intermediate response.
127       *
128       * @param  oid  The OID for this intermediate response.
129       */
130      public void setOID(String oid)
131      {
132        this.oid = oid;
133      }
134    
135    
136    
137      /**
138       * Retrieves the value for this intermediate response.
139       *
140       * @return  The value for this intermediate response, or
141       *          <CODE>null</CODE> if there is none.
142       */
143      public ASN1OctetString getValue()
144      {
145        return value;
146      }
147    
148    
149    
150      /**
151       * Specifies the value for this intermediate response.
152       *
153       * @param  value  The value for this intermediate response.
154       */
155      public void setValue(ASN1OctetString value)
156      {
157        this.value = value;
158      }
159    
160    
161    
162      /**
163       * Retrieves the set of controls for this intermediate response.
164       * The contents of the list may be altered by intermediate response
165       * plugins.
166       *
167       * @return  The set of controls for this intermediate response.
168       */
169      public List<Control> getControls()
170      {
171        return controls;
172      }
173    
174    
175    
176      /**
177       * Retrieves a string representation of this intermediate response.
178       *
179       * @return  A string representation of this intermediate response.
180       */
181      public String toString()
182      {
183        StringBuilder buffer = new StringBuilder();
184        toString(buffer);
185        return buffer.toString();
186      }
187    
188    
189    
190      /**
191       * Appends a string representation of this intermediate response to
192       * the provided buffer.
193       *
194       * @param  buffer  The buffer to which the information should be
195       *                 appended.
196       */
197      public void toString(StringBuilder buffer)
198      {
199        buffer.append("IntermediateResponse(operation=");
200        operation.toString(buffer);
201        buffer.append(",oid=");
202        buffer.append(String.valueOf(oid));
203        buffer.append(",value=");
204        buffer.append(String.valueOf(buffer));
205    
206        if (! controls.isEmpty())
207        {
208          buffer.append(",controls={");
209    
210          Iterator<Control> iterator = controls.iterator();
211          iterator.next().toString(buffer);
212    
213          while (iterator.hasNext())
214          {
215            buffer.append(",");
216            iterator.next().toString(buffer);
217          }
218    
219          buffer.append("}");
220        }
221    
222        buffer.append(")");
223      }
224    }
225