本文整理汇总了Java中jdk.nashorn.api.scripting.ScriptObjectMirror.isFunction方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptObjectMirror.isFunction方法的具体用法?Java ScriptObjectMirror.isFunction怎么用?Java ScriptObjectMirror.isFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.api.scripting.ScriptObjectMirror
的用法示例。
在下文中一共展示了ScriptObjectMirror.isFunction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import jdk.nashorn.api.scripting.ScriptObjectMirror; //导入方法依赖的package包/类
public static Object convert(Object original) {
if (original == null) {
return null;
} else if (original instanceof String || original instanceof Integer || original instanceof Long || original instanceof Boolean || original instanceof Double) {
return original;
} else if (original instanceof ScriptObjectMirror) {
ScriptObjectMirror jsOriginal = (ScriptObjectMirror)original;
if (jsOriginal.isArray()) {
List<Object> listResult = new ArrayList<Object>();
Integer length = (Integer)jsOriginal.get("length");
for (int i = 0; i < length; i++) {
listResult.add(convert(jsOriginal.get("" + i)));
}
return listResult;
} else if (jsOriginal.isFunction()) {
// can't convert it...
return null;
}
Map<String,Object> mapResult = new LinkedHashMap<String,Object>();
for (Map.Entry<String,Object> entry: jsOriginal.entrySet()) {
mapResult.put(entry.getKey(), convert(entry.getValue()));
}
return mapResult;
}
return original;
}
示例2: isJsFunctionAvailable
import jdk.nashorn.api.scripting.ScriptObjectMirror; //导入方法依赖的package包/类
private boolean isJsFunctionAvailable(ScriptEngine eng, String functionName, boolean doDeepTest) {
// We want to test if the function is there, but without actually
// invoking it.
Object obj = eng.get(functionName);
if (!doDeepTest && obj != null) {
// Shallow test. We've established that there's
// "something" in the ENGINE_SCOPE with a name like
// functionName, and we *hope* it is a function, but we really don't
// know, therefore we call it a shallow test.
return true;
}
// For Nashorn post JDK8u40 we can do even deeper validation
// using the ScriptObjectMirror class. This will not work for Rhino.
if (doDeepTest && obj != null) {
if (obj instanceof ScriptObjectMirror) {
ScriptObjectMirror som = (ScriptObjectMirror) obj;
if (som.isFunction()) {
return true;
}
}
}
return false;
}
示例3: bindToExpression
import jdk.nashorn.api.scripting.ScriptObjectMirror; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private static Object bindToExpression(final Object fn, final Object receiver) {
if (fn instanceof ScriptFunction) {
return bindToExpression((ScriptFunction) fn, receiver);
} else if (fn instanceof ScriptObjectMirror) {
final ScriptObjectMirror mirror = (ScriptObjectMirror)fn;
if (mirror.isFunction()) {
// We need to make sure correct 'this' is used for calls with Ident call
// expressions. We do so here using an AbstractJSObject instance.
return new AbstractJSObject() {
@Override
public Object call(final Object thiz, final Object... args) {
return mirror.call(withFilterExpression(receiver), args);
}
};
}
}
return fn;
}
示例4: StringifyObject
import jdk.nashorn.api.scripting.ScriptObjectMirror; //导入方法依赖的package包/类
private static void StringifyObject(Object object, StringBuilder builder, boolean inObjectOrArray) {
if (object == null) {
builder.append("null");
} else if (object instanceof String && inObjectOrArray) {
builder.append("\"").append(((String) object).replaceAll("\"", "\\\"")).append("\"");
} else if (object instanceof String) {
builder.append(object);
} else if (object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Double) {
builder.append(object.toString());
} else if (object instanceof ScriptObjectMirror) {
ScriptObjectMirror scriptObject = (ScriptObjectMirror)object;
if (scriptObject.isArray()) {
builder.append("[");
Integer length = (Integer) scriptObject.get("length");
for (int i = 0; i < length; i++) {
StringifyObject(scriptObject.get("" + i), builder, true);
}
builder.append("]");
} else if (scriptObject.isFunction()) {
builder.append("[function()]");
} else {
builder.append("{");
boolean isFirst = true;
for (Map.Entry<String, Object> entry : scriptObject.entrySet()) {
builder.append(isFirst ? "" : ", ")
.append("\"")
.append(entry.getKey())
.append("\": ");
StringifyObject(entry.getValue(), builder, true);
isFirst = false;
}
builder.append("}");
}
} else {
builder.append(object.toString());
}
}
示例5: ScriptValue
import jdk.nashorn.api.scripting.ScriptObjectMirror; //导入方法依赖的package包/类
public ScriptValue(Object value, String source) {
this.value = value;
this.source = source;
if (value == null) {
type = Type.NULL;
} else if (value instanceof DocumentContext) {
type = Type.JSON;
} else if (value instanceof Node) {
type = Type.XML;
} else if (value instanceof List) {
type = Type.LIST;
} else if (value instanceof Map) {
if (value instanceof ScriptObjectMirror) {
ScriptObjectMirror som = (ScriptObjectMirror) value;
if (som.isArray()) {
type = Type.JS_ARRAY;
} else if (som.isFunction()) {
type = Type.JS_FUNCTION;
} else {
type = Type.JS_OBJECT;
}
} else {
type = Type.MAP;
}
} else if (value instanceof String) {
type = Type.STRING;
} else if (value instanceof byte[]) {
type = Type.BYTE_ARRAY;
} else if (value instanceof InputStream) {
type = Type.INPUT_STREAM;
} else if (Script.isPrimitive(value.getClass())) {
type = Type.PRIMITIVE;
} else if (value instanceof FeatureWrapper) {
type = Type.FEATURE_WRAPPER;
} else {
type = Type.UNKNOWN;
}
}