本文整理汇总了Java中org.mozilla.javascript.FunctionObject类的典型用法代码示例。如果您正苦于以下问题:Java FunctionObject类的具体用法?Java FunctionObject怎么用?Java FunctionObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FunctionObject类属于org.mozilla.javascript包,在下文中一共展示了FunctionObject类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFunctionObject
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
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;
}
示例2: locateFunction
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
/**
* 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;
}
示例3: toJavaValue
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
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()));
}
}
示例4: exportMethod
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
/**
* 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();
}
}
示例5: finishInit
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
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);
}
示例6: getFunctions
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
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;
}
示例7: finishInit
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
public static void finishInit(Scriptable scope, FunctionObject constructor, Scriptable prototype) {
System.out.println("finishInit is called.");
globalPrototype = prototype;
}
示例8: addFunctionExtension
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
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);
}
示例9: locateFunction
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
/**
* 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;
}
示例10: locateFunction
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
/**
* 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;
}
示例11: locateFunction
import org.mozilla.javascript.FunctionObject; //导入依赖的package包/类
/**
* 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;
}