@Test public void testUnwrapMapError() throws ScriptException, NoSuchMethodException { engine.eval("function test() { return []; };"); ScriptObjectMirror object = (ScriptObjectMirror) ((Invocable) engine).invokeFunction("test"); try { ScriptObjectMirrors.unwrapMap(object); fail("unwrapMap should throw an exception."); } catch (IllegalArgumentException e) { assertEquals("JavaScript input is not an Object!", e.getMessage()); } }
public static Map<String, Object> unwrapMap(ScriptObjectMirror jso) { if (!JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not an Object!"); } Map<String, Object> result = new HashMap<>(); for (String k : jso.keySet()) { Object o = jso.get(k); if (o instanceof ScriptObjectMirror) { result.put(k, unwrap((ScriptObjectMirror) o)); } else { result.put(k, DocumentScriptingWrapper.unwrap(o)); } } return result; }
ScriptObjectMirrors { public static Map<String, Object> unwrapMap(ScriptObjectMirror jso) { if (!JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not an Object!"); } Map<String, Object> result = new HashMap<>(); for (String k : jso.keySet()) { Object o = jso.get(k); if (o instanceof ScriptObjectMirror) { result.put(k, unwrap((ScriptObjectMirror) o)); } else { result.put(k, DocumentScriptingWrapper.unwrap(o)); } } return result; } }
ScriptObjectMirrors { public static Map<String, Object> unwrapMap(ScriptObjectMirror jso) { if (!JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not an Object!"); } Map<String, Object> result = new HashMap<>(); for (String k : jso.keySet()) { Object o = jso.get(k); if (o instanceof ScriptObjectMirror) { result.put(k, unwrap((ScriptObjectMirror) o)); } else { result.put(k, DocumentScriptingWrapper.unwrap(o)); } } return result; } private  ScriptObjectMirrors(); }
ScriptObjectMirrors { public static Map<String, Object> unwrapMap(ScriptObjectMirror jso) { if (!JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not an Object!"); } Map<String, Object> result = new HashMap<>(); for (String k : jso.keySet()) { Object o = jso.get(k); if (o instanceof ScriptObjectMirror) { result.put(k, unwrap((ScriptObjectMirror) o)); } else { result.put(k, DocumentScriptingWrapper.unwrap(o)); } } return result; } private  ScriptObjectMirrors(); static Object unwrap(ScriptObjectMirror jso); static List<Object> unwrapList(ScriptObjectMirror jso); static Map<String, Object> unwrapMap(ScriptObjectMirror jso); static Calendar unwrapDate(ScriptObjectMirror jso); static Object wrap(Map<String, Object> map); }
ScriptObjectMirrors { public static Map<String, Object> unwrapMap(ScriptObjectMirror jso) { if (!JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not an Object!"); } Map<String, Object> result = new HashMap<>(); for (String k : jso.keySet()) { Object o = jso.get(k); if (o instanceof ScriptObjectMirror) { result.put(k, unwrap((ScriptObjectMirror) o)); } else { result.put(k, DocumentScriptingWrapper.unwrap(o)); } } return result; } private  ScriptObjectMirrors(); static Object unwrap(ScriptObjectMirror jso); static List<Object> unwrapList(ScriptObjectMirror jso); static Map<String, Object> unwrapMap(ScriptObjectMirror jso); static Calendar unwrapDate(ScriptObjectMirror jso); static Object wrap(Map<String, Object> map);  }