Package javax.script

Examples of javax.script.Bindings


        String payload = output.toString("UTF-8");

        PyList result = new PyList();
        int nextIndex = 0;
        while (nextIndex < payload.length()) {
            Bindings bindings = new SimpleBindings();
            bindings.put("payload", payload.substring(nextIndex));
            unpickleScript.eval(bindings);
            result.addAll(result.size(), (PyList) bindings.get("metrics"));
            nextIndex += (Integer) bindings.get("batchLength");
        }

        for (Object aResult : result) {
            PyTuple datapoint = (PyTuple) aResult;
            String name = datapoint.get(0).toString();
View Full Code Here


    public static void clearEngines() {
        ENGINES.get().clear();
    }

    private static Bindings binding() {
        final Bindings bindings = new SimpleBindings();
        bindings.put("bm", new BeanManagerHelper());

        final ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
        for (BeanContext beanContext : cs.deployments()) {
            if (BeanContext.Comp.class.equals(beanContext.getBeanClass())) {
                continue;
            }

            Object service = null;
            if (beanContext.getBusinessLocalInterface() != null) {
                service = ProxyEJB.proxy(beanContext, beanContext.getBusinessLocalInterfaces().toArray(new Class<?>[beanContext.getBusinessLocalInterfaces().size()]));
            } else if (beanContext.isLocalbean()) {
                service = ProxyEJB.proxy(beanContext, new Class<?>[] { beanContext.getBusinessLocalBeanInterface() });
            } else if (beanContext.getBusinessRemoteInterface() != null) {
                service = ProxyEJB.proxy(beanContext, beanContext.getBusinessRemoteInterfaces().toArray(new Class<?>[beanContext.getBusinessRemoteInterfaces().size()]));
            }

            if (service != null) {
                // replace all non alphanumeric characters in the ejb name by an underscore (to be a groovy variable)
                bindings.put(beanContext.getEjbName().replaceAll("[^a-zA-Z0-9]", "_"), service);
            }
        }
        return bindings;
    }
View Full Code Here

        this.rootScope = rootScope;
    }

    public Object eval(Reader scriptReader, ScriptContext scriptContext)
            throws ScriptException {
        Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
        String scriptName = "NO_SCRIPT_NAME";
        {
            SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
            if(helper != null) {
                scriptName = helper.getScript().getScriptResource().getPath();
            }
        }

        // wrap the reader in an EspReader for ESP scripts
        if (scriptName.endsWith(RhinoJavaScriptEngineFactory.ESP_SCRIPT_EXTENSION)) {
            scriptReader = new EspReader(scriptReader);
        }

        // create a rhino Context and execute the script
        try {
           
            final Context rhinoContext = Context.enter();
            final ScriptableObject scope = new NativeObject();

            // Set the global scope to be our prototype
            scope.setPrototype(rootScope);

            // We want "scope" to be a new top-level scope, so set its parent
            // scope to null. This means that any variables created by assignments
            // will be properties of "scope".
            scope.setParentScope(null);

            // setup the context for use
            rhinoContext.setWrapFactory(SlingWrapFactory.INSTANCE);

            // add initial properties to the scope
            for (Object entryObject : bindings.entrySet()) {
                Entry<?, ?> entry = (Entry<?, ?>) entryObject;
                Object wrapped = ScriptRuntime.toObject(scope, entry.getValue());
                ScriptableObject.putProperty(scope, (String) entry.getKey(),
                    wrapped);
            }

            final int lineNumber = 1;
            final Object securityDomain = null;

            return rhinoContext.evaluateReader(scope, scriptReader, scriptName,
                lineNumber, securityDomain);

        } catch (JavaScriptException t) {
           
            final ScriptException se = new ScriptException(t.details(),
                t.sourceName(), t.lineNumber());

            ((Logger) bindings.get(SlingBindings.LOG)).error(t.getScriptStackTrace());
            se.setStackTrace(t.getStackTrace());
            throw se;
           
        } catch (Throwable t) {
           
View Full Code Here

            super(JspScriptEngineFactory.this);
        }

        public Object eval(Reader script, ScriptContext context)
                throws ScriptException {
            Bindings props = context.getBindings(ScriptContext.ENGINE_SCOPE);
            SlingScriptHelper scriptHelper = (SlingScriptHelper) props.get(SLING);
            if (scriptHelper != null) {
                try {
                    callJsp(props, scriptHelper);
                } catch (Exception e) {
                    throw new ScriptException(e);
View Full Code Here

        ScriptContext scriptContext = new SimpleScriptContext();
        ScriptHelper helper = createScriptHelper(scriptContext);
        if (helper != null) {
            localContext.put(SCRIPT_HELPER_KEY, helper);
        }
        Bindings bindings = new SimpleBindings(localContext);
        scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        return scriptContext;
    }
View Full Code Here

        Assert.notNull("context", context, "protectedKeys", protectedKeys);
        Map<String, Object> localContext = new HashMap<String, Object>(context);
        localContext.put(WIDGET_CONTEXT_KEY, context);
        localContext.put("context", context);
        ScriptContext scriptContext = new SimpleScriptContext();
        Bindings bindings = new ProtectedBindings(localContext, Collections.unmodifiableSet(protectedKeys));
        scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        ScriptHelper helper = createScriptHelper(scriptContext);
        if (helper != null) {
            localContext.put(SCRIPT_HELPER_KEY, helper);
        }
View Full Code Here

            Preconditions.checkNotNull(registeredScript, "The script called " + flowName + " could not be found");
            if (registeredScript instanceof Scriptable)
            {
                Scriptable script = (Scriptable) registeredScript;
                Bindings bindings = script.getScriptEngine().createBindings();
                script.populateDefaultBindings(bindings);
                try
                {
                    return script.runScript(bindings);
                }
View Full Code Here

    }

    public void escalate(@Observes @Severity(Severity.Level.HEARTBEAT) Snapshot current) {
        List<Script> scripts = this.scripting.activeScripts();
        try {
            Bindings binding = this.scriptEngine.createBindings();
            binding.put("current", current);
            Snapshot recent = this.recentSnapshots.get(current.getInstanceName());
            binding.put("previous", recent);
            long start = System.currentTimeMillis();
            try {
                if (recent != null) {
                    for (Script script : scripts) {
                        Object retVal = null;
View Full Code Here

      this.context = new SimpleScriptContext();

      if (globalContext != null)
      {
        final Bindings bindings = globalContext.getBindings(ScriptContext.ENGINE_SCOPE);
        this.context.getBindings(ScriptContext.ENGINE_SCOPE).putAll(bindings);
      }
      else
      {
        context.setAttribute("dataFactory", dataFactory, ScriptContext.ENGINE_SCOPE);
View Full Code Here

    public BXMLSerializer() {
        xmlInputFactory = XMLInputFactory.newInstance();
        xmlInputFactory.setProperty("javax.xml.stream.isCoalescing", true);

        scriptEngineManager = new javax.script.ScriptEngineManager();
        scriptEngineManager.setBindings(new Bindings() {
            @Override
            public Object get(Object key) {
                return namespace.get(key.toString());
            }
View Full Code Here

TOP

Related Classes of javax.script.Bindings

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.