fipaos.util
Class DynamicClass


public class DynamicClass

This class provides dynamic access to methods of classes which may not be available at compile time & run time.


Inner Class Summary
 public static classDynamicClass.CollectionHint
          Hint for a collection type - details Classes than it can contain
 public static classDynamicClass.ConstrainedSelectionHint
          Hint for a property that should take only a constrained set of values
 public static classDynamicClass.ImmutableHint
          Hint that a CLASS is immutable (i.e.
 public static classDynamicClass.PossibleSelectionHint
          Hint for a property that COULD take a predefined set of values, or something else of the specified type
 public static classDynamicClass.Property
          Class to represent a property type
 public static classDynamicClass.PropertyHint
          Umbrella class PropertyHint that all property-hint types extend

Field Summary
 final static StringGET_HINTS_METHOD
          Indicates name of method to invoke in order to get hints for a particular property

Constructor Summary
DynamicClass(String class_name, Class[] params, Object[] args)
          Creates an instance of the given class, using the constructor with the given arguments.
DynamicClass(String class_name)
          Creates an instance of the given class, using the default constructor.
DynamicClass(Object obj)
          Creates a DynamicClass to wrap the given Object

Method Summary
 static ObjectcreateInstance(String class_name)
          Instantiate an instance of a particular class
 static ObjectcreateInstance(String class_name, Class[] param_types, Object[] params)
          Instatiates a class, using a constructor with the given parameters
 Objectduplicate()
          Attempt to duplicate the object this DynamicClass wrapps using the following mechanisms in the given order: Object.clone() Serialization
 PropertyHintgetHint(String property)
          Get the hint (if available) for the given property - returns null if no hint available
 ObjectgetObject()
           
 ListgetProperties()
          Gets the properties for this object (i.e.
 Objectinvoke(String method, Class[] params, Object[] args)
          Invokes a method on the wrapper object with the given arguments
 Objectinvoke(String method)
          Invokes a method on the wrapper object without any arguments
 static ObjectinvokeStatic(String class_name, String method, Class[] params, Object[] args)
          Invokes a method on the given object with the given arguments
 static ObjectinvokeStatic(String class_name, String method)
          Invokes a method on the given object with no arguments
 static voidmain(String[] args)
           
 StringtoString()
           

Field Detail

GET_HINTS_METHOD

public final static String GET_HINTS_METHOD
Indicates name of method to invoke in order to get hints for a particular property
Constructor Detail

DynamicClass

public DynamicClass(String class_name, Class[] params, Object[] args)
throws java.lang.ClassNotFoundException,
java.lang.NoSuchMethodException,
java.lang.InstantiationException,
DynamicClassException
Creates an instance of the given class, using the constructor with the given arguments. NOTE: Primitive types (e.g. int, char, double) should be wrapped in their java.lang wrapper classes (e.g. Integer, Double etc...)
Parameters:
class_name - Name of the class to wrap
params - Argument signature for the constructor to use
args - Array containing parameters for constructor of class to wrap

DynamicClass

public DynamicClass(String class_name)
throws java.lang.ClassNotFoundException,
java.lang.NoSuchMethodException,
java.lang.InstantiationException,
DynamicClassException
Creates an instance of the given class, using the default constructor.
Parameters:
class_name - Name of the class to wrap
args - Array containing parameters for constructor of class to wrap

DynamicClass

public DynamicClass(Object obj)
Creates a DynamicClass to wrap the given Object
Parameters:
obj - Wrap the given object
Method Detail

createInstance

public static Object createInstance(String class_name)
Instantiate an instance of a particular class
Parameters:
class_name - Fully qualified name of the class to instantitate
Returns: An instance of the given class, or null if some error occured whilst instantiating an instance

createInstance

public static Object createInstance(String class_name, Class[] param_types, Object[] params)
Instatiates a class, using a constructor with the given parameters
Parameters:
class_name - Name of the class to instantiate
param_types - An array of the types of the parameters of the constructor to use
params - The actual parameters to the constructor
Returns: The instantiated object, or null if something went wrong

duplicate

public Object duplicate()
Attempt to duplicate the object this DynamicClass wrapps using the following mechanisms in the given order:
Returns: A duplicate of the wrapped object, or null if this couldn't be achieved

getHint

public PropertyHint getHint(String property)
Get the hint (if available) for the given property - returns null if no hint available

getObject

public Object getObject()

getProperties

public List getProperties()
Gets the properties for this object (i.e. matching get/set pairs)

The List returned contains Property instances, or null if the Object is immutable


invoke

public Object invoke(String method, Class[] params, Object[] args)
throws DynamicClassException,
java.lang.NoSuchMethodException
Invokes a method on the wrapper object with the given arguments
Parameters:
method - The name of the method to invoke
params - Classes of arguments making up signature of method to invoke
args - An array of object to be used as arguments to the method being invoked (primitive types should be wrapped in appropriate Java classes (e.g. double => Double ).
Returns: The result of the operation, null if the method was void or an object wrapping the result if the return type is a primitive.

invoke

public Object invoke(String method)
throws DynamicClassException,
java.lang.NoSuchMethodException
Invokes a method on the wrapper object without any arguments
Parameters:
method - The name of the method to invoke
Returns: The result of the operation, null if the method was void or an object wrapping the result if the return type is a primitive.

invokeStatic

public static Object invokeStatic(String class_name, String method, Class[] params, Object[] args)
throws DynamicClassException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException
Invokes a method on the given object with the given arguments
Parameters:
method - The name of the method to invoke
args - An array of object to be used as arguments to the method being invoked (primitive types should be wrapped in appropriate Java classes (e.g. double => Double ).
params - The classes of the arguments of the method to invoke
Returns: The result of the operation, null if the method was void or an object wrapping the result if the return type is a primitive.

invokeStatic

public static Object invokeStatic(String class_name, String method)
throws DynamicClassException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException
Invokes a method on the given object with no arguments
Parameters:
method - The name of the method to invoke
Returns: The result of the operation, null if the method was void or an object wrapping the result if the return type is a primitive.

main

public static void main(String[] args)
throws java.lang.Throwable

toString

public String toString()

Association Links

to Class java.lang.String

Indicates name of method to invoke in order to get hints for a particular property

to Class java.lang.Object

Object to wrap and dynamically invoke methods on

to Class java.lang.Class

Class representing the wrapped object