simple.util
Class Introspector

java.lang.Object
  extended by simple.util.Introspector

public class Introspector
extends java.lang.Object

The Introspector provides a means to invoke methods of arbitrary objects by matching a parameter list and name. The method matching done by this is similar, but more primitave, to the dynamic binding done by the Java runtime. This will basically attempt to find a method, in no specific order, that has the name specified and that takes parameters that are compatiable to those given to the invoke methods.

Author:
Niall Gallagher

Constructor Summary
Introspector(java.lang.Class type)
          Constructor for the Introspector class.
 
Method Summary
 java.lang.Object invoke(java.lang.String name, java.lang.Object target, java.lang.Object data)
          Performs a reflective invocation on a target object by means of discovering a method compatible with the arguments.
 java.lang.Object invoke(java.lang.String name, java.lang.Object target, java.lang.Object[] list)
          Performs a reflective invocation on a target object by means of discovering a method compatible with the arguments.
 java.lang.reflect.Method match(java.lang.String name, java.lang.Class type)
          This method performs the "discovery" of methods within the instance class.
 java.lang.reflect.Method match(java.lang.String name, java.lang.Class[] types)
          This method performs the "discovery" of methods within the instance class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Introspector

public Introspector(java.lang.Class type)
Constructor for the Introspector class. This will enable methods of the specified Class to be invoked using only the name of the method and the arguments to that method. The target of the invocation must be either the same type or a subclass of the class specified to this.

Parameters:
type - the object type the introspection is done with
Method Detail

match

public java.lang.reflect.Method match(java.lang.String name,
                                      java.lang.Class type)
                               throws java.lang.Exception
This method performs the "discovery" of methods within the instance class. This will attempt to find a match for a method with the specified name and that takes a parameter of the type represented by the issued Class.

The discovery of the method is done in no specific order. This will simply match aand retrieve the first method that is compatable with the signature described. If no match is found then this method will return null.

Parameters:
name - this is the name of the method to be invoked
type - this is the type of the single parameter
Returns:
returns the Method that is discovered
Throws:
java.lang.Exception - thrown if there is a problem matching

match

public java.lang.reflect.Method match(java.lang.String name,
                                      java.lang.Class[] types)
This method performs the "discovery" of methods within the instance class. This will attempt to find a match for a method with the specified name and that takes a parameter of the type represented by the Class array.

The discovery of the method is done in no specific order. This will simply match and retrieve the first method that is compatable with the signature described. If no match is found then this method will return null.

Parameters:
name - this is the name of the method to be invoked
types - these are the types of the method parameters
Returns:
returns the Method that is discovered

invoke

public java.lang.Object invoke(java.lang.String name,
                               java.lang.Object target,
                               java.lang.Object data)
                        throws java.lang.Exception
Performs a reflective invocation on a target object by means of discovering a method compatible with the arguments. The name of the method to be invoked coupled with the list of arguments are used to "discover" a signature within the class this Introspector instance was created to search.

If the target object is not of the same type as the type this instance was specified to use, then this method will throw an IllegalArgumentException. The target object therefore must be of the same type or a subclass of the type.

Parameters:
name - this is the name of the method to search for
target - this is the target object to be invoked
data - a single argument to be passed to the method
Returns:
this returns whatever the invoked method returns
Throws:
java.lang.IllegalAccessException - this is thrown if the method discovered is not public
java.lang.reflect.InvocationTargetException - this is thrown if the discovered method throws an exception
java.lang.IllegalArgumentException - thrown if the target object is not compatable with the issued type
java.lang.NoSuchMethodException - thrown if a matching method cannot be found for the class
java.lang.Exception

invoke

public java.lang.Object invoke(java.lang.String name,
                               java.lang.Object target,
                               java.lang.Object[] list)
                        throws java.lang.Exception
Performs a reflective invocation on a target object by means of discovering a method compatible with the arguments. The name of the method to be invoked coupled with the list of arguments are used to "discover" a signature within the class this Introspector instance was created to search.

If the target object is not of the same type as the type this instance was specified to use, then this method will throw an IllegalArgumentException. The target object therefore must be of the same type or a subclass of the type.

Parameters:
name - this is the name of the method to search for
target - this is the target object to be invoked
list - the list of arguments to be passed to the method
Returns:
this returns whatever the invoked method returns
Throws:
java.lang.IllegalAccessException - this is thrown if the method discovered is not public
java.lang.reflect.InvocationTargetException - this is thrown if the discovered method throws an exception
java.lang.IllegalArgumentException - thrown if the target object is not compatable with the issued type
java.lang.NoSuchMethodException - thrown if a matching method cannot be found for the class
java.lang.Exception