Class ClassDescription


  • public class ClassDescription
    extends Object

    A helper class for defining references to classes.

    Handling of classes can become quite complex because of issues with different class loaders. Because of that the dependency injection framework supports multiple ways of defining classes:

    • by directly specifying Class objects; this can be used when the class is already known at compile time
    • by providing only the class name; the class will then be resolved using a default class loader
    • by providing a class name and a symbolic name for a class loader; this works together with the class loader registration mechanism supported by BeanContext

    Instances of this class encapsulate the different ways of specifying a class. They can be initialized with different variants of class descriptions. The getTargetClass() method can be used for obtaining a reference to the wrapped class. Instances are thread-safe and can be shared between multiple components. New instances are created using the static factory methods.

    Version:
    $Id: ClassDescription.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Method Detail

      • getTargetClass

        public Class<?> getTargetClass​(ClassLoaderProvider clProvider)
        Returns the target class of this description. The passed in ClassLoaderProvider is used for resolving the class if necessary. This implementation will cache the Class objects when they have been resolved.
        Parameters:
        clProvider - the ClassLoaderProvider
        Returns:
        the target class of this description instance
        Throws:
        InjectionException - if the class cannot be resolved
        IllegalArgumentException - if the ClassLoaderProvider is needed, but is null
      • getTargetClassName

        public String getTargetClassName()
        Returns the name of the target class of this description.
        Returns:
        the name of the target class
      • getClassLoaderName

        public String getClassLoaderName()
        Returns the symbolic name of the class loader for resolving the class. This can be null if the default class loader is to be used.
        Returns:
        the name of the class loader to use
      • equals

        public boolean equals​(Object obj)
        Tests the passed in object for equality. Two objects of this class are considered equal if they have the same target class name and class loader name.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare to
        Returns:
        a flag whether the objects are equal
      • hashCode

        public int hashCode()
        Returns a hash code for this object.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code
      • toString

        public String toString()
        Returns a string representation of this object. This string will contain the name of the target class. If a class loader name is specified, this name will also be contained in the resulting string.
        Overrides:
        toString in class Object
        Returns:
        a string for this object
      • getInstance

        public static ClassDescription getInstance​(Class<?> cls)
        Returns an instance for the specified class. This method can be used when the target class is already known at compile time.
        Parameters:
        cls - the target class
        Returns:
        the description instance for this class
      • getInstance

        public static ClassDescription getInstance​(String clsName,
                                                   String clsLoaderName)
        Returns an instance for the specified class name and class loader name. The target class will be resolved using reflection. It is loaded from the class loader with the given symbolic name.
        Parameters:
        clsName - the name of the class
        clsLoaderName - the symbolic name of the class loader
        Returns:
        the description instance for this class
      • getInstance

        public static ClassDescription getInstance​(String clsName)
        Returns an instance for the specified class name that will be resolved using the default class loader.
        Parameters:
        clsName - the name of the class
        Returns:
        the description instance for this class