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