Package net.sf.jguiraffe.di.impl
Class ClassDescription
- java.lang.Object
-
- net.sf.jguiraffe.di.impl.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
- by directly specifying
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Tests the passed in object for equality.String
getClassLoaderName()
Returns the symbolic name of the class loader for resolving the class.static ClassDescription
getInstance(Class<?> cls)
Returns an instance for the specified class.static ClassDescription
getInstance(String clsName)
Returns an instance for the specified class name that will be resolved using the default class loader.static ClassDescription
getInstance(String clsName, String clsLoaderName)
Returns an instance for the specified class name and class loader name.Class<?>
getTargetClass(ClassLoaderProvider clProvider)
Returns the target class of this description.String
getTargetClassName()
Returns the name of the target class of this description.int
hashCode()
Returns a hash code for this object.String
toString()
Returns a string representation of this object.
-
-
-
Method Detail
-
getTargetClass
public Class<?> getTargetClass(ClassLoaderProvider clProvider)
Returns the target class of this description. The passed inClassLoaderProvider
is used for resolving the class if necessary. This implementation will cache theClass
objects when they have been resolved.- Parameters:
clProvider
- theClassLoaderProvider
- Returns:
- the target class of this description instance
- Throws:
InjectionException
- if the class cannot be resolvedIllegalArgumentException
- if theClassLoaderProvider
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.
-
hashCode
public int hashCode()
Returns a hash code for this object.
-
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.
-
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 classclsLoaderName
- 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
-
-