Source for gnu.classpath.debug.Component

   1: /* Component.java -- a component log level.
   2:    Copyright (C) 2005  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, 7);
  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 the application messages during SSL communications.
  93:    */
  94:   public static final Component SSL_APPLICATION = new Component ("SSL APPLICATION", 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:   private final int startIndex;
 120:   private final int endIndex;
 121: 
 122:   private Component (final String name, final int bitIndex)
 123:   {
 124:     this (name, bitIndex, bitIndex + 1);
 125:   }
 126: 
 127:   private Component (final String name, final int startIndex, final int endIndex)
 128:   {
 129:     super (name, Level.FINE.intValue ());
 130:     this.startIndex = startIndex;
 131:     this.endIndex = endIndex;
 132:   }
 133: 
 134:   /**
 135:    * Return the component for the given name.
 136:    *
 137:    * @param name The name of the component to get.
 138:    * @return The named component, or null if there is no such component.
 139:    */
 140:   public static Component forName (final String name)
 141:   {
 142:     try
 143:       {
 144:     Field f = Component.class.getField (name.toUpperCase ());
 145:     if (!Modifier.isStatic (f.getModifiers ())
 146:         || Component.class.isAssignableFrom (f.getClass ()))
 147:       return null;
 148:     return (Component) f.get (null);
 149:       }
 150:     catch (Throwable _)
 151:       {
 152:     return null;
 153:       }
 154:   }
 155: 
 156:   public int startIndex ()
 157:   {
 158:     return startIndex;
 159:   }
 160: 
 161:   public int endIndex ()
 162:   {
 163:     return endIndex;
 164:   }