本文整理匯總了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;
}
}