Java 类org.mozilla.javascript.FunctionObject 实例源码

项目:lams    文件:ScriptingSupport.java   
private static FunctionObject getFunctionObject( Class aClass, String methodName, Scriptable scriptable ) {
    Hashtable functionMap = (Hashtable) _classFunctionMaps.get( aClass );
    if (functionMap == null) {
        _classFunctionMaps.put( aClass, functionMap = new Hashtable() );
    }

    Object result = functionMap.get( methodName );
    if (result == NO_SUCH_PROPERTY) return null;
    if (result != null) return (FunctionObject) result;

    Method[] methods = aClass.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method.getName().equalsIgnoreCase( methodName )) {
            FunctionObject function = new FunctionObject( methodName, method, scriptable );
            functionMap.put( methodName, function );
            return function;
        }
    }
    functionMap.put( methodName, NO_SUCH_PROPERTY );
    return null;
}
项目:NK-VirtualGlobe    文件:X3DExecutionContext.java   
/**
 * Convenience method to locate a function name for this object and
 * create an appriate Function instance to represent it. It assumes that
 * the name you give it is the normal name and will add a "jsFunction_"
 * prefix to locate that from the method details. There is also the
 * implicit assumption that you have made a check for this name being a
 * valid function for this object before you call this method. If a
 * function object is found for this method, it will automatically be
 * registered and you can also have a copy of it returned to use.
 *
 * @param name The real method name to look for
 * @return The function object corresponding to the munged method name
 */
protected FunctionObject locateFunction(String name) {
    String real_name = JS_FUNCTION_PREFIX + name;
    Method[] methods = FunctionObject.findMethods(getClass(), real_name);

    if (methods == null) {
        errorReporter.warningReport("Unknown function: " + real_name +
                                    " on: " + getClass(), null);
        return null;
    }

    FunctionObject function = new FunctionObject(name, methods[0], this);

    functionObjects.put(name, function);

    return function;
}
项目:Reer    文件:RhinoWorkerUtils.java   
public static Object toJavaValue(Object object) {
    if (object == null || object.equals(Context.getUndefinedValue())) {
        return null;
    } else if (object.getClass().getPackage().getName().startsWith("java.")) {
        return object;
    } else if (object instanceof FunctionObject) {
        throw new IllegalArgumentException(String.format("Cannot convert function object to value (object: %s)", object));
    } else if (object instanceof Scriptable) {
        return toMap((Scriptable) object);
    } else {
        throw new IllegalArgumentException(String.format("Can't convert JS object %s (type: %s) to native Java object", object, object.getClass().getName()));
    }
}
项目:Pushjet-Android    文件:RhinoWorkerUtils.java   
public static Object toJavaValue(Object object) {
    if (object == null || object.equals(Context.getUndefinedValue())) {
        return null;
    } else if (object.getClass().getPackage().getName().startsWith("java.")) {
        return object;
    } else if (object instanceof FunctionObject) {
        throw new IllegalArgumentException(String.format("Cannot convert function object to value (object: %s)", object));
    } else if (object instanceof Scriptable) {
        return toMap((Scriptable) object);
    } else {
        throw new IllegalArgumentException(String.format("Can't convert JS object %s (type: %s) to native Java object", object, object.getClass().getName()));
    }
}
项目:Pushjet-Android    文件:RhinoWorkerUtils.java   
public static Object toJavaValue(Object object) {
    if (object == null || object.equals(Context.getUndefinedValue())) {
        return null;
    } else if (object.getClass().getPackage().getName().startsWith("java.")) {
        return object;
    } else if (object instanceof FunctionObject) {
        throw new IllegalArgumentException(String.format("Cannot convert function object to value (object: %s)", object));
    } else if (object instanceof Scriptable) {
        return toMap((Scriptable) object);
    } else {
        throw new IllegalArgumentException(String.format("Can't convert JS object %s (type: %s) to native Java object", object, object.getClass().getName()));
    }
}
项目:frinika    文件:JavascriptScope.java   
/**
 * Exports a Java method as a Javascript (top-level-)function. Only works
 * with methods in this class (because scope is used as value for 'this'
 * when invoking methods).
 * 
 * @param methodName
 * @param parameterSignature
 */
private void exportMethod(String methodName, Class[] parameterSignature) {
    try {
        Method m = JavascriptScope.class.getMethod(methodName,
                parameterSignature);
        while (methodName.charAt(0) == '_') {
            methodName = methodName.substring(1);
        } // remove leading _ for JS name
        FunctionObject functionJS = new FunctionObject(methodName, m, this);
        ScriptableObject.putProperty(this, methodName, functionJS);
    } catch (NoSuchMethodException nse) {
        nse.printStackTrace();
    }
}
项目:native.js    文件:View.java   
public static void finishInit(Scriptable scope, FunctionObject constructor,
        Scriptable prototype) {
    int flags = DONTENUM | READONLY | PERMANENT;
    /* for horizontalSize, verticalSize */
    constructor.defineProperty("wrap_view", WRAP_VIEW, flags);
    constructor.defineProperty("fill_container", FILL_CONTAINER, flags);

    /* for verticalAlignment, horizontalAlignment */
    constructor.defineProperty("left", LEFT, flags);
    constructor.defineProperty("center", CENTER, flags);
    constructor.defineProperty("right", RIGHT, flags);
    constructor.defineProperty("top", TOP, flags);
    constructor.defineProperty("bottom", BOTTOM, flags);
}
项目:pacman-dsl    文件:FunctionExtension.java   
public List<FunctionObject> getFunctions(Scriptable scope) {
    List<String> names = this.getMethodNames();
    List<FunctionObject> functions = new ArrayList<FunctionObject>();

    Method[] methods = this.getClass().getMethods();
    for (Method method : methods)
        if (names.contains(method.getName()))
            functions.add(new FunctionObject(method.getName(), method, scope));

    return functions;
}
项目:phonk    文件:StyleProperties.java   
public static void finishInit(Scriptable scope, FunctionObject constructor, Scriptable prototype) {
    System.out.println("finishInit is called.");
    globalPrototype = prototype;
}
项目:phonk    文件:ProtoProperties.java   
public static void finishInit(Scriptable scope, FunctionObject constructor, Scriptable prototype) {
    System.out.println("finishInit is called.");
    globalPrototype = prototype;
}
项目:pacman-dsl    文件:Converter.java   
private void addFunctionExtension(Scriptable scope, FunctionExtension extension) {
    List<FunctionObject> functions = extension.getFunctions(scope);
    if (functions != null)
        for (FunctionObject func : functions)
            ScriptableObject.putProperty(scope, func.getFunctionName(), func);
}
项目:NK-VirtualGlobe    文件:ExternProtoDeclaration.java   
/**
 * Convenience method to locate a function name for this object and
 * create an appriate Function instance to represent it. It assumes that
 * the name you give it is the normal name and will add a "jsFunction_"
 * prefix to locate that from the method details. There is also the
 * implicit assumption that you have made a check for this name being a
 * valid function for this object before you call this method. If a
 * function object is found for this method, it will automatically be
 * registered and you can also have a copy of it returned to use.
 *
 * @param name The real method name to look for
 * @return The function object corresponding to the munged method name
 */
private FunctionObject locateFunction(String name) {
    String real_name = JS_FUNCTION_PREFIX + name;
    Method[] methods = FunctionObject.findMethods(getClass(), real_name);

    FunctionObject function = new FunctionObject(name, methods[0], this);

    functionObjects.put(name, function);

    return function;
}
项目:NK-VirtualGlobe    文件:ProtoDeclaration.java   
/**
 * Convenience method to locate a function name for this object and
 * create an appriate Function instance to represent it. It assumes that
 * the name you give it is the normal name and will add a "jsFunction_"
 * prefix to locate that from the method details. There is also the
 * implicit assumption that you have made a check for this name being a
 * valid function for this object before you call this method. If a
 * function object is found for this method, it will automatically be
 * registered and you can also have a copy of it returned to use.
 *
 * @param name The real method name to look for
 * @return The function object corresponding to the munged method name
 */
private FunctionObject locateFunction(String name) {
    String real_name = JS_FUNCTION_PREFIX + name;
    Method[] methods = FunctionObject.findMethods(getClass(), real_name);

    FunctionObject function = new FunctionObject(name, methods[0], this);

    functionObjects.put(name, function);

    return function;
}
项目:NK-VirtualGlobe    文件:FieldScriptableObject.java   
/**
 * Convenience method to locate a function name for this object and
 * create an appriate Function instance to represent it. It assumes that
 * the name you give it is the normal name and will add a "jsFunction_"
 * prefix to locate that from the method details. There is also the
 * implicit assumption that you have made a check for this name being a
 * valid function for this object before you call this method. If a
 * function object is found for this method, it will automatically be
 * registered and you can also have a copy of it returned to use.
 *
 * @param name The real method name to look for
 * @return The function object corresponding to the munged method name
 */
protected FunctionObject locateFunction(String name) {
    String real_name = JS_FUNCTION_PREFIX + name;
    Method[] methods = FunctionObject.findMethods(getClass(), real_name);

    FunctionObject function = new FunctionObject(name, methods[0], this);

    registerFunction(name, function);

    return function;
}
项目:NK-VirtualGlobe    文件:Browser.java   
/**
 * Convenience method to locate a function name for this object and
 * create an appriate Function instance to represent it. It assumes that
 * the name you give it is the normal name and will add a "jsFunction_"
 * prefix to locate that from the method details. There is also the
 * implicit assumption that you have made a check for this name being a
 * valid function for this object before you call this method. If a
 * function object is found for this method, it will automatically be
 * registered and you can also have a copy of it returned to use.
 *
 * @param name The real method name to look for
 * @return The function object corresponding to the munged method name
 */
protected FunctionObject locateFunction(String name) {
    String real_name = JS_FUNCTION_PREFIX + name;

    Method[] methods = FunctionObject.findMethods(getClass(), real_name);

    FunctionObject function = new FunctionObject(name, methods[0], this);

    functionObjects.put(name, function);

    return function;
}