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