@Override public String apply(String s) { Object call = jso.call(jso, s); return call == null ? null : call.toString(); } };
@Override public String stringify(Object object) { if (object instanceof JSObject) { final JSObject jso = (JSObject) object; if (jso.isFunction()) { Object call = jso.call(jso); return stringify(coerce(call)); } } return super.stringify(object); }
@Override public Object call( final Object thiz, final Object... args ) { final JSObject func = (JSObject) args[0]; final Object[] array = (Object[]) args[1]; final Object[] jsArray = JsObjectConverter.toJsArray( array ); return func.call( thiz, jsArray ); } }
public Object toJava(Object aValue) { if (aValue instanceof ScriptObject) { aValue = ScriptUtils.wrap((ScriptObject) aValue); } if (aValue instanceof JSObject) { assert toPrimitiveFunc != null : SCRIPT_NOT_INITIALIZED; aValue = toPrimitiveFunc.call(null, new Object[]{aValue}); } else if (aValue == ScriptRuntime.UNDEFINED) { return null; } return aValue; }
public Object toJs(Object aValue) { if (aValue instanceof Date) {// force js boxing of date, because of absence js literal of date value assert toDateFunc != null : SCRIPT_NOT_INITIALIZED; return toDateFunc.call(null, aValue); } else if (aValue instanceof Number) { return ((Number) aValue).doubleValue(); } else if (aValue instanceof HasPublished) { return ((HasPublished) aValue).getPublished(); } else { return aValue; } }
public String toJson(Object aObj) { assert writeJsonFunc != null : SCRIPT_NOT_INITIALIZED; if (aObj instanceof Undefined) {//nashorn JSON parser could not work with undefined. aObj = null; } if (aObj instanceof JSObject || aObj instanceof CharSequence || aObj instanceof Number || aObj instanceof Boolean || aObj instanceof ScriptObject || aObj == null) { return JSType.toString(writeJsonFunc.call(null, new Object[]{aObj})); } else { throw new IllegalArgumentException("Java object couldn't be converted to JSON!"); } }
@Override public void completed(Integer result, Object attachment) { callingSpace.process(callingContext, () -> { if (aOnSuccess != null) { aOnSuccess.call(null, new Object[]{result}); } }); }
public static Object load(final String aResourceName, String aCalledFromFile, JSObject aOnSuccess, JSObject aOnFailure) throws Exception { Scripts.Space space = Scripts.getSpace(); return _load(aResourceName, aCalledFromFile, space, aOnSuccess != null ? (Object aLoaded) -> { aOnSuccess.call(null, new Object[]{space.toJs(aLoaded)}); } : null, aOnFailure != null ? (Exception ex) -> { aOnFailure.call(null, new Object[]{space.toJs(ex.getMessage())}); } : null); }
public JSObject readJsArray(Collection<Map<String, Object>> aCollection) { JSObject result = makeArray(); JSObject jsPush = (JSObject) result.getMember("push"); aCollection.forEach((Map<String, Object> aItem) -> { JSObject jsItem = makeObj(); aItem.entrySet().forEach((Map.Entry<String, Object> aItemContent) -> { jsItem.setMember(aItemContent.getKey(), toJs(aItemContent.getValue())); }); jsPush.call(result, new Object[]{jsItem}); }); return result; }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; } }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; }
@Override public JSObject getPublished() { if (published == null) { JSObject publisher = Scripts.getSpace().getPublisher(this.getClass().getName()); if (publisher == null || !publisher.isFunction()) { throw new NoPublisherException(); } published = (JSObject) publisher.call(null, new Object[]{this}); } return published; }