net.spy.util
Class Instantiator<C>

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.util.Instantiator<C>
Type Parameters:
C - the type of object to be instantiated.

public class Instantiator<C>
extends SpyObject

Generic object instantiator. The factory factory.


Constructor Summary
protected Instantiator()
          Default constructor to allow subclasses to figure out how they want to build their instance.
  Instantiator(String className)
          Create an instantiator for the given class name.
  Instantiator(String className, ClassLoader cl)
          Create an instantiator for the given class name in the given class loader.
 
Method Summary
protected  C createInstance(String className)
          Create an instance of the given class (expected to be a C).
protected  C createInstance(String className, ClassLoader cl)
          Create an instance of the given class (expected to be a C).
 C getInstance()
          Get the instantiated instance.
protected  void setInstance(C i)
          Set the instance.
 
Methods inherited from class net.spy.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Instantiator

protected Instantiator()
                throws Exception
Default constructor to allow subclasses to figure out how they want to build their instance. It's expected that the instance will be set after this invocation.

Throws:
Exception
See Also:
setInstance(Object)

Instantiator

public Instantiator(String className)
             throws Exception
Create an instantiator for the given class name.

Parameters:
className - the name of the class to instantiate
Throws:
Exception - if the instance can't be instantiated

Instantiator

public Instantiator(String className,
                    ClassLoader cl)
             throws Exception
Create an instantiator for the given class name in the given class loader.

Parameters:
className - the name of the class to load
cl - the class loader to use to instantiate the class
Throws:
Exception - if the instance can't be instantiated
Method Detail

setInstance

protected void setInstance(C i)
Set the instance. This may only be invoked once.

Parameters:
i - the instance

createInstance

protected C createInstance(String className)
                    throws Exception
Create an instance of the given class (expected to be a C).

Parameters:
className - the name of the class
Returns:
the new instance
Throws:
Exception - if the class can't be instantiated

createInstance

protected C createInstance(String className,
                           ClassLoader cl)
                    throws Exception
Create an instance of the given class (expected to be a C).

Parameters:
className - the name of the class
Returns:
the new instance
Throws:
Exception - if the class can't be instantiated

getInstance

public C getInstance()
              throws Exception
Get the instantiated instance.

Throws:
Exception


Copyright © 1995-2007 SPY Internetworking. All Rights Reserved.