001/*
002 * Copyright 2013-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2013-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2015-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.extensions;
037
038
039
040import com.unboundid.ldap.sdk.Control;
041import com.unboundid.ldap.sdk.ExtendedRequest;
042import com.unboundid.ldap.sdk.ExtendedResult;
043import com.unboundid.ldap.sdk.LDAPConnection;
044import com.unboundid.ldap.sdk.LDAPException;
045import com.unboundid.ldap.sdk.ResultCode;
046import com.unboundid.util.ThreadSafety;
047import com.unboundid.util.ThreadSafetyLevel;
048
049import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
050
051
052
053/**
054 * This class provides an implementation of an extended request that can be used
055 * to retrieve a list of all available versions of the configuration within a
056 * server.  This may include not only the currently-active configuration, but
057 * also former configurations that have been archived, and the baseline
058 * configuration for the current server version.
059 * <BR>
060 * <BLOCKQUOTE>
061 *   <B>NOTE:</B>  This class, and other classes within the
062 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
063 *   supported for use against Ping Identity, UnboundID, and
064 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
065 *   for proprietary functionality or for external specifications that are not
066 *   considered stable or mature enough to be guaranteed to work in an
067 *   interoperable way with other types of LDAP servers.
068 * </BLOCKQUOTE>
069 * <BR>
070 * The OID for this extended request is 1.3.6.1.4.1.30221.2.6.26.  It does not
071 * have a value.
072 * <BR><BR>
073 * <H2>Example</H2>
074 * The following example demonstrates the process for using the list
075 * configurations and get configuration extended requests to obtain the oldest
076 * archived configuration from the server:
077 * <PRE>
078 * // Get a list of the available configurations from the server.
079 * ListConfigurationsExtendedResult listConfigsResult =
080 *      (ListConfigurationsExtendedResult)
081 *      connection.processExtendedOperation(
082 *           new ListConfigurationsExtendedRequest());
083 * String archivedConfigFileName =
084 *      listConfigsResult.getArchivedFileNames().get(0);
085 *
086 * // Retrieve the first archived configuration from the list configurations
087 * // result.
088 * GetConfigurationExtendedResult getConfigResult =
089 *      (GetConfigurationExtendedResult)
090 *      connection.processExtendedOperation(GetConfigurationExtendedRequest.
091 *           createGetArchivedConfigurationRequest(archivedConfigFileName));
092 *
093 * InputStream fileDataStream = getConfigResult.getFileDataInputStream();
094 * // Read data from the file.
095 * fileDataStream.close();
096 * </PRE>
097 *
098 * @see  GetConfigurationExtendedRequest
099 */
100@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
101public final class ListConfigurationsExtendedRequest
102       extends ExtendedRequest
103{
104  /**
105   * The OID (1.3.6.1.4.1.30221.2.6.26) for the list configurations extended
106   * request.
107   */
108  public static final  String LIST_CONFIGS_REQUEST_OID =
109       "1.3.6.1.4.1.30221.2.6.26";
110
111
112
113  /**
114   * The serial version UID for this serializable class.
115   */
116  private static final long serialVersionUID = -5511054471842622735L;
117
118
119
120  /**
121   * Creates a new list configurations extended request with the provided
122   * information.
123   *
124   * @param  controls  An optional set of controls to include in the request.
125   *                   This may be {@code null} or empty if no controls should
126   *                   be included in the request.
127   */
128  public ListConfigurationsExtendedRequest(final Control... controls)
129  {
130    super(LIST_CONFIGS_REQUEST_OID, controls);
131  }
132
133
134
135  /**
136   * Creates a new list configurations extended request that has been decoded
137   * from the provided generic extended request.
138   *
139   * @param  r  The generic extended request to decode as a list configurations
140   *            extended request.
141   *
142   * @throws LDAPException  If the provided request cannot be decoded as a
143   *                         valid list configurations extended request.
144   */
145  public ListConfigurationsExtendedRequest(final ExtendedRequest r)
146         throws LDAPException
147  {
148    super(r);
149
150    if (r.hasValue())
151    {
152      throw new LDAPException(ResultCode.DECODING_ERROR,
153           ERR_LIST_CONFIGS_REQUEST_HAS_VALUE.get());
154    }
155  }
156
157
158
159  /**
160   * {@inheritDoc}
161   */
162  @Override()
163  public ListConfigurationsExtendedResult process(
164              final LDAPConnection connection, final int depth)
165         throws LDAPException
166  {
167    final ExtendedResult extendedResponse = super.process(connection, depth);
168    return new ListConfigurationsExtendedResult(extendedResponse);
169  }
170
171
172
173  /**
174   * {@inheritDoc}
175   */
176  @Override()
177  public ListConfigurationsExtendedRequest duplicate()
178  {
179    return duplicate(getControls());
180  }
181
182
183
184  /**
185   * {@inheritDoc}
186   */
187  @Override()
188  public ListConfigurationsExtendedRequest duplicate(
189              final Control[] controls)
190  {
191    final ListConfigurationsExtendedRequest r =
192         new ListConfigurationsExtendedRequest(controls);
193    r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
194    return r;
195  }
196
197
198
199  /**
200   * {@inheritDoc}
201   */
202  @Override()
203  public String getExtendedRequestName()
204  {
205    return INFO_EXTENDED_REQUEST_NAME_LIST_CONFIGS.get();
206  }
207
208
209
210  /**
211   * {@inheritDoc}
212   */
213  @Override()
214  public void toString(final StringBuilder buffer)
215  {
216    buffer.append("ListConfigurationsExtendedRequest(");
217
218    final Control[] controls = getControls();
219    if (controls.length > 0)
220    {
221      buffer.append("controls={");
222      for (int i=0; i < controls.length; i++)
223      {
224        if (i > 0)
225        {
226          buffer.append(", ");
227        }
228
229        buffer.append(controls[i]);
230      }
231      buffer.append('}');
232    }
233
234    buffer.append(')');
235  }
236}