Merge from mainline.
[official-gcc.git] / libjava / classpath / gnu / classpath / debug / Component.java
blob0cc38d7096af24bfb3f7b1b2070ebad180d2e5b8
1 /* Component.java -- a component log level.
2 Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4 This file is a part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at
9 your option) any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under terms
30 of your choice, provided that you also meet, for each linked independent
31 module, the terms and conditions of the license of that module. An
32 independent module is a module which is not derived from or based on
33 this library. If you modify this library, you may extend this exception
34 to your version of the library, but you are not obligated to do so. If
35 you do not wish to do so, delete this exception statement from your
36 version. */
39 package gnu.classpath.debug;
41 import java.lang.reflect.Field;
42 import java.lang.reflect.Modifier;
43 import java.util.logging.Level;
45 public final class Component extends Level
49 * HOW TO ADD NEW COMPONENTS:
51 * If you want to add a new, simple component, that you will use in
52 * logging statements, simply create a new class variable that
53 * instantiates this class, and choose an appropriate string name
54 * and a integer constant not used by any other component level.
56 * For example, if my component had to do with 'frobbing', I would
57 * add this entry below:
59 * private static final Component FROBBING = new Component ("FROBBING", 7);
61 * Then, I would update the component 'EVERYTHING' to have and end
62 * index ONE GREATER THAN the index of the new component.
64 * ADDING NEW COMPONENT CLASSES:
66 * A "component class" is a run of more than one component, which can
67 * be enabled all at once. EVERYTHING and SSL are examples of component
68 * classes. To add a new class, create a new component with a start index
69 * equal to the index of the first member component, and with an end
70 * index equal to the index of the last member component plus one.
73 /**
74 * Signifies that everything should be logged. This should be used to
75 * enable or disable levels only; logging code should not use it.
77 public static final Component EVERYTHING = new Component ("*", 0, 11);
79 /**
80 * Signifies that all SSL related messages should be logged. This should
81 * be used to enable or disable levels only; logging code should not use
82 * it.
84 public static final Component SSL = new Component ("SSL", 0, 5);
86 /**
87 * Traces the progression of an SSL handshake.
89 public static final Component SSL_HANDSHAKE = new Component ("SSL HANDSHAKE", 0);
91 /**
92 * Traces record layer messages during SSL communications.
94 public static final Component SSL_RECORD_LAYER = new Component ("SSL RECORD LAYER", 1);
96 /**
97 * Trace details about the SSL key exchange.
99 public static final Component SSL_KEY_EXCHANGE = new Component ("SSL KEY EXCHANGE", 2);
101 /* Indices 3 and 4 reserved for future use by SSL components. */
104 * Trace the operation of cryptographic primitives.
106 public static final Component CRYPTO = new Component ("CRYPTO", 5);
109 * Trace the parsing of X.509 certificates and related objects.
111 public static final Component X509 = new Component ("X.509", 6);
114 * Trace access control policies, including the parsing of
115 * java.policy files.
117 public static final Component POLICY = new Component ("POLICY", 7);
120 * Trace ipp implementation.
122 public static final Component IPP = new Component ("IPP", 10);
124 private final int startIndex;
125 private final int endIndex;
127 private Component (final String name, final int bitIndex)
129 this (name, bitIndex, bitIndex + 1);
132 private Component (final String name, final int startIndex, final int endIndex)
134 super (name, Level.FINE.intValue ());
135 this.startIndex = startIndex;
136 this.endIndex = endIndex;
140 * Return the component for the given name.
142 * @param name The name of the component to get.
143 * @return The named component, or null if there is no such component.
145 public static Component forName (final String name)
149 Field f = Component.class.getField (name.toUpperCase ());
150 if (!Modifier.isStatic (f.getModifiers ())
151 || Component.class.isAssignableFrom (f.getClass ()))
152 return null;
153 return (Component) f.get (null);
155 catch (Throwable _)
157 return null;
161 public int startIndex ()
163 return startIndex;
166 public int endIndex ()
168 return endIndex;