oscript.data
Class JavaBridge

java.lang.Object
  extended byoscript.data.JavaBridge

public class JavaBridge
extends java.lang.Object

Utilities to convert between script and java types.

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

Nested Class Summary
static class JavaBridge.FunctionTransformer
          This abstract class is implemented by transformers that understand how to transform a script object (function) to a certain type of java class.
static interface JavaBridge.JavaCallableAccessor
          Abstracts Method and Constructor differences
 
Constructor Summary
JavaBridge()
           
 
Method Summary
static java.lang.Object call(JavaBridge.JavaCallableAccessor accessor, int id, java.lang.Object javaObject, java.lang.Object[] javaCallables, StackFrame sf, MemberTable args)
          Since choosing the correct method to call, and correct constructor to call, uses the same algorithm, instead of duplicating the logic in two places, it is handled by this method.
static int convertArgs(java.lang.Class[] parameterTypes, java.lang.Object[] javaArgs, MemberTable args)
          Utility to convert args to javaArgs of the types specified by parameterTypes.
static java.lang.Object convertToJavaObject(Value scriptObj, java.lang.Class cls)
           
static java.lang.Object convertToJavaObject(Value scriptObj, java.lang.String javaTypeStr)
          This is used by java class wrappers to convert the return type back to a java type:
static Value convertToScriptObject(boolean javaObject)
           
static Value convertToScriptObject(double doubleVal)
           
static Value convertToScriptObject(long longVal)
           
static Value convertToScriptObject(java.lang.Object javaObject)
          Convert a java object to a script object.
static Value convertToScriptObject(java.lang.String javaObject)
           
static void registerFunctionTransformer(JavaBridge.FunctionTransformer ft)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaBridge

public JavaBridge()
Method Detail

registerFunctionTransformer

public static void registerFunctionTransformer(JavaBridge.FunctionTransformer ft)

convertToJavaObject

public static java.lang.Object convertToJavaObject(Value scriptObj,
                                                   java.lang.String javaTypeStr)
This is used by java class wrappers to convert the return type back to a java type:


convertToJavaObject

public static java.lang.Object convertToJavaObject(Value scriptObj,
                                                   java.lang.Class cls)

call

public static final java.lang.Object call(JavaBridge.JavaCallableAccessor accessor,
                                          int id,
                                          java.lang.Object javaObject,
                                          java.lang.Object[] javaCallables,
                                          StackFrame sf,
                                          MemberTable args)
Since choosing the correct method to call, and correct constructor to call, uses the same algorithm, instead of duplicating the logic in two places, it is handled by this method. Having it in one place also makes it easier to explore optimizations in the future.

Parameters:
accessor -
id - the symbol (name) of the method/constructor
javaObject - the java object, to pass to JavaBridge.JavaCallableAccessor.call(java.lang.Object, java.lang.Object, java.lang.Object[])
javaCallables - the candidate methods/constructors
sf - the current stack frame
args - the args
Returns:
the return value of JavaBridge.JavaCallableAccessor.call(java.lang.Object, java.lang.Object, java.lang.Object[])

convertArgs

public static int convertArgs(java.lang.Class[] parameterTypes,
                              java.lang.Object[] javaArgs,
                              MemberTable args)
Utility to convert args to javaArgs of the types specified by parameterTypes. Each array should be of the same length. This will return a score of the conversion. A score of less than or equal to zero indicates that the conversion is not possible. A higher score is better.


convertToScriptObject

public static final Value convertToScriptObject(java.lang.Object javaObject)
Convert a java object to a script object. Some java types can be converted back to native script types, rather than need a wrapper, so this handles that conversion.

Parameters:
javaObject - the java object to make a wrapper for

convertToScriptObject

public static final Value convertToScriptObject(long longVal)

convertToScriptObject

public static final Value convertToScriptObject(double doubleVal)

convertToScriptObject

public static final Value convertToScriptObject(boolean javaObject)

convertToScriptObject

public static final Value convertToScriptObject(java.lang.String javaObject)