mandala.jacob
Class Instanciator

java.lang.Object
  extended bymandala.jacob.Instanciator
All Implemented Interfaces:
java.io.Serializable

public class Instanciator
extends java.lang.Object
implements java.io.Serializable

Allows indirect instanciation of objects.

This class provides an elegant solution for both remote instanciaton and making non-serializable objects remotely accessible by being remotely inserted into an active map.

Each instance of this class has a related active map in which fresh instances are stored. Each instance also has a default constructor which is returned by getConstructor() to prevent caller from specifying same constructor multiple times.

Version:
$Revision: 1.3 $
Author:
eipi
See Also:
ActiveMap, Serialized Form

Field Summary
protected  ConstructorOp constructor
           Prevents multiple same constructor specification
 
Method Summary
 boolean equals(java.lang.Object o)
           
 ActiveMap getActiveMap()
          Returns the related ActiveMap.
 ConstructorOp getConstructor()
          Returns the default constructor.
static StoredObjectReference getInstance(ActiveMap activeMap)
          Equivalent to getInstance(activeMap, null).
static StoredObjectReference getInstance(ActiveMap activeMap, ConstructorOp constructor)
          Get the StoredObjectReference on the Instanciator instance which is related to the given activeMap.
 int hashCode()
           
 java.lang.Object instanciate(ConstructorOp constructor, java.lang.Object[] args)
          Instanciate a new object and associates it with a new key.
 java.lang.Object instanciate(java.lang.Object[] args)
          Equivalent to instanciate(getConstructorOp(), args).
 java.lang.Object instanciateWith(ConstructorOp constructor, java.lang.Object[] keys)
          Instanciate a new object with parameters taken from the active map and associates it with a new key.
 java.lang.Object instanciateWith(java.lang.Object[] keys)
          Equivalent to instanciateWith(getConstructorOp(), keys).
 ConstructorOp setConstructor(ConstructorOp constructor)
          Sets the default constructor.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

constructor

protected ConstructorOp constructor

Prevents multiple same constructor specification

Method Detail

getInstance

public static StoredObjectReference getInstance(ActiveMap activeMap,
                                                ConstructorOp constructor)

Get the StoredObjectReference on the Instanciator instance which is related to the given activeMap.

If an instance is not already mapped to the given activeMap is is created and stored into the activeMap so the returned StoredObjectReference references it.

Parameters:
activeMap - the active map in which the instanciator must inserts fresh instances
constructor - the default constructor to use
Returns:
the StoredObjectReference referencing the instanciator related to the given activeMap

getInstance

public static StoredObjectReference getInstance(ActiveMap activeMap)

Equivalent to getInstance(activeMap, null).

Parameters:
activeMap - an ActiveMap value
Returns:
a StoredObjectReference value

equals

public boolean equals(java.lang.Object o)

hashCode

public int hashCode()

getConstructor

public ConstructorOp getConstructor()

Returns the default constructor.

Returns:
a ConstructorOp value

setConstructor

public ConstructorOp setConstructor(ConstructorOp constructor)

Sets the default constructor.

Parameters:
constructor - a ConstructorOp value
Returns:
a ConstructorOp value

getActiveMap

public ActiveMap getActiveMap()

Returns the related ActiveMap.

Returns:
an ActiveMap value

instanciate

public java.lang.Object instanciate(java.lang.Object[] args)
                             throws java.lang.InstantiationException,
                                    java.lang.IllegalAccessException,
                                    java.lang.IllegalArgumentException,
                                    java.lang.reflect.InvocationTargetException

Equivalent to instanciate(getConstructorOp(), args).

Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
See Also:
instanciate(ConstructorOp, Object[])

instanciate

public java.lang.Object instanciate(ConstructorOp constructor,
                                    java.lang.Object[] args)
                             throws java.lang.InstantiationException,
                                    java.lang.IllegalAccessException,
                                    java.lang.IllegalArgumentException,
                                    java.lang.reflect.InvocationTargetException

Instanciate a new object and associates it with a new key.

Parameters:
constructor - the constructor to use for the instanciation
args - the arguments used for the instanciation
Returns:
the key which the new object is to be associated with
Throws:
java.lang.InstantiationException - if the class that declares the underlying constructor represents an abstract class.
InvocationTargetException - if the underlying constructor throws an exception.
java.lang.ExceptionInInitializerError - if the initialization provoked by this method fails.
java.lang.ClassCastException - if the class of the specified key or value prevents it from being stored in this map.
java.lang.IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map.
java.lang.NullPointerException - this map does not permit null keys or values, and the specified key or value is null.
java.lang.IllegalAccessException - if the underlying constructor is inaccessible.
java.lang.IllegalArgumentException - if the number of actual and formal parameters differ, or if an unwrapping or method invocation conversion fails.
Since:
2.2
See Also:
Map.put(Object, Object), ConstructorOp.newInstance(Object[])

instanciateWith

public java.lang.Object instanciateWith(java.lang.Object[] keys)
                                 throws java.lang.InstantiationException,
                                        java.lang.IllegalAccessException,
                                        java.lang.IllegalArgumentException,
                                        java.lang.reflect.InvocationTargetException

Equivalent to instanciateWith(getConstructorOp(), keys).

Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
See Also:
instanciate(ConstructorOp, Object[])

instanciateWith

public java.lang.Object instanciateWith(ConstructorOp constructor,
                                        java.lang.Object[] keys)
                                 throws java.lang.InstantiationException,
                                        java.lang.IllegalAccessException,
                                        java.lang.IllegalArgumentException,
                                        java.lang.reflect.InvocationTargetException

Instanciate a new object with parameters taken from the active map and associates it with a new key.

The key arguments represent the stored objects to use for the instanciation.

Parameters:
constructor - the constructor to use for the instanciation
keys - the mapping of the stored objects used for the instanciation
Returns:
the key which the new object is to be associated with
Throws:
java.lang.InstantiationException - if the class that declares the underlying constructor represents an abstract class.
InvocationTargetException - if the underlying constructor throws an exception.
java.lang.ExceptionInInitializerError - if the initialization provoked by this method fails.
java.lang.ClassCastException - if the class of the specified key or value prevents it from being stored in this map.
java.lang.IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map.
java.lang.NullPointerException - this map does not permit null keys or values, and the specified key or value is null.
java.lang.IllegalAccessException - if the underlying constructor is inaccessible.
java.lang.IllegalArgumentException - if the number of actual and formal parameters differ, or if an unwrapping or method invocation conversion fails.
Since:
2.2
See Also:
Map.put(Object, Object), ConstructorOp.newInstance(Object[])

toString

public java.lang.String toString()


Mandala help mailing list