本文整理汇总了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);
}
}