oscript.classwrap
Class ClassWrapGen

java.lang.Object
  extended byoscript.classwrap.ClassWrapGen

public class ClassWrapGen
extends java.lang.Object

The classwrap package is used to generate a "wrapper" for a java class. A wrapper is just a subclass of a given java class, where for each public non-final, non-static method, a wrapper method and an "orig" method are generated. The wrapper method looks up a property with the same name in the script object, and if it exists, and is a function that takes a compatible number of arguments, calls it, otherwise it calls the same method in the parent (original) java class. The orig method simply calls the same method in the parent class.

The "wrapper" class is used any place where a script objects extends a java class (ie. java class, java interface, or builtin-type). The purpose is to allow the script object to override methods in a java class, or implement methods in a java interface.

The "wrapper" class is generated using the Byte Code Engineering Library (BCEL.jar).

Version:
1.34
Author:
Rob Clark (rob@ti.com)

Method Summary
static boolean canMakeWrapperClass(java.lang.Class origClass)
          Check if we can make a wrapper class for the specified class...
static java.lang.Class getNonWrapperClass(java.lang.Class javaClass)
          Given a java class that may or may not be a wrapper class, return a java class that is the closest super-class that is not a wrapper class.
static java.lang.String getOrigMethodName(java.lang.Object javaObj, java.lang.String methodName)
          Because the wrapper method looks to the script object first, before calling the wrapped method, there are times when we want to call the original method directly.
static java.lang.String getOrigMethodName(java.lang.String methodName)
           
static Value getScriptObject(java.lang.Object javaObj)
          Given a java object, which may be linked to a script object, return the linked script object.
static boolean isWrapperInstance(java.lang.Object javaObj)
          Is the specified object an instance of a wrapper class?
static void linkObjects(java.lang.Object javaObj, Scope scriptObj)
          Link the specified java object and script object.
static java.lang.Class makeWrapperClass(java.lang.Class origClass)
          Make the wrapper class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

canMakeWrapperClass

public static boolean canMakeWrapperClass(java.lang.Class origClass)
Check if we can make a wrapper class for the specified class... this is needed by JavaClassWrapper, which needs to know if it can construct a wrapper class... but it wants to defer the act of actually making the wrapper class.

Parameters:
origClass - the original class
Returns:
true if we can make a wrapper (ie. class isn't final, etc)

makeWrapperClass

public static java.lang.Class makeWrapperClass(java.lang.Class origClass)
Make the wrapper class. Wrap all public non-final instance methods.

Parameters:
origClass - the original class
Returns:
the auto-generated wrapper class, or if a wrapper class cannot be generated, the origClass. This should never return null.

getOrigMethodName

public static java.lang.String getOrigMethodName(java.lang.Object javaObj,
                                                 java.lang.String methodName)
Because the wrapper method looks to the script object first, before calling the wrapped method, there are times when we want to call the original method directly. To do this, you call the "orig" method. To hide the naming convention, other code should use this method to get the name of the "orig" method for the named method.

Parameters:
javaObj - the java object
methodName - the name of the method in the parent class
Returns:
the mangled name of the method that calls the requested method in the parent class, ie. the "orig" method.

getOrigMethodName

public static java.lang.String getOrigMethodName(java.lang.String methodName)

isWrapperInstance

public static boolean isWrapperInstance(java.lang.Object javaObj)
Is the specified object an instance of a wrapper class?

Parameters:
javaObj - the java object to test
Returns:
true if instance of auto-generated wrapper class

linkObjects

public static void linkObjects(java.lang.Object javaObj,
                               Scope scriptObj)
Link the specified java object and script object. The java object should be an instance of a wrapper class generated by the makeWrapperClass method.

Parameters:
javaObj - the java object
scriptObj - the script object

getScriptObject

public static Value getScriptObject(java.lang.Object javaObj)
Given a java object, which may be linked to a script object, return the linked script object.

Parameters:
javaObj - the java object
Returns:
the script object, or null

getNonWrapperClass

public static final java.lang.Class getNonWrapperClass(java.lang.Class javaClass)
Given a java class that may or may not be a wrapper class, return a java class that is the closest super-class that is not a wrapper class.

Parameters:
javaClass - a java class that might be a wrapper class
Returns:
a java class that is not a wrapper class