001 /*
002 * Copyright 2008-2016 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2008-2016 UnboundID Corp.
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 */
021 package com.unboundid.util;
022
023
024
025 import 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)
034 public 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 private 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.
134 *
135 * @return The requested debug type, or {@code null} if there is no such
136 * debug type.
137 */
138 public static DebugType forName(final String name)
139 {
140 final String lowerName = toLowerCase(name);
141
142 if (lowerName.equals("asn1"))
143 {
144 return ASN1;
145 }
146 else if (lowerName.equals("connect"))
147 {
148 return CONNECT;
149 }
150 else if (lowerName.equals("exception"))
151 {
152 return EXCEPTION;
153 }
154 else if (lowerName.equals("ldap"))
155 {
156 return LDAP;
157 }
158 else if (lowerName.equals("ldif"))
159 {
160 return LDIF;
161 }
162 else if (lowerName.equals("monitor"))
163 {
164 return MONITOR;
165 }
166 else if (lowerName.equals("coding-error"))
167 {
168 return CODING_ERROR;
169 }
170 else if (lowerName.equals("other"))
171 {
172 return OTHER;
173 }
174
175 return null;
176 }
177
178
179
180 /**
181 * Retrieves a comma-delimited list of the defined debug type names.
182 *
183 * @return A comma-delimited list of the defined debug type names.
184 */
185 public static String getTypeNameList()
186 {
187 final StringBuilder buffer = new StringBuilder();
188
189 final DebugType[] types = DebugType.values();
190 for (int i=0; i < types.length; i++)
191 {
192 if (i > 0)
193 {
194 buffer.append(", ");
195 }
196
197 buffer.append(types[i].getName());
198 }
199
200 return buffer.toString();
201 }
202
203
204
205 /**
206 * Retrieves a string representation of this debug type.
207 *
208 * @return A string representation of this debug type.
209 */
210 @Override()
211 public String toString()
212 {
213 return name;
214 }
215 }