Class sysExt.methodRef
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sysExt.methodRef

java.lang.Object
   |
   +----sysExt.methodRef

public class methodRef
extends Object
Abstraction of a method reference. Used for dynamic method dispatching, aka a method callback mechanism. Several convenience methods are provided. Examples:
 import testPkg.* ; // contains greeter class..
 import sysExt.* ;  // contains methodRef class
 // Create a target object..
 greeter aGreeter = new greeter (1);
 // 'point' to sayHello() action, and set the target to aGreeter.
 methodRef mr = methodRef.newRef(aGreeter, "sayHello"); 
 // make aGreeter 'perform' sayHello()
 mr.doAction();
        .
        .
 // now point to sayGoodBye() action..
 methodRef mr2 = methodRef.newRef("testPkg",
                                  "greeter",
                                  "sayGoodbye");
 // make aGreeter 'perform' sayGoodBye()
 mr2.on(aGreeter).doAction();
A unique subclass of methodRef is generated as the applet/application runs. The user of the methodRef object however, *always* deals with it as a methodRef. The dynamically created subclass has the name CLASS__METHOD__PARAMCLASS where CLASS is the fully qualified name of the method's class, METHOD is the method's name, and PARAMCLASS is the fully qualified method's parameters' class name. This subclass is made part of a methodRefClasses package.
Restrictions:
	- IMPORTANT: Because the generated methodRef lives in its own package,
	only PUBLIC methods and PUBLIC interfaces of PUBLIC classes can be
	pointed to. Likewise, the target method's parameter class must be
	PUBLIC as well. 
	- Once a method reference is generated, it is bound to the
	referred method and cannot be changed.
	- Applets may not use this package. This is because of a current security
	restriction on class loaders.
Known bugs: - Specifying an invalid method name to methodRef.newRef(), does not always cause a NoSuchMethodError exception to be generated in doAction(). Since it sometimes occurs, I assume it's a bug in the VM. This is presently being looked at...

Variable Index

 o O
The target of the callback method
 o useCompiler
flag to determine if javac compiler should be used to generate functor class.

Constructor Index

 o methodRef()
Constructor

Method Index

 o doAction(Object)
Performs the action on the on the target object..This is an abstract method that is overridden in the dynamically generated method reference (functor) Invocation of doAction() will cause your desired method to be called and passed o as a parameter..
 o doAction()
overloads default doAction() (convenience function) - Passes a null reference to the referred method..
 o getTarget()
Gets the target object of the action
 o newRef(String, String, String, String)
Creates a reference to a specific method.
 o newRef(String, String, String)
Creates a reference to a specific method.Convenience method.
 o newRef(Object, String)
newRef() - Convenience method.
 o newRef(Object, String, Class)
newRef() - Convenience method.
 o on(Object)
Convenience method.
 o overrideProtect(boolean)
Allows you to 'point' to a protected method...
 o setTarget(Object)
Sets the target object of the action
 o toDisk(boolean)
Controls whether a .class file should be written to disk.

Variables

 o O
  protected Object O
The target of the callback method
 o useCompiler
  public static boolean useCompiler
flag to determine if javac compiler should be used to generate functor class. As this is exceptionally slow as well as extremely applet unsafe, this feature is left here for debugging purposes only.

Constructors

 o methodRef
  public methodRef()
Constructor

Methods

 o doAction
  public abstract void doAction(Object o)
Performs the action on the on the target object..This is an abstract method that is overridden in the dynamically generated method reference (functor) Invocation of doAction() will cause your desired method to be called and passed o as a parameter..
Parameters:
o - passed to called back method
 o setTarget
  public final void setTarget(Object target)
Sets the target object of the action
Parameters:
target - Target of referenced method
 o getTarget
  public final Object getTarget()
Gets the target object of the action
Returns:
Current target of referenced method.
 o doAction
  public void doAction()
overloads default doAction() (convenience function) - Passes a null reference to the referred method.. Use this one if parameter to method callback need not be used.
 o on
  public methodRef on(Object o)
Convenience method. Useful for dispatching a method on an target object all in one statement...
usage: mr.on( obj ).doAction() ;
Parameters:
o - target object of action. Note: The target is set to this object until changed.
Returns:
reference to self (i.e. this subclass of a methodRef)
 o newRef
  public static methodRef newRef(String packageString,
                                 String classString,
                                 String methodString,
                                 String paramClassString) throws InvalidMethodRefException
Creates a reference to a specific method. The method *must* have a specific signature, i.e must take a parameter that derives from Object and returns void. In order to 'point' a specific method, a subclass of methodRef is created at *runtime*, with Java byte codes dynamically generated to invoke the method within doAction().
Parameters:
packageString - package of target object
classString - class of target object
methodString - string representation of method to make a reference to ..
paramClassString - string representation of method's parameter's class
Returns:
reference to method
Throws: InvalidMethodRefException
If generation of methodRef fails for any reason.
 o newRef
  public static methodRef newRef(String packageString,
                                 String classString,
                                 String methodString) throws InvalidMethodRefException
Creates a reference to a specific method.Convenience method. Tthe target method's parameter's class defaults to Object...
Parameters:
packageString - package of target object
classString - class of target object
methodString - string representation of method to make a reference to ..
Returns:
reference to method
Throws: InvalidMethodRefException
If generation of methodRef fails for any reason
 o newRef
  public static methodRef newRef(Object targetObj,
                                 String method) throws InvalidMethodRefException
newRef() - Convenience method. No need to specify a package string and class string. All of that is extracted from the targetObj. Note: targetObj must have been instantiated first.The target O is then set to targetObj. The method's parameter's class defaults to Object... The target object is then set to targetObj.
Parameters:
targetObj - package and clas string are extracted from it. The target object is then set to this.
method - string representation of method to make reference to.
Returns:
reference to method
Throws: InvalidMethodRefException
If generation of methodRef fails for any reason
 o newRef
  public static methodRef newRef(Object targetObj,
                                 String method,
                                 Class paramClass) throws InvalidMethodRefException
newRef() - Convenience method. No need to specify a package string and class string. All of that is extracted from the targetObj. Note: targetObj must have been instantiated first. The target object is then set to targetObj.
Parameters:
targetObj - package and clas string are extracted from it. The target object is then set to this.
method - string representation of target method to make reference to.
paramClass - Class of target method's parameter
Returns:
reference to method
Throws: InvalidMethodRefException
If generation of methodRef fails for any reason
 o toDisk
  public static void toDisk(boolean bool)
Controls whether a .class file should be written to disk. Requires a ./methodRefClasses subdirectory to be present for the resulting class files. Default is not to write to disk.
 o overrideProtect
  public static void overrideProtect(boolean val)
Allows you to 'point' to a protected method... Not yet implemented.

All Packages  Class Hierarchy  This Package  Previous  Next  Index