com.ccg.beans
Class ObjectFactoryAdapter

java.lang.Object
  extended by com.ccg.beans.ObjectFactoryAdapter
All Implemented Interfaces:
ObjectFactory
Direct Known Subclasses:
NamedObjectFactory

public class ObjectFactoryAdapter
extends Object
implements ObjectFactory

Adapater which can be used to implement the ObjectFactory interface.

This adapter provides a full implementation of the ObjectFactory interface. It provides the following three functions:

Since:
1.0
Version:
$Revision: 1.1 $
Author:
$Author: pkb $

Constructor Summary
ObjectFactoryAdapter()
          Initializes the object and associates the Object.class with the object.
ObjectFactoryAdapter(Class oclass)
          Initializes the object and associates the specified class.
ObjectFactoryAdapter(String cname)
          Initializes the object and associates the specified class.
 
Method Summary
static ObjectFactory createNamedObjectFactory(String name, Class oc)
          Creates a new ObjectFactory for an associated class with an optional string name.
 Object createObjectInstance()
          Creates a new instance of the type of object associated with the menu item.
static Object createObjectInstance(Class oclass)
          Creates a new instance of the object associated with the Class passed.
 Class getObjectClass()
          Get the Class associated with the object factory.
 void setObjectClass(Class val)
          Set the Class associated with the object factory.
static Class stringToClass(String cname)
          Convert a string into a Class object.
 String toString()
          Get a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectFactoryAdapter

public ObjectFactoryAdapter()
Initializes the object and associates the Object.class with the object.

Since:
1.0

ObjectFactoryAdapter

public ObjectFactoryAdapter(Class oclass)
Initializes the object and associates the specified class.

Parameters:
val - Class to associate with menu item (must not be null).
Throws:
NullPointerException - If you pass null.
Since:
1.0
See Also:
setObjectClass(java.lang.Class)

ObjectFactoryAdapter

public ObjectFactoryAdapter(String cname)
Initializes the object and associates the specified class.

Parameters:
cname - Fully qualified name of the class to associate (like: "java.util.Date").
Throws:
IllegalArgumentException - If we could not resolve the string passed to a available class within the CLASSPATH.
NullPointerException - If you pass null.
Since:
1.0
See Also:
setObjectClass(java.lang.Class)
Method Detail

stringToClass

public static Class stringToClass(String cname)
                           throws NullPointerException,
                                  IllegalArgumentException
Convert a string into a Class object.

This static helper method is used to convert a arbitrary string into the Class object which it represents. This method either succeeds and returns a non-null value, or fails and throws a exception (you never get null back).

This method is intended to aid those implementing the ObjectFactory, but can be used by anyone.

Parameters:
cname - Fully qualified name of the class to associate (like: "java.util.Date").
Returns:
The Class which the string value referred to - never returns null.
Throws:
IllegalArgumentException - If we could not resolve the string passed to a available class within the CLASSPATH.
NullPointerException - If you pass null.
Since:
1.0

setObjectClass

public final void setObjectClass(Class val)
Set the Class associated with the object factory.

This method is used to set the associated class. The class set, should either have a usable default constructor (in order for the factory to create new instances), OR you should override the createObjectInstance method to access your specialized constructor.

Parameters:
val - Class to associate with menu item (must not be null).
Throws:
NullPointerException - If you pass null.
See Also:
getObjectClass()

getObjectClass

public final Class getObjectClass()
Get the Class associated with the object factory.

Specified by:
getObjectClass in interface ObjectFactory
Returns:
Current Class value assigned - never returns null.
See Also:
setObjectClass(java.lang.Class)

createObjectInstance

public static Object createObjectInstance(Class oclass)
                                   throws IllegalStateException
Creates a new instance of the object associated with the Class passed.

This static method attempts to create a new instance of the passed class by using the default constructor of the class. If the class does not have a accessible default constructor, a exception is thrown (null is never returned).

This static method is intended for those implementing the ObjectFactory interface (in particular the createObjectInstance method), and hence throws a IllegalStateException instead of a IllegalArgumentException.

Returns:
New instance of a object associated with the menu item (never returns null).
Throws:
IllegalStateException - If the class has not been set, or we could not create a new instance of the object using the newInstance method.
Since:
1.0
See Also:
setObjectClass(java.lang.Class)

createObjectInstance

public Object createObjectInstance()
                            throws IllegalStateException
Creates a new instance of the type of object associated with the menu item.

This method attempts to create a new instance of the associated class by using the default constructor of the associated class. If the associated class does not have a accessible default constructor, a exception is thrown (null is never returned).

Specified by:
createObjectInstance in interface ObjectFactory
Returns:
New instance of a object associated with the menu item (never returns null).
Throws:
IllegalStateException - If the class has not been set, or we could not create a new instance of the object using the newInstance method.
Since:
1.0
See Also:
setObjectClass(java.lang.Class)

toString

public String toString()
Get a string representation of the object.

Overrides:
toString in class Object
Returns:
The name of the associated class.
Since:
1.0

createNamedObjectFactory

public static ObjectFactory createNamedObjectFactory(String name,
                                                     Class oc)
Creates a new ObjectFactory for an associated class with an optional string name.

This static method allows one to construct a Object factory instance but assign it a different textual name (set what the toString() method returns).

Parameters:
name - The text name you want to associate with the ObjectFactory, or null if you want to take it from the associated object class.
oc - The class to be associated with the ObjectFactory (it should have a working default constructor).
Returns:
New object factory.
Throws:
NullPointerException - If 'oc' was null.
Since:
1.0


Copyright 1998-1998-2006 null. All Rights Reserved.