net.sf.jguiraffe.di.impl
Class ClassDescription

java.lang.Object
  extended by net.sf.jguiraffe.di.impl.ClassDescription

public class ClassDescription
extends java.lang.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:

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 156 2009-03-03 21:04:47Z oheger $
Author:
Oliver Heger

Method Summary
 boolean equals(java.lang.Object obj)
          Tests the passed in object for equality.
 java.lang.String getClassLoaderName()
          Returns the symbolic name of the class loader for resolving the class.
static ClassDescription getInstance(java.lang.Class<?> cls)
          Returns an instance for the specified class.
static ClassDescription getInstance(java.lang.String clsName)
          Returns an instance for the specified class name that will be resolved using the default class loader.
static ClassDescription getInstance(java.lang.String clsName, java.lang.String clsLoaderName)
          Returns an instance for the specified class name and class loader name.
 java.lang.Class<?> getTargetClass(ClassLoaderProvider depProvider)
          Returns the target class of this description.
 java.lang.String getTargetClassName()
          Returns the name of the target class of this description.
 int hashCode()
          Returns a hash code for this object.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getTargetClass

public java.lang.Class<?> getTargetClass(ClassLoaderProvider depProvider)
Returns the target class of this description. The passed in DependencyProvider is used for resolving the class if necessary. This implementation will cache the Class objects when they have been resolved.

Parameters:
depProvider - the dependency provider
Returns:
the target class of this description instance
Throws:
InjectionException - if the class cannot be resolved

getTargetClassName

public java.lang.String getTargetClassName()
Returns the name of the target class of this description.

Returns:
the name of the target class

getClassLoaderName

public java.lang.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(java.lang.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 java.lang.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 java.lang.Object
Returns:
a hash code

toString

public java.lang.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 java.lang.Object
Returns:
a string for this object

getInstance

public static ClassDescription getInstance(java.lang.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(java.lang.String clsName,
                                           java.lang.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(java.lang.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


Copyright © 2009 The JGUIraffe Team. All Rights Reserved.