fipaos.util
Class DynamicClass

java.lang.Object
  |
  +--fipaos.util.DynamicClass

public class DynamicClass
extends java.lang.Object

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


Inner Class Summary
static class DynamicClass.CollectionHint
          Hint for a collection type - details Classes than it can contain
static class DynamicClass.ConstrainedSelectionHint
          Hint for a property that should take only a constrained set of values
static class DynamicClass.ImmutableHint
          Hint that a CLASS is immutable (i.e.
static class DynamicClass.PossibleSelectionHint
          Hint for a property that COULD take a predefined set of values, or something else of the specified type
static class DynamicClass.Property
          Class to represent a property type
static class DynamicClass.PropertyHint
          Umbrella class PropertyHint that all property-hint types extend
 
Field Summary
static java.lang.String GET_HINTS_METHOD
          Indicates name of method to invoke in order to get hints for a particular property
 
Constructor Summary
DynamicClass(java.lang.Object obj)
          Creates a DynamicClass to wrap the given Object
DynamicClass(java.lang.String class_name)
          Creates an instance of the given class, using the default constructor.
DynamicClass(java.lang.String class_name, java.lang.Class[] params, java.lang.Object[] args)
          Creates an instance of the given class, using the constructor with the given arguments.
 
Method Summary
static java.lang.Object createInstance(java.lang.String class_name)
          Instantiate an instance of a particular class
static java.lang.Object createInstance(java.lang.String class_name, java.lang.Class[] param_types, java.lang.Object[] params)
          Instatiates a class, using a constructor with the given parameters
 java.lang.Object duplicate()
          Attempt to duplicate the object this DynamicClass wrapps using the following mechanisms in the given order: Object.clone() Serialization
 DynamicClass.PropertyHint getHint(java.lang.String property)
          Get the hint (if available) for the given property - returns null if no hint available
 java.lang.Object getObject()
           
 java.util.List getProperties()
          Gets the properties for this object (i.e.
 java.lang.Object invoke(java.lang.String method)
          Invokes a method on the wrapper object without any arguments
 java.lang.Object invoke(java.lang.String method, java.lang.Class[] params, java.lang.Object[] args)
          Invokes a method on the wrapper object with the given arguments
static java.lang.Object invokeStatic(java.lang.String class_name, java.lang.String method)
          Invokes a method on the given object with no arguments
static java.lang.Object invokeStatic(java.lang.String class_name, java.lang.String method, java.lang.Class[] params, java.lang.Object[] args)
          Invokes a method on the given object with the given arguments
static void main(java.lang.String[] args)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GET_HINTS_METHOD

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

DynamicClass

public DynamicClass(java.lang.String class_name,
                    java.lang.Class[] params,
                    java.lang.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(java.lang.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(java.lang.Object obj)
Creates a DynamicClass to wrap the given Object
Parameters:
obj - Wrap the given object
Method Detail

invoke

public java.lang.Object invoke(java.lang.String method,
                               java.lang.Class[] params,
                               java.lang.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 java.lang.Object invoke(java.lang.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 java.lang.Object invokeStatic(java.lang.String class_name,
                                            java.lang.String method,
                                            java.lang.Class[] params,
                                            java.lang.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 java.lang.Object invokeStatic(java.lang.String class_name,
                                            java.lang.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.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getObject

public java.lang.Object getObject()

createInstance

public static java.lang.Object createInstance(java.lang.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 java.lang.Object createInstance(java.lang.String class_name,
                                              java.lang.Class[] param_types,
                                              java.lang.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 java.lang.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

getProperties

public java.util.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


getHint

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

main

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