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