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