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