001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.loggers; 028 029 import java.util.ArrayList; 030 031 /** 032 * The category class defines a set of standard logging types that 033 * can be used to control logging output. 034 */ 035 public class LogCategory 036 { 037 private static ArrayList<LogCategory> known = new ArrayList<LogCategory>(); 038 039 040 /** 041 * The non-localized name of the type. 042 */ 043 private final String name; 044 045 /** 046 * Create a named type. 047 * <p> 048 * Note that this constructor is "protected" to allow subclassing. 049 * 050 * @param name the name of the category, for example "MESSAGE". 051 */ 052 protected LogCategory(String name) { 053 if (name == null) { 054 throw new NullPointerException(); 055 } 056 this.name = name; 057 058 known.add(this); 059 } 060 061 /** 062 * Return the non-localized string name of the Level. 063 * 064 * @return non-localized name 065 */ 066 public String getName() { 067 return name; 068 } 069 070 /** 071 * Retrieves the string reprentation of this log category. 072 * 073 * @return the non-localized name of the LogCategory, for example "ENTRY". 074 */ 075 public final String toString() { 076 return name; 077 } 078 079 /** 080 * Parse a category name string into a LogCategory. 081 * <p> 082 * For example: 083 * <ul> 084 * <li> "EXIT" 085 * <li> "caught" 086 * </ul> 087 * @param name string to be parsed 088 * @throws IllegalArgumentException if the value is not valid. 089 * Known names are the categories defined by this class or created 090 * by this class with appropriate package access, or new levels defined 091 * or created by subclasses. 092 * 093 * @return The parsed category 094 */ 095 public static synchronized LogCategory parse(String name) 096 throws IllegalArgumentException { 097 // Check that name is not null. 098 name.length(); 099 100 // Look for a known Level with the given name. 101 for (int i = 0; i < known.size(); i++) { 102 LogCategory c = known.get(i); 103 if (name.equalsIgnoreCase(c.name)) { 104 return c; 105 } 106 } 107 108 // OK, we've tried everything and failed 109 throw new IllegalArgumentException("Bad category \"" + name + "\""); 110 } 111 }