org.mozilla.javascript
Class NativeJavaMethod

java.lang.Object
  |
  +--org.mozilla.javascript.ScriptableObject
        |
        +--org.mozilla.javascript.IdScriptable
              |
              +--org.mozilla.javascript.BaseFunction
                    |
                    +--org.mozilla.javascript.NativeFunction
                          |
                          +--org.mozilla.javascript.NativeJavaMethod
All Implemented Interfaces:
Function, IdFunctionMaster, Scriptable, java.io.Serializable

public class NativeJavaMethod
extends NativeFunction
implements Function

This class reflects Java methods into the JavaScript environment. It handles overloading of methods, and method/field name conflicts. All NativeJavaMethods behave as JSRef `bound' methods, in that they always operate on the object underlying the original NativeJavaObject parent regardless of any reparenting that may occur.

Author:
Mike Shaver
See Also:
NativeJavaArray, NativeJavaPackage, NativeJavaClass, Serialized Form

Fields inherited from class org.mozilla.javascript.NativeFunction
debug_level, debug_srcName, nestedFunctions
 
Fields inherited from class org.mozilla.javascript.ScriptableObject
DONTENUM, EMPTY, PERMANENT, READONLY
 
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
NativeJavaMethod()
           
NativeJavaMethod(java.lang.reflect.Method[] methods)
           
NativeJavaMethod(java.lang.reflect.Method method, java.lang.String name)
           
 
Method Summary
 void add(java.lang.reflect.Method method)
           
 java.lang.Object call(Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args)
          Call the function.
 java.lang.String decompile(Context cx, int indent, boolean justbody)
          Decompile the source information associated with this js function/script back into a string.
static int preferConversion(java.lang.Object fromObj, java.lang.Class toClass1, java.lang.Class toClass2)
          Determine which of two types is the easier conversion.
static int preferSignature(java.lang.Object[] args, java.lang.Class[] sig1, java.lang.Class[] sig2)
          Determine which of two signatures is the closer fit.
 java.lang.String toString()
           
 
Methods inherited from class org.mozilla.javascript.NativeFunction
getArity, getLength, jsGet_name
 
Methods inherited from class org.mozilla.javascript.BaseFunction
construct, execMethod, getClassName, getFunctionName, hasInstance, methodArity, setImmunePrototypeProperty
 
Methods inherited from class org.mozilla.javascript.IdScriptable
addAsPrototype, defineProperty, delete, get, getAttributes, has, put, setAttributes
 
Methods inherited from class org.mozilla.javascript.ScriptableObject
callMethod, defineClass, defineClass, defineFunctionProperties, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, get, getAllIds, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, has, hasProperty, hasProperty, isSealed, put, putProperty, putProperty, sealObject, setAttributes, setParentScope, setPrototype
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mozilla.javascript.Function
construct
 
Methods inherited from interface org.mozilla.javascript.Scriptable
delete, delete, get, get, getClassName, getDefaultValue, getIds, getParentScope, getPrototype, has, has, hasInstance, put, put, setParentScope, setPrototype
 

Constructor Detail

NativeJavaMethod

public NativeJavaMethod()

NativeJavaMethod

public NativeJavaMethod(java.lang.reflect.Method[] methods)

NativeJavaMethod

public NativeJavaMethod(java.lang.reflect.Method method,
                        java.lang.String name)
Method Detail

add

public void add(java.lang.reflect.Method method)

decompile

public java.lang.String decompile(Context cx,
                                  int indent,
                                  boolean justbody)
Description copied from class: NativeFunction
Decompile the source information associated with this js function/script back into a string. For the most part, this just means translating tokens back to their string representations; there's a little bit of lookahead logic to decide the proper spacing/indentation. Most of the work in mapping the original source to the prettyprinted decompiled version is done by the parser. Note that support for Context.decompileFunctionBody is hacked on through special cases; I suspect that js makes a distinction between function header and function body that rhino decompilation does not.
Overrides:
decompile in class NativeFunction
Following copied from class: org.mozilla.javascript.NativeFunction
Parameters:
cx - Current context
indent - How much to indent the decompiled result
justbody - Whether the decompilation should omit the function header and trailing brace.

toString

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

call

public java.lang.Object call(Context cx,
                             Scriptable scope,
                             Scriptable thisObj,
                             java.lang.Object[] args)
                      throws JavaScriptException
Description copied from interface: Function
Call the function. Note that the array of arguments is not guaranteed to have length greater than 0.
Specified by:
call in interface Function
Overrides:
call in class BaseFunction
Following copied from interface: org.mozilla.javascript.Function
Parameters:
cx - the current Context for this thread
scope - the scope to execute the function relative to. This is set to the value returned by getParentScope() except when the function is called from a closure.
thisObj - the JavaScript this object
args - the array of arguments
Returns:
the result of the call
Throws:
JavaScriptException - if an uncaught exception occurred while executing the function

preferSignature

public static int preferSignature(java.lang.Object[] args,
                                  java.lang.Class[] sig1,
                                  java.lang.Class[] sig2)
Determine which of two signatures is the closer fit. Returns one of PREFERENCE_EQUAL, PREFERENCE_FIRST_ARG, PREFERENCE_SECOND_ARG, or PREFERENCE_AMBIGUOUS.

preferConversion

public static int preferConversion(java.lang.Object fromObj,
                                   java.lang.Class toClass1,
                                   java.lang.Class toClass2)
Determine which of two types is the easier conversion. Returns one of PREFERENCE_EQUAL, PREFERENCE_FIRST_ARG, PREFERENCE_SECOND_ARG, or PREFERENCE_AMBIGUOUS.