Frames | No Frames |
1: /* Component.java -- a component log level. 2: Copyright (C) 2005, 2006 Free Software Foundation, Inc. 3: 4: This file is a part of GNU Classpath. 5: 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. 10: 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. 15: 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 20: 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. 25: 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. */ 37: 38: 39: package gnu.classpath.debug; 40: 41: import java.lang.reflect.Field; 42: import java.lang.reflect.Modifier; 43: import java.util.logging.Level; 44: 45: public final class Component extends Level 46: { 47: 48: /* 49: * HOW TO ADD NEW COMPONENTS: 50: * 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. 55: * 56: * For example, if my component had to do with 'frobbing', I would 57: * add this entry below: 58: * 59: * private static final Component FROBBING = new Component ("FROBBING", 7); 60: * 61: * Then, I would update the component 'EVERYTHING' to have and end 62: * index ONE GREATER THAN the index of the new component. 63: * 64: * ADDING NEW COMPONENT CLASSES: 65: * 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. 71: */ 72: 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. 76: */ 77: public static final Component EVERYTHING = new Component ("*", 0, 11); 78: 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. 83: */ 84: public static final Component SSL = new Component ("SSL", 0, 5); 85: 86: /** 87: * Traces the progression of an SSL handshake. 88: */ 89: public static final Component SSL_HANDSHAKE = new Component ("SSL HANDSHAKE", 0); 90: 91: /** 92: * Traces record layer messages during SSL communications. 93: */ 94: public static final Component SSL_RECORD_LAYER = new Component ("SSL RECORD LAYER", 1); 95: 96: /** 97: * Trace details about the SSL key exchange. 98: */ 99: public static final Component SSL_KEY_EXCHANGE = new Component ("SSL KEY EXCHANGE", 2); 100: 101: /* Indices 3 and 4 reserved for future use by SSL components. */ 102: 103: /** 104: * Trace the operation of cryptographic primitives. 105: */ 106: public static final Component CRYPTO = new Component ("CRYPTO", 5); 107: 108: /** 109: * Trace the parsing of X.509 certificates and related objects. 110: */ 111: public static final Component X509 = new Component ("X.509", 6); 112: 113: /** 114: * Trace access control policies, including the parsing of 115: * java.policy files. 116: */ 117: public static final Component POLICY = new Component ("POLICY", 7); 118: 119: /** 120: * Trace ipp implementation. 121: */ 122: public static final Component IPP = new Component ("IPP", 10); 123: 124: private final int startIndex; 125: private final int endIndex; 126: 127: private Component (final String name, final int bitIndex) 128: { 129: this (name, bitIndex, bitIndex + 1); 130: } 131: 132: private Component (final String name, final int startIndex, final int endIndex) 133: { 134: super (name, Level.FINE.intValue ()); 135: this.startIndex = startIndex; 136: this.endIndex = endIndex; 137: } 138: 139: /** 140: * Return the component for the given name. 141: * 142: * @param name The name of the component to get. 143: * @return The named component, or null if there is no such component. 144: */ 145: public static Component forName (final String name) 146: { 147: try 148: { 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); 154: } 155: catch (Throwable _) 156: { 157: return null; 158: } 159: } 160: 161: public int startIndex () 162: { 163: return startIndex; 164: } 165: 166: public int endIndex () 167: { 168: return endIndex; 169: }