001/*
002 * Copyright 2008-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2024 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) 2008-2024 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.util;
037
038
039
040/**
041 * This enumeration defines a set of debugging types that are used by the LDAP
042 * SDK.
043 */
044@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
045public enum DebugType
046{
047  /**
048   * The debug type that will be used for debugging information about ASN.1
049   * elements written to or read from a directory server.
050   */
051  ASN1("asn1"),
052
053
054
055  /**
056   * The debug type that will be used for debugging information about
057   * connection establishment and termination.
058   */
059  CONNECT("connect"),
060
061
062
063  /**
064   * The debug type that will be used for debugging information about
065   * exceptions that are caught.
066   */
067  EXCEPTION("exception"),
068
069
070
071  /**
072   * The debug type that will be used for debugging information about LDAP
073   * requests sent to or received from a directory server.
074   */
075  LDAP("ldap"),
076
077
078
079  /**
080   * The debug type that will be used for information about connection pool
081   * interaction.
082   */
083  CONNECTION_POOL("connection-pool"),
084
085
086
087  /**
088   * The debug type that will be used for debugging information about LDIF
089   * entries or change records read or written.
090   */
091  LDIF("ldif"),
092
093
094
095  /**
096   * The debug type that will be used for information about monitor entry
097   * parsing.
098   */
099  MONITOR("monitor"),
100
101
102
103  /**
104   * The debug type that will be used for information about coding errors or
105   * other types of incorrect uses of the LDAP SDK.
106   */
107  CODING_ERROR("coding-error"),
108
109
110
111  /**
112   * The debug type that will be used for debug messages not applicable to any
113   * of the other categories.
114   */
115  OTHER("other");
116
117
118
119  // The name for this debug type.
120  @NotNull private final String name;
121
122
123
124  /**
125   * Creates a new debug type with the specified name.
126   *
127   * @param  name  The name for this debug type.  It should be in all lowercase
128   *               characters.
129   */
130  DebugType(@NotNull final String name)
131  {
132    this.name = name;
133  }
134
135
136
137  /**
138   * Retrieves the name for this debug type.
139   *
140   * @return  The name for this debug type.
141   */
142  @NotNull()
143  public String getName()
144  {
145    return name;
146  }
147
148
149
150  /**
151   * Retrieves the debug type with the specified name.
152   *
153   * @param  name  The name of the debug type to retrieve.  It must not be
154   *               {@code null}.
155   *
156   * @return  The requested debug type, or {@code null} if there is no such
157   *          debug type.
158   */
159  @Nullable()
160  public static DebugType forName(@NotNull final String name)
161  {
162    switch (StaticUtils.toLowerCase(name))
163    {
164      case "asn1":
165        return ASN1;
166      case "connect":
167        return CONNECT;
168      case "exception":
169        return EXCEPTION;
170      case "ldap":
171        return LDAP;
172      case "pool":
173      case "connectionpool":
174      case "connection-pool":
175      case "connection_pool":
176        return CONNECTION_POOL;
177      case "ldif":
178        return LDIF;
179      case "monitor":
180        return MONITOR;
181      case "codingerror":
182      case "coding-error":
183      case "coding_error":
184        return CODING_ERROR;
185      case "other":
186        return OTHER;
187      default:
188        return null;
189    }
190  }
191
192
193
194  /**
195   * Retrieves a comma-delimited list of the defined debug type names.
196   *
197   * @return  A comma-delimited list of the defined debug type names.
198   */
199  @NotNull()
200  public static String getTypeNameList()
201  {
202    final StringBuilder buffer = new StringBuilder();
203
204    final DebugType[] types = DebugType.values();
205    for (int i=0; i < types.length; i++)
206    {
207      if (i > 0)
208      {
209        buffer.append(", ");
210      }
211
212      buffer.append(types[i].name);
213    }
214
215    return buffer.toString();
216  }
217
218
219
220  /**
221   * Retrieves a string representation of this debug type.
222   *
223   * @return  A string representation of this debug type.
224   */
225  @Override()
226  @NotNull()
227  public String toString()
228  {
229    return name;
230  }
231}