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 legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.server.types;
028
029import org.forgerock.opendj.ldap.ByteString;
030import java.util.ArrayList;
031import java.util.Iterator;
032import java.util.List;
033
034
035
036
037/**
038 * This class defines a data structure for holding information that
039 * may be sent to the client in the form of an intermediate response.
040 * It may contain an OID, value, and/or set of controls.
041 */
042@org.opends.server.types.PublicAPI(
043     stability=org.opends.server.types.StabilityLevel.VOLATILE,
044     mayInstantiate=true,
045     mayExtend=false,
046     mayInvoke=true)
047public final class IntermediateResponse
048{
049  /** The value for this intermediate response. */
050  private ByteString value;
051
052  /** The set of controls for this intermediate response. */
053  private List<Control> controls;
054
055  /** The operation with which this intermediate response is associated. */
056  private Operation operation;
057
058  /** The OID for this intermediate response. */
059  private String oid;
060
061
062
063  /**
064   * Creates a new intermediate response with the provided
065   * information.
066   *
067   * @param  operation  The operation with which this intermediate
068   *                    response is associated.
069   * @param  oid        The OID for this intermediate response.
070   * @param  value      The value for this intermediate response.
071   * @param  controls   The set of controls to for this intermediate
072   *                    response.
073   */
074  public IntermediateResponse(Operation operation, String oid,
075                              ByteString value,
076                              List<Control> controls)
077  {
078    this.operation = operation;
079    this.oid       = oid;
080    this.value     = value;
081
082    if (controls == null)
083    {
084      this.controls = new ArrayList<>(0);
085    }
086    else
087    {
088      this.controls = controls;
089    }
090  }
091
092
093
094  /**
095   * Retrieves the operation with which this intermediate response
096   * message is associated.
097   *
098   * @return  The operation with which this intermediate response
099   *          message is associated.
100   */
101  public Operation getOperation()
102  {
103    return operation;
104  }
105
106
107
108  /**
109   * Retrieves the OID for this intermediate response.
110   *
111   * @return  The OID for this intermediate response, or
112   *          <CODE>null</CODE> if there is none.
113   */
114  public String getOID()
115  {
116    return oid;
117  }
118
119
120
121  /**
122   * Specifies the OID for this intermediate response.
123   *
124   * @param  oid  The OID for this intermediate response.
125   */
126  public void setOID(String oid)
127  {
128    this.oid = oid;
129  }
130
131
132
133  /**
134   * Retrieves the value for this intermediate response.
135   *
136   * @return  The value for this intermediate response, or
137   *          <CODE>null</CODE> if there is none.
138   */
139  public ByteString getValue()
140  {
141    return value;
142  }
143
144
145
146  /**
147   * Specifies the value for this intermediate response.
148   *
149   * @param  value  The value for this intermediate response.
150   */
151  public void setValue(ByteString value)
152  {
153    this.value = value;
154  }
155
156
157
158  /**
159   * Retrieves the set of controls for this intermediate response.
160   * The contents of the list may be altered by intermediate response
161   * plugins.
162   *
163   * @return  The set of controls for this intermediate response.
164   */
165  public List<Control> getControls()
166  {
167    return controls;
168  }
169
170
171
172  /**
173   * Retrieves a string representation of this intermediate response.
174   *
175   * @return  A string representation of this intermediate response.
176   */
177  public String toString()
178  {
179    StringBuilder buffer = new StringBuilder();
180    toString(buffer);
181    return buffer.toString();
182  }
183
184
185
186  /**
187   * Appends a string representation of this intermediate response to
188   * the provided buffer.
189   *
190   * @param  buffer  The buffer to which the information should be
191   *                 appended.
192   */
193  public void toString(StringBuilder buffer)
194  {
195    buffer.append("IntermediateResponse(operation=");
196    operation.toString(buffer);
197    buffer.append(",oid=").append(oid);
198    buffer.append(",value=").append(buffer);
199
200    if (! controls.isEmpty())
201    {
202      buffer.append(",controls={");
203
204      Iterator<Control> iterator = controls.iterator();
205      iterator.next().toString(buffer);
206
207      while (iterator.hasNext())
208      {
209        buffer.append(",");
210        iterator.next().toString(buffer);
211      }
212
213      buffer.append("}");
214    }
215
216    buffer.append(")");
217  }
218}
219