001/*
002 * Copyright 2013-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 Ping Identity Corporation
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 */
021package com.unboundid.ldap.sdk.unboundidds.extensions;
022
023
024
025import com.unboundid.ldap.sdk.Control;
026import com.unboundid.ldap.sdk.ExtendedRequest;
027import com.unboundid.ldap.sdk.ExtendedResult;
028import com.unboundid.ldap.sdk.LDAPConnection;
029import com.unboundid.ldap.sdk.LDAPException;
030import com.unboundid.ldap.sdk.ResultCode;
031import com.unboundid.util.ThreadSafety;
032import com.unboundid.util.ThreadSafetyLevel;
033
034import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
035
036
037
038/**
039 * This class provides an implementation of an extended request that can be used
040 * to retrieve a list of all available versions of the configuration within a
041 * server.  This may include not only the currently-active configuration, but
042 * also former configurations that have been archived, and the baseline
043 * configuration for the current server version.
044 * <BR>
045 * <BLOCKQUOTE>
046 *   <B>NOTE:</B>  This class, and other classes within the
047 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
048 *   supported for use against Ping Identity, UnboundID, and
049 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
050 *   for proprietary functionality or for external specifications that are not
051 *   considered stable or mature enough to be guaranteed to work in an
052 *   interoperable way with other types of LDAP servers.
053 * </BLOCKQUOTE>
054 * <BR>
055 * The OID for this extended request is 1.3.6.1.4.1.30221.2.6.26.  It does not
056 * have a value.
057 * <BR><BR>
058 * <H2>Example</H2>
059 * The following example demonstrates the process for using the list
060 * configurations and get configuration extended requests to obtain the oldest
061 * archived configuration from the server:
062 * <PRE>
063 * // Get a list of the available configurations from the server.
064 * ListConfigurationsExtendedResult listConfigsResult =
065 *      (ListConfigurationsExtendedResult)
066 *      connection.processExtendedOperation(
067 *           new ListConfigurationsExtendedRequest());
068 * String archivedConfigFileName =
069 *      listConfigsResult.getArchivedFileNames().get(0);
070 *
071 * // Retrieve the first archived configuration from the list configurations
072 * // result.
073 * GetConfigurationExtendedResult getConfigResult =
074 *      (GetConfigurationExtendedResult)
075 *      connection.processExtendedOperation(GetConfigurationExtendedRequest.
076 *           createGetArchivedConfigurationRequest(archivedConfigFileName));
077 *
078 * InputStream fileDataStream = getConfigResult.getFileDataInputStream();
079 * // Read data from the file.
080 * fileDataStream.close();
081 * </PRE>
082 *
083 * @see  GetConfigurationExtendedRequest
084 */
085@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
086public final class ListConfigurationsExtendedRequest
087       extends ExtendedRequest
088{
089  /**
090   * The OID (1.3.6.1.4.1.30221.2.6.26) for the list configurations extended
091   * request.
092   */
093  public static final  String LIST_CONFIGS_REQUEST_OID =
094       "1.3.6.1.4.1.30221.2.6.26";
095
096
097
098  /**
099   * The serial version UID for this serializable class.
100   */
101  private static final long serialVersionUID = -5511054471842622735L;
102
103
104
105  /**
106   * Creates a new list configurations extended request with the provided
107   * information.
108   *
109   * @param  controls  An optional set of controls to include in the request.
110   *                   This may be {@code null} or empty if no controls should
111   *                   be included in the request.
112   */
113  public ListConfigurationsExtendedRequest(final Control... controls)
114  {
115    super(LIST_CONFIGS_REQUEST_OID, controls);
116  }
117
118
119
120  /**
121   * Creates a new list configurations extended request that has been decoded
122   * from the provided generic extended request.
123   *
124   * @param  r  The generic extended request to decode as a list configurations
125   *            extended request.
126   *
127   * @throws LDAPException  If the provided request cannot be decoded as a
128   *                         valid list configurations extended request.
129   */
130  public ListConfigurationsExtendedRequest(final ExtendedRequest r)
131         throws LDAPException
132  {
133    super(r);
134
135    if (r.hasValue())
136    {
137      throw new LDAPException(ResultCode.DECODING_ERROR,
138           ERR_LIST_CONFIGS_REQUEST_HAS_VALUE.get());
139    }
140  }
141
142
143
144  /**
145   * {@inheritDoc}
146   */
147  @Override()
148  public ListConfigurationsExtendedResult process(
149              final LDAPConnection connection, final int depth)
150         throws LDAPException
151  {
152    final ExtendedResult extendedResponse = super.process(connection, depth);
153    return new ListConfigurationsExtendedResult(extendedResponse);
154  }
155
156
157
158  /**
159   * {@inheritDoc}
160   */
161  @Override()
162  public ListConfigurationsExtendedRequest duplicate()
163  {
164    return duplicate(getControls());
165  }
166
167
168
169  /**
170   * {@inheritDoc}
171   */
172  @Override()
173  public ListConfigurationsExtendedRequest duplicate(
174              final Control[] controls)
175  {
176    final ListConfigurationsExtendedRequest r =
177         new ListConfigurationsExtendedRequest(controls);
178    r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
179    return r;
180  }
181
182
183
184  /**
185   * {@inheritDoc}
186   */
187  @Override()
188  public String getExtendedRequestName()
189  {
190    return INFO_EXTENDED_REQUEST_NAME_LIST_CONFIGS.get();
191  }
192
193
194
195  /**
196   * {@inheritDoc}
197   */
198  @Override()
199  public void toString(final StringBuilder buffer)
200  {
201    buffer.append("ListConfigurationsExtendedRequest(");
202
203    final Control[] controls = getControls();
204    if (controls.length > 0)
205    {
206      buffer.append("controls={");
207      for (int i=0; i < controls.length; i++)
208      {
209        if (i > 0)
210        {
211          buffer.append(", ");
212        }
213
214        buffer.append(controls[i]);
215      }
216      buffer.append('}');
217    }
218
219    buffer.append(')');
220  }
221}