Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.crosswire.common.util
Class ClassUtil

    java.lang.Object
      org.crosswire.common.util.ClassUtil

    public final class ClassUtil

extends Object

Various Java Class Utilities.

Author:
  Joe Walker [joe at eireneh dot com]
See Also:
  `for license details.
  The copyright to this program is held by it's authors.`

Field Summary
`private static String` | `DEFAULT` The string for default implementations
`private static String` | `EXTENSION_CLASS`
`private static String` | `EXTENSION_JAR`
`private static String` | `EXTENSION_ZIP`
`private static char` | `INNER_CLASS_SEPARATOR_CHAR` The inner class separator character: `$`.
`private static Logger` | `log` The log stream
`private static char` | `PACKAGE_SEPARATOR_CHAR` The package separator character: `.`.

Constructor Summary
`private` | `ClassUtil()` Prevent Instansiation

Method Summary
`static String` | `findClasspathEntry(String classname)` This function find the first matching filename for a Java class file from the classpath, if none is found it returns null.
`static String` | `findClasspathEntry(String classname, String classpath)` This function finds the first matching filename for a Java class file from the classpath, if none is found it returns null.
`static Object` | `getImplementation(Class clazz)` Get and instansiate the preferred implementor of some interface or abstract class.
`static Class` | `getImplementor(Class clazz)` Get the preferred implementor of some interface or abstract class.
`static Class[]` | `getImplementors(Class clazz)` Get the known implementors of some interface or abstract class.
`static Map` | `getImplementorsMap(Class clazz)` Get a map of known implementors of some interface or abstract class.
`static String` | `getShortClassName(Class cls)` Gets the class name minus the package name from a `Class`.
`static String` | `getShortClassName(Object object, String valueIfNull)` Gets the class name minus the package name for an `Object`.
`static String` | `getShortClassName(String className)` Gets the class name minus the package name from a String.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### PACKAGE_SEPARATOR_CHAR

    private static final char PACKAGE_SEPARATOR_CHAR

  The package separator character: `.`.

  See Also:
    Constant Field Values

### INNER_CLASS_SEPARATOR_CHAR

    private static final char INNER_CLASS_SEPARATOR_CHAR

  The inner class separator character: `$`.

  See Also:
    Constant Field Values

### EXTENSION_CLASS

    private static final String EXTENSION_CLASS

See Also:
  Constant Field Values

### EXTENSION_JAR

    private static final String EXTENSION_JAR

See Also:
  Constant Field Values

### EXTENSION_ZIP

    private static final String EXTENSION_ZIP

See Also:
  Constant Field Values

### log

    private static final Logger log

  The log stream

### DEFAULT

    private static final String DEFAULT

  The string for default implementations

  See Also:
    Constant Field Values

Constructor Detail

### ClassUtil

    private ClassUtil()

  Prevent Instansiation

Method Detail

### findClasspathEntry

    public static String findClasspathEntry(String classname,
                                            String classpath)

  This function finds the first matching filename for a Java class file from the classpath, if none is found it returns null.

### findClasspathEntry

    public static String findClasspathEntry(String classname)

  This function find the first matching filename for a Java class file from the classpath, if none is found it returns null.

### getImplementors

    public static Class[] getImplementors(Class clazz)

  Get the known implementors of some interface or abstract class. This is currently done by looking up a properties file by the name of the given class, and assuming that values are implementors of said class. Those that are not are warned, but ignored.

  Parameters:
    `clazz` - The class or interface to find implementors of.
  Returns:
    The list of implementing classes.

### getImplementorsMap

    public static Map getImplementorsMap(Class clazz)

  Get a map of known implementors of some interface or abstract class. This is currently done by looking up a properties file by the name of the given class, and assuming that values are implementors of said class. Those that are not are warned, but ignored. The reply is in the form of a map of keys=strings, and values=classes in case you need to get at the names given to the classes in the properties file.

  Parameters:
    `clazz` - The class or interface to find implementors of.
  Returns:
    The map of implementing classes.
  See Also:
    `getImplementors(Class)`

### getImplementor

    public static Class getImplementor(Class clazz)
                                throws IOException,
                                       ClassNotFoundException,
                                       ClassCastException

  Get the preferred implementor of some interface or abstract class. This is currently done by looking up a properties file by the name of the given class, and assuming that the "default" key is an implemention of said class. Warnings are given otherwise.

  Parameters:
    `clazz` - The class or interface to find an implementation of.
  Returns:
    The configured implementing class.
  Throws:
    `MalformedURLException` - if the properties file can not be found
    `IOException` - if there is a problem reading the found file
    `ClassNotFoundException` - if the read contents are not found
    `ClassCastException` - if the read contents are not valid
  See Also:
    `getImplementors(Class)`

### getImplementation

    public static Object getImplementation(Class clazz)
                                    throws MalformedURLException,
                                           ClassCastException,
                                           IOException,
                                           ClassNotFoundException,
                                           InstantiationException,
                                           IllegalAccessException

  Get and instansiate the preferred implementor of some interface or abstract class.

  Parameters:
    `clazz` - The class or interface to find an implementation of.
  Returns:
    The configured implementing class.
  Throws:
    `MalformedURLException` - if the properties file can not be found
    `IOException` - if there is a problem reading the found file
    `ClassNotFoundException` - if the read contents are not found
    `ClassCastException` - if the read contents are not valid
    `InstantiationException` - if the new object can not be instansiated
    `IllegalAccessException` - if the new object can not be instansiated
  See Also:
    `getImplementors(Class)`

### getShortClassName

    public static String getShortClassName(Object object,
                                           String valueIfNull)

  Gets the class name minus the package name for an `Object`.

  Parameters:
    `object` - the class to get the short name for, may be null
    `valueIfNull` - the value to return if null
  Returns:
    the class name of the object without the package name, or the null value

### getShortClassName

    public static String getShortClassName(Class cls)

  Gets the class name minus the package name from a `Class`.

  Parameters:
    `cls` - the class to get the short name for, must not be `null`
  Returns:
    the class name without the package name
  Throws:
    `IllegalArgumentException` - if the class is `null`

### getShortClassName

    public static String getShortClassName(String className)

  Gets the class name minus the package name from a String.

  The string passed in is assumed to be a class name - it is not checked.

  Parameters:
    `className` - the className to get the short name for, must not be empty or `null`
  Returns:
    the class name of the class without the package name
  Throws:
    `IllegalArgumentException` - if the className is empty

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Copyright ? 2003-2006
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD