本文整理匯總了Java中jdk.nashorn.api.scripting.ScriptObjectMirror.getOwnKeys方法的典型用法代碼示例。如果您正苦於以下問題:Java ScriptObjectMirror.getOwnKeys方法的具體用法?Java ScriptObjectMirror.getOwnKeys怎麽用?Java ScriptObjectMirror.getOwnKeys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jdk.nashorn.api.scripting.ScriptObjectMirror
的用法示例。
在下文中一共展示了ScriptObjectMirror.getOwnKeys方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: jsToNode
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
private org.antology.db.Node jsToNode(Object object) throws Exception {
if (object instanceof ScriptObjectMirror) {
ScriptObjectMirror mirror = (ScriptObjectMirror) object;
if (mirror.isArray()) {
List<org.antology.db.Node> list = new LinkedList<>();
for (int i = 0; i < mirror.size(); i++) {
list.add(jsToNode(mirror.get(Integer.toString(i))));
}
return new Node(Schema.Type.LIST, list);
} else {
Map<String, org.antology.db.Node> struct = new HashMap<>();
for (String key : mirror.getOwnKeys(false)) {
java.lang.Object value = mirror.get(key);
struct.put(key, jsToNode(value));
}
return new Node(Schema.Type.STRUCT, struct);
}
} else if (object instanceof String) {
return new Node(Schema.Type.STRING, object);
} else if (object instanceof Integer) {
return new Node(Schema.Type.INTEGER, object);
} else if (object instanceof Double) {
return new Node(Schema.Type.FLOAT, object);
} else if (object instanceof Boolean) {
return new Node(Schema.Type.BOOLEAN, object);
} else {
throw new Exception("Unknown type " + object.getClass().getName());
}
}
示例2: keys
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
/**
* ECMA 15.2.3.14 Object.keys ( O )
*
* @param self self reference
* @param obj object from which to extract keys
* @return array of keys in object
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static ScriptObject keys(final Object self, final Object obj) {
if (obj instanceof ScriptObject) {
final ScriptObject sobj = (ScriptObject)obj;
return new NativeArray(sobj.getOwnKeys(false));
} else if (obj instanceof ScriptObjectMirror) {
final ScriptObjectMirror sobjMirror = (ScriptObjectMirror)obj;
return new NativeArray(sobjMirror.getOwnKeys(false));
} else {
throw notAnObject(obj);
}
}