com.ls.util.objectcontrol
Class DynamicObjectController

java.lang.Object
  |
  +--com.ls.util.objectcontrol.DynamicObjectController
All Implemented Interfaces:
Serializable

public class DynamicObjectController
extends Object
implements Serializable

Object controller class, which allows to dynamically instantiate and configure objects in two ways:

  1. Instantiate an object of a specified class once, configure it (if wanted) and store the object under a specified key in an internal map.
    This is used, if only one instance of that object is needed at runtime.
    The user of the object is responsible for synchronization issues regarding the object!
  2. Store an object definition under a specified key in an internal map containing object definitions and instantiate and configure a new object of that class at each request.
    This is used, if multiple instances of that object are needed at runtime.
The object is instantiated in every case by using the default constructor (the one without arguments). To use the automatic configuration of the object, the object needs to implement the IConfigurable interface.

Version:
$Revision: 1.5 $
Author:
Last modified by $Author: JBogenschuetz $
See Also:
Serialized Form

Constructor Summary
DynamicObjectController()
           
 
Method Summary
 void defineObject(Object key, String className)
          Defines access of an object of the given class.
 void defineObject(Object key, String className, Map configuration)
          Stores an object definition of the given class in an internal Map under the given key.
 Object getInstanceFromDefined(Object key)
          Retrieves a previously stored object defininition from an internal Map and instantiates that object.
 Object getLoaded(Object key)
          Retrieves a previously loaded object from an internal Map.
 void loadObject(Object key, String className)
          Instantiates an object of the given class.
 void loadObject(Object key, String className, Map configuration)
          Instantiates and possibly configures an object of the given class.
 void removeDefined(Object key)
          Deletes a previously stored object definition from an internal Map.
 Object removeLoaded(Object key)
          Deletes a previously loaded object from an internal Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicObjectController

public DynamicObjectController()
Method Detail

loadObject

public void loadObject(Object key,
                       String className,
                       Map configuration)
                throws ObjectControlException
Instantiates and possibly configures an object of the given class. If a configuration is performed, depends on, if the object implements IConfigurable. If yes, configure(configuration) with the given Map is called on the new object.
In the end the new object is stored in an internal Map under the given key.
Parameters:
key - with help of the key one later can access the loaded object
className - fully qualified class name of object to be instantiated
configuration - parameters for configuration, see IConfigurable.configure(Map)
Throws:
ObjectControlException - if the given key is already used for another stored object or if the instantiation of the object fails or if the configuration of the object fails or if any of the arguments is null
See Also:
loadObject(Object,String), getLoaded(java.lang.Object), removeLoaded(java.lang.Object)

loadObject

public void loadObject(Object key,
                       String className)
                throws ObjectControlException
Instantiates an object of the given class. Then the new object is stored in an internal Map under the given key.
Parameters:
key - with help of the key one later can access the loaded object
className - fully qualified class name of object to be instantiated
Throws:
ObjectControlException - if the given key is already used for another stored object or if the instantiation of the object fails or if any of the arguments is null
See Also:
loadObject(Object,String,Map), getLoaded(java.lang.Object), removeLoaded(java.lang.Object)

getLoaded

public Object getLoaded(Object key)
                 throws ObjectControlException
Retrieves a previously loaded object from an internal Map. The given key is used to identify the wanted object.
Parameters:
key - identifies the object to get
Returns:
the object, which is internally stored under the specified key
Throws:
ObjectControlException - if no object is stored under the given key or if key is null
See Also:
loadObject(Object,String,Map), loadObject(Object,String), removeLoaded(java.lang.Object)

removeLoaded

public Object removeLoaded(Object key)
                    throws ObjectControlException
Deletes a previously loaded object from an internal Map. The given key is used to identify the wanted object.
Parameters:
key - identifies the object to delete
Returns:
the object, which was previously stored under the specified key
Throws:
ObjectControlException - if no object is stored under the given key or if key is null
See Also:
loadObject(Object,String,Map), loadObject(Object,String), getLoaded(java.lang.Object)

defineObject

public void defineObject(Object key,
                         String className,
                         Map configuration)
                  throws ObjectControlException
Stores an object definition of the given class in an internal Map under the given key. The configuration parameter is used at instantiation time to configure the defined object.
Parameters:
key - with help of the key one later can access the defined object
className - fully qualified class name of object to be defined
configuration - parameters for configuration, see IConfigurable.configure(Map)
Throws:
ObjectControlException - if the given key is already used for another defined object or if any of the arguments is null
See Also:
defineObject(Object,String), getInstanceFromDefined(java.lang.Object), removeDefined(java.lang.Object)

defineObject

public void defineObject(Object key,
                         String className)
                  throws ObjectControlException
Defines access of an object of the given class. The "defined object" is stored in an internal Map under the given key.
Parameters:
key - with help of the key one later can access the defined object
className - fully qualified class name of object to be defined
Throws:
ObjectControlException - if the given key is already used for another defined object or if any of the arguments is null
See Also:
defineObject(Object,String,Map), getInstanceFromDefined(java.lang.Object), removeDefined(java.lang.Object)

getInstanceFromDefined

public Object getInstanceFromDefined(Object key)
                              throws ObjectControlException
Retrieves a previously stored object defininition from an internal Map and instantiates that object. (The given key is used to identify the wanted definition.) If the definition contains configuration parameters and the newly created object implements IConfigurable, IConfigurable.configure(Map) with the stored configuration parameters is called on the new object.
Parameters:
key - identifies the object definition to be used for instantiating a new object
Returns:
new object instance fitting the stored object definition
Throws:
ObjectControlException - if no object definition is stored under the given key or if the instantiation of the object fails or if the configuration of the object fails or if key is null
See Also:
defineObject(Object,String,Map), defineObject(Object,String), removeDefined(java.lang.Object)

removeDefined

public void removeDefined(Object key)
                   throws ObjectControlException
Deletes a previously stored object definition from an internal Map. The given key is used to identify the wanted object definition.
Parameters:
key - identifies the object definition to delete
Throws:
ObjectControlException - if no object definition is stored under the given key or if key is null
See Also:
defineObject(Object,String,Map), defineObject(Object,String), getInstanceFromDefined(java.lang.Object)