Search in sources :

Example 71 with Function

use of org.mozilla.javascript.Function in project Osmand by osmandapp.

the class JsCommandBuilder method callVoidJsFunction.

private void callVoidJsFunction(Object function, Object[] params) {
    if (function instanceof Function) {
        Function jsFunction = (Function) function;
        jsFunction.call(jsContext, jsScope, jsScope, params);
    }
}
Also used : Function(org.mozilla.javascript.Function)

Example 72 with Function

use of org.mozilla.javascript.Function in project candlepin by candlepin.

the class JsRunner method init.

/**
 * initialize the javascript rules for the provided namespace. you must run
 * this
 * before trying to run a javascript rule or method.
 *
 * @param namespace the javascript rules namespace containing the rules type
 *        you want
 */
public void init(String namespace) {
    this.namespace = namespace;
    if (!initialized) {
        Context context = Context.enter();
        try {
            Object func = ScriptableObject.getProperty(scope, namespace);
            this.rulesNameSpace = unwrapReturnValue(((Function) func).call(context, scope, scope, Context.emptyArgs));
            this.initialized = true;
        } catch (RhinoException ex) {
            this.initialized = false;
            throw new RuleParseException(ex);
        } finally {
            Context.exit();
        }
    }
}
Also used : Context(org.mozilla.javascript.Context) Function(org.mozilla.javascript.Function) ScriptableObject(org.mozilla.javascript.ScriptableObject) RhinoException(org.mozilla.javascript.RhinoException)

Example 73 with Function

use of org.mozilla.javascript.Function in project convertigo by convertigo.

the class Transaction method executeSimpleHandlerCore.

protected void executeSimpleHandlerCore(String handlerType, org.mozilla.javascript.Context myJavascriptContext) throws EcmaError, EvaluatorException, JavaScriptException, EngineException {
    handlerName = "on" + handlerType;
    Engine.logBeans.trace("(Transaction) Searching the " + handlerType + " handler (" + handlerName + ")");
    Object object = scope.get(handlerName, scope);
    Engine.logBeans.trace("(Transaction) Rhino returned: [" + object.getClass().getName() + "] " + object.toString());
    if (!(object instanceof Function)) {
        Engine.logBeans.debug("(Transaction) No " + handlerType + " handler (" + handlerName + ") found");
        return;
    } else {
        Engine.logBeans.debug("(Transaction) Execution of the " + handlerType + " handler (" + handlerName + ") for the transaction '" + getName() + "'");
    }
    function = (Function) object;
    Object returnedValue = function.call(myJavascriptContext, scope, scope, null);
    if (returnedValue instanceof org.mozilla.javascript.Undefined) {
        handlerResult = "";
    } else {
        handlerResult = returnedValue.toString();
    }
}
Also used : Function(org.mozilla.javascript.Function) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject)

Example 74 with Function

use of org.mozilla.javascript.Function in project convertigo by convertigo.

the class RequestableObject method synchronize.

public static Object synchronize(org.mozilla.javascript.Context cx, Scriptable thisObj, Object[] args, Function funObj) {
    if (args.length < 2) {
        return null;
    }
    Object lock = ((NativeJavaObject) args[0]).unwrap();
    Function fun = (Function) args[1];
    Object res;
    synchronized (lock) {
        res = fun.call(cx, thisObj, thisObj, null);
    }
    return res;
}
Also used : Function(org.mozilla.javascript.Function) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) FunctionObject(org.mozilla.javascript.FunctionObject) NativeJavaObject(org.mozilla.javascript.NativeJavaObject)

Example 75 with Function

use of org.mozilla.javascript.Function in project convertigo by convertigo.

the class UIDynamicElement method getFormatedLabel.

protected String getFormatedLabel() {
    if (ionBean != null) {
        String source = ionBean.getDisplayFormat();
        if (!source.isEmpty()) {
            String sourceName = "displayFormat", message = null;
            Context javascriptContext = org.mozilla.javascript.Context.enter();
            Scriptable scope = javascriptContext.initStandardObjects(null);
            for (IonProperty property : ionBean.getProperties().values()) {
                String p_name = property.getName();
                // Object p_value = property.getValue();
                String smartValue = property.getSmartType().getLabel().replace("{{", "").replace("}}", "").replace("?.", ".");
                Scriptable jsObject = ((smartValue == null) ? null : org.mozilla.javascript.Context.toObject(smartValue, scope));
                scope.put(p_name, scope, jsObject);
            }
            try {
                Object ob = RhinoUtils.evalInterpretedJavascript(javascriptContext, scope, source, sourceName, 1, null);
                if (ob instanceof Function) {
                    Object returnedValue = ((Function) ob).call(javascriptContext, scope, scope, new Object[] {});
                    return returnedValue.toString();
                }
            } catch (EcmaError e) {
                message = "Unable to evaluate code for '" + sourceName + "'.\n" + "UIDynamicElement: \"" + getName() + "\"\n" + "A Javascript runtime error has occured at line " + e.lineNumber() + ", column " + e.columnNumber() + ": " + e.getMessage() + " \n" + e.lineSource();
            } catch (EvaluatorException e) {
                message = "Unable to evaluate code for '" + sourceName + "'.\n" + "UIDynamicElement: \"" + getName() + "\"\n" + "A Javascript evaluation error has occured: " + e.getMessage();
            } catch (JavaScriptException e) {
                message = "Unable to evaluate code for '" + sourceName + "'.\n" + "UIDynamicElement: \"" + getName() + "\"\n" + "A Javascript error has occured: " + e.getMessage();
            } finally {
                if (javascriptContext != null) {
                    org.mozilla.javascript.Context.exit();
                }
                if (message != null) {
                    System.out.println(message);
                    Engine.logBeans.warn(message);
                }
            }
        }
    }
    return null;
}
Also used : Context(org.mozilla.javascript.Context) Function(org.mozilla.javascript.Function) IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) EcmaError(org.mozilla.javascript.EcmaError) EvaluatorException(org.mozilla.javascript.EvaluatorException) JSONObject(org.codehaus.jettison.json.JSONObject) Scriptable(org.mozilla.javascript.Scriptable) JavaScriptException(org.mozilla.javascript.JavaScriptException)

Aggregations

Function (org.mozilla.javascript.Function)126 Scriptable (org.mozilla.javascript.Scriptable)35 Context (org.mozilla.javascript.Context)33 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)27 ScriptableObject (org.mozilla.javascript.ScriptableObject)27 JSFunction (org.mozilla.javascript.annotations.JSFunction)25 MouseEventImpl (org.loboevolution.html.js.events.MouseEventImpl)11 BaseFunction (org.mozilla.javascript.BaseFunction)10 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)10 NativeObject (org.mozilla.javascript.NativeObject)10 RepositoryException (com.servoy.j2db.persistence.RepositoryException)8 GlobalScope (com.servoy.j2db.scripting.GlobalScope)7 ServoyException (com.servoy.j2db.util.ServoyException)7 IOException (java.io.IOException)7 HtmlRendererContext (org.loboevolution.http.HtmlRendererContext)7 JSONObject (org.json.JSONObject)6 ModelNode (org.loboevolution.html.dom.nodeimpl.ModelNode)6 RhinoException (org.mozilla.javascript.RhinoException)6 PropertyDescription (org.sablo.specification.PropertyDescription)6 ArrayList (java.util.ArrayList)5