org.jgroups.conf

## Class ClassConfigurator

- java.lang.Object
- - org.jgroups.conf.ClassConfigurator

-     public class ClassConfigurator
      extends java.lang.Object

  This class will be replaced with the class that read info from the magic number configurator that reads info from the xml file. The name and the relative path of the magic number map file can be specified as value of the property `org.jgroups.conf.magicNumberFile`. It must be relative to one of the classpath elements, to allow the classloader to locate the file. If a value is not specified, `MagicNumberReader.MAGIC_NUMBER_FILE` is used, which defaults to "jg-magic-map.xml".
  Author:
    Filip Hanik, Bela Ban

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static Log` | `log`
    `static java.lang.String` | `MAGIC_NUMBER_FILE`
    `static java.lang.String` | `PROTOCOL_ID_FILE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClassConfigurator()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `add(short magic, java.lang.Class clazz)` Method to register a user-defined header with jg-magic-map at runtime
    `static void` | `addProtocol(short id, java.lang.Class protocol)`
    `static java.lang.Class` | `get(short magic)` Returns a class for a magic number.
    `static java.lang.Class` | `get(java.lang.String clazzname)` Loads and returns the class from the class name
    `static short` | `getMagicNumber(java.lang.Class clazz)` Returns the magic number for the class.
    `static java.lang.Class` | `getProtocol(short id)`
    `static short` | `getProtocolId(java.lang.Class protocol)`
    `protected static void` | `init()`
    `protected static java.util.List<Tuple<java.lang.Short,java.lang.String>>` | `parse(java.io.InputStream stream)`
    `protected static Tuple<java.lang.Short,java.lang.String>` | `parseClassData(org.w3c.dom.Node protocol)`
    `static java.lang.String` | `printClassMap()`
    `static java.lang.String` | `printMagicMap()`
    `protected static java.util.List<Tuple<java.lang.Short,java.lang.String>>` | `readMappings(java.lang.String name)` try to read the magic number configuration file as a Resource form the classpath using getResourceAsStream if this fails this method tries to read the configuration file from mMagicNumberFile using a FileInputStream (not in classpath but somewhere else in the disk)
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### MAGIC_NUMBER_FILE

          public static final java.lang.String MAGIC_NUMBER_FILE

      See Also:
        Constant Field Values

    - #### PROTOCOL_ID_FILE

          public static final java.lang.String PROTOCOL_ID_FILE

      See Also:
        Constant Field Values

    - #### log

          protected static final Log log

  - ### Constructor Detail

    - #### ClassConfigurator

          public ClassConfigurator()

  - ### Method Detail

    - #### init

          protected static void init()
                              throws ChannelException

      Throws:
        `ChannelException`

    - #### add

          public static void add(short magic,
                 java.lang.Class clazz)
                          throws java.lang.IllegalArgumentException

      Method to register a user-defined header with jg-magic-map at runtime
      Parameters:
        `magic` - The magic number. Needs to be > 1024
        `clazz` - The class. Usually a subclass of Header
      Throws:
        `java.lang.IllegalArgumentException` - If the magic number is already taken, or the magic number is <= 1024

    - #### addProtocol

          public static void addProtocol(short id,
                         java.lang.Class protocol)

    - #### get

          public static java.lang.Class get(short magic)

      Returns a class for a magic number. Returns null if no class is found
      Parameters:
        `magic` - the magic number that maps to the class
      Returns:
        a Class object that represents a class that implements java.io.Externalizable

    - #### get

          public static java.lang.Class get(java.lang.String clazzname)

      Loads and returns the class from the class name
      Parameters:
        `clazzname` - a fully classified class name to be loaded
      Returns:
        a Class object that represents a class that implements java.io.Externalizable

    - #### getMagicNumber

          public static short getMagicNumber(java.lang.Class clazz)

      Returns the magic number for the class.
      Parameters:
        `clazz` - a class object that we want the magic number for
      Returns:
        the magic number for a class, -1 if no mapping is available

    - #### getProtocolId

          public static short getProtocolId(java.lang.Class protocol)

    - #### getProtocol

          public static java.lang.Class getProtocol(short id)

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### printMagicMap

          public static java.lang.String printMagicMap()

    - #### printClassMap

          public static java.lang.String printClassMap()

    - #### readMappings

          protected static java.util.List<Tuple<java.lang.Short,java.lang.String>> readMappings(java.lang.String name)
                                                                                         throws java.lang.Exception

      try to read the magic number configuration file as a Resource form the classpath using getResourceAsStream if this fails this method tries to read the configuration file from mMagicNumberFile using a FileInputStream (not in classpath but somewhere else in the disk)
      Returns:
        an array of ClassMap objects that where parsed from the file (if found) or an empty array if file not found or had en exception
      Throws:
        `java.lang.Exception`

    - #### parse

          protected static java.util.List<Tuple<java.lang.Short,java.lang.String>> parse(java.io.InputStream stream)
                                                                                  throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### parseClassData

          protected static Tuple<java.lang.Short,java.lang.String> parseClassData(org.w3c.dom.Node protocol)
                                                                           throws java.io.IOException

      Throws:
        `java.io.IOException`

Copyright © 1998-2009 Bela Ban / Red Hat. All Rights Reserved.