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