當前位置: 首頁>>代碼示例>>Java>>正文


Java ScriptObjectMirror.isFunction方法代碼示例

本文整理匯總了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;
}
 
開發者ID:marrow16,項目名稱:Nasapi,代碼行數:27,代碼來源:ScriptObjectMirrors.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:NbPacScriptEvaluator.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:WithObject.java

示例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());
	}
}
 
開發者ID:marrow16,項目名稱:Nasapi,代碼行數:38,代碼來源:ScriptObjectMirrors.java

示例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;
    }
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:39,代碼來源:ScriptValue.java


注:本文中的jdk.nashorn.api.scripting.ScriptObjectMirror.isFunction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。