001/*
002 * Copyright 2013-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2013-2022 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) 2013-2022 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.util.NotNull;
041import com.unboundid.util.Nullable;
042import com.unboundid.util.StaticUtils;
043import com.unboundid.util.ThreadSafety;
044import com.unboundid.util.ThreadSafetyLevel;
045
046
047
048/**
049 * This enum defines the types of configurations that may be obtained using the
050 * get configuration extended operation.
051 * <BR>
052 * <BLOCKQUOTE>
053 *   <B>NOTE:</B>  This class, and other classes within the
054 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
055 *   supported for use against Ping Identity, UnboundID, and
056 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
057 *   for proprietary functionality or for external specifications that are not
058 *   considered stable or mature enough to be guaranteed to work in an
059 *   interoperable way with other types of LDAP servers.
060 * </BLOCKQUOTE>
061 */
062@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
063public enum GetConfigurationType
064{
065  /**
066   * The type used to specify the current active configuration.
067   */
068  ACTIVE(GetConfigurationType.ACTIVE_BER_TYPE, 0),
069
070
071
072  /**
073   * The type used to specify the baseline configuration for the current server
074   * version.
075   */
076  BASELINE(GetConfigurationType.BASELINE_BER_TYPE, 1),
077
078
079
080  /**
081   * The type used to specify an archived configuration that was previously
082   * in effect.
083   */
084  ARCHIVED(GetConfigurationType.ARCHIVED_BER_TYPE, 2);
085
086
087
088  /**
089   * The BER type used to designate the active type.
090   */
091  static final byte ACTIVE_BER_TYPE = (byte) 0x80;
092
093
094
095  /**
096   * The BER type used to designate the baseline type.
097   */
098  static final byte BASELINE_BER_TYPE = (byte) 0x81;
099
100
101
102  /**
103   * The BER type used to designate the archived type.
104   */
105  static final byte ARCHIVED_BER_TYPE = (byte) 0x82;
106
107
108
109  // The BER type that should be used when this configuration type needs to be
110  // encoded in a get configuration request.
111  private final byte berType;
112
113  // The integer value that should be used when this configuration type needs to
114  // be encoded as an enumerated element in a get configuration result.
115  private final int intValue;
116
117
118
119  /**
120   * Creates a new get configuration type value with the specified information.
121   *
122   * @param  berType   The BER type that should be used when this configuration
123   *                   type needs to be encoded in a get configuration request.
124   * @param  intValue  The integer value that should be used when this
125   *                   configuration type needs to be encoded as an enumerated
126   *                   element in a get configuration result.
127   */
128  GetConfigurationType(final byte berType, final int intValue)
129  {
130    this.berType  = berType;
131    this.intValue = intValue;
132  }
133
134
135
136  /**
137   * Retrieves the BER type that should be used when this configuration type
138   * needs to be encoded in a get configuration request.
139   *
140   * @return  The BER type that should be used when this configuration type
141   *          needs to be encoded in a get configuration request.
142   */
143  public byte getBERType()
144  {
145    return berType;
146  }
147
148
149
150  /**
151   * Retrieves the integer value that should be used when this configuration
152   * type needs to be encoded as an enumerated element in a get configuration
153   * result.
154   *
155   * @return  The integer value that should be used when this configuration
156   *          type needs to be encoded as an enumerated element in a get
157   *          configuration result.
158   */
159  public int getIntValue()
160  {
161    return intValue;
162  }
163
164
165
166  /**
167   * Retrieves the get configuration type value that has the specified BER type.
168   *
169   * @param  berType  The BER type for the get configuration type value to
170   *                  retrieve.
171   *
172   * @return  The get configuration type value for the specified BER type, or
173   *          {@code null} if there is no enum value with the specified BER
174   *          type.
175   */
176  @Nullable()
177  public static GetConfigurationType forBERType(final byte berType)
178  {
179    for (final GetConfigurationType t : values())
180    {
181      if (t.berType == berType)
182      {
183        return t;
184      }
185    }
186
187    return null;
188  }
189
190
191
192  /**
193   * Retrieves the get configuration type value that has the specified integer
194   * value.
195   *
196   * @param  intValue  The integer value for the get configuration type value
197   *                   to retrieve.
198   *
199   * @return  The get configuration type value for the specified integer value,
200   *          or {@code null} if there is no enum value with the specified
201   *          integer value.
202   */
203  @Nullable()
204  public static GetConfigurationType forIntValue(final int intValue)
205  {
206    for (final GetConfigurationType t : values())
207    {
208      if (t.intValue == intValue)
209      {
210        return t;
211      }
212    }
213
214    return null;
215  }
216
217
218
219  /**
220   * Retrieves the get configuration type value with the specified name.
221   *
222   * @param  name  The name of the get configuration type value to retrieve.  It
223   *               must not be {@code null}.
224   *
225   * @return  The requested get configuration type value, or {@code null} if no
226   *          such value is defined.
227   */
228  @Nullable()
229  public static GetConfigurationType forName(@NotNull final String name)
230  {
231    switch (StaticUtils.toLowerCase(name))
232    {
233      case "active":
234        return ACTIVE;
235      case "baseline":
236        return BASELINE;
237      case "archived":
238        return ARCHIVED;
239      default:
240        return null;
241    }
242  }
243}