001/*
002 * Copyright 2008-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-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) 2008-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.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  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(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  public String getName()
143  {
144    return name;
145  }
146
147
148
149  /**
150   * Retrieves the debug type with the specified name.
151   *
152   * @param  name  The name of the debug type to retrieve.  It must not be
153   *               {@code null}.
154   *
155   * @return  The requested debug type, or {@code null} if there is no such
156   *          debug type.
157   */
158  public static DebugType forName(final String name)
159  {
160    switch (StaticUtils.toLowerCase(name))
161    {
162      case "asn1":
163        return ASN1;
164      case "connect":
165        return CONNECT;
166      case "exception":
167        return EXCEPTION;
168      case "ldap":
169        return LDAP;
170      case "pool":
171      case "connectionpool":
172      case "connection-pool":
173      case "connection_pool":
174        return CONNECTION_POOL;
175      case "ldif":
176        return LDIF;
177      case "monitor":
178        return MONITOR;
179      case "codingerror":
180      case "coding-error":
181      case "coding_error":
182        return CODING_ERROR;
183      case "other":
184        return OTHER;
185      default:
186        return null;
187    }
188  }
189
190
191
192  /**
193   * Retrieves a comma-delimited list of the defined debug type names.
194   *
195   * @return  A comma-delimited list of the defined debug type names.
196   */
197  public static String getTypeNameList()
198  {
199    final StringBuilder buffer = new StringBuilder();
200
201    final DebugType[] types = DebugType.values();
202    for (int i=0; i < types.length; i++)
203    {
204      if (i > 0)
205      {
206        buffer.append(", ");
207      }
208
209      buffer.append(types[i].name);
210    }
211
212    return buffer.toString();
213  }
214
215
216
217  /**
218   * Retrieves a string representation of this debug type.
219   *
220   * @return  A string representation of this debug type.
221   */
222  @Override()
223  public String toString()
224  {
225    return name;
226  }
227}