Package javax.script

Examples of javax.script.SimpleScriptContext


    protected ScriptContext getScriptContext(Bindings bindings) {
        if (bindings == null) {
            throw new NullPointerException("null bindings in engine scope");
        }

        ScriptContext newContext = new SimpleScriptContext();
        newContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        Bindings global = getBindings(ScriptContext.GLOBAL_SCOPE);
        if (global != null) {
            newContext.setBindings(global, ScriptContext.GLOBAL_SCOPE);
        }
        newContext.setReader(context.getReader());
        newContext.setWriter(context.getWriter());
        newContext.setErrorWriter(context.getErrorWriter());

        return newContext;
    }
View Full Code Here


          return 1;
        }
        invoke = true;
      }
     
      ScriptContext ctx = new SimpleScriptContext();
     
      // Put the following objects into the context so that they
      // are available to the scripts
      // TODO: What else should go in here?
      Bindings b = engine.getBindings(ScriptContext.ENGINE_SCOPE);
      b.put("connection", shellState.getConnector());
     
      List<Object> argValues = new ArrayList<Object>();
      if (cl.hasOption(args.getOpt())) {
        String[] argList = cl.getOptionValue(args.getOpt()).split(",");
        for (String arg : argList) {
          String[] parts = arg.split("=");
          if (parts.length == 0) {
            continue;
          } else if (parts.length == 1) {
            b.put(parts[0], null);
            argValues.add(null);
          } else if (parts.length == 2) {
            b.put(parts[0], parts[1]);
            argValues.add(parts[1]);
          }
        }
      }
      ctx.setBindings(b, ScriptContext.ENGINE_SCOPE);
      Object[] argArray = argValues.toArray(new Object[argValues.size()]);
     
      Writer writer = null;
      if (cl.hasOption(out.getOpt())) {
        File f = new File(cl.getOptionValue(out.getOpt()));
        writer = new FileWriter(f);
        ctx.setWriter(writer);
      }
     
      if (cl.hasOption(file.getOpt())) {
        File f = new File(cl.getOptionValue(file.getOpt()));
        if (!f.exists()) {
View Full Code Here

            throw new IllegalArgumentException("can't find factory for language " + language + ". You probably need to add the jar to openejb libs.");
        }

        ScriptContext executionContext = context;
        if (executionContext == null) {
            executionContext = new SimpleScriptContext();
        }

        //we bind local variables (per execution) every time we execute a script
        bindLocal(executionContext);
View Full Code Here

        final ScriptEngineManager manager = new ScriptEngineManager();
        final ScriptEngine engine = manager.getEngineByName((String) this.options.get("engineName"));

        //new context for the execution of this script
        final ScriptContext newContext = new SimpleScriptContext();

        //creating the bidings object for the current execution
        final Bindings bindings = newContext.getBindings(ScriptContext.ENGINE_SCOPE);

        bindings.put("user", this.userData.user);
        bindings.put("password", this.userData.pass);

        final List<String> myGroups;
View Full Code Here

        }
      }

      if(engine instanceof Compilable && Config.SCRIPT_ALLOW_COMPILATION)
      {
        ScriptContext context = new SimpleScriptContext();
        context.setAttribute("mainClass", getClassForFile(file).replace('/', '.').replace('\\', '.'), ScriptContext.ENGINE_SCOPE);
        context.setAttribute(ScriptEngine.FILENAME, file.getName(), ScriptContext.ENGINE_SCOPE);
        context.setAttribute("classpath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
        context.setAttribute("sourcepath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
        context.setAttribute(JythonScriptEngine.JYTHON_ENGINE_INSTANCE, engine, ScriptContext.ENGINE_SCOPE);

        setCurrentLoadingScript(file);
        ScriptContext ctx = engine.getContext();
        try
        {
          engine.setContext(context);
          if(Config.SCRIPT_CACHE)
          {
            CompiledScript cs = _cache.loadCompiledScript(engine, file);
            cs.eval(context);
          }
          else
          {
            Compilable eng = (Compilable) engine;
            CompiledScript cs = eng.compile(lnr);
            cs.eval(context);
          }
        }
        finally
        {
          engine.setContext(ctx);
          setCurrentLoadingScript(null);
          context.removeAttribute(ScriptEngine.FILENAME, ScriptContext.ENGINE_SCOPE);
          context.removeAttribute("mainClass", ScriptContext.ENGINE_SCOPE);
        }
      }
      else
      {
        ScriptContext context = new SimpleScriptContext();
        context.setAttribute("mainClass", getClassForFile(file).replace('/', '.').replace('\\', '.'), ScriptContext.ENGINE_SCOPE);
        context.setAttribute(ScriptEngine.FILENAME, file.getName(), ScriptContext.ENGINE_SCOPE);
        context.setAttribute("classpath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
        context.setAttribute("sourcepath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
        setCurrentLoadingScript(file);
        try
        {
          engine.eval(lnr, context);
        }
View Full Code Here

  }

  @Override
  public Map<String, Object> preprocessData(Map<String, Object> data, PreprocessChainContext chainContext) {

    ScriptContext newContext = new SimpleScriptContext();
    Bindings engineScope = newContext.getBindings(ScriptContext.ENGINE_SCOPE);
    engineScope.put("data", data);

    try {
      synchronized (engine) {
        engine.eval(script, newContext);
View Full Code Here

    }

    public void testScriptFilename() {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine pythonEngine = manager.getEngineByName("python");
        SimpleScriptContext scriptContext = new SimpleScriptContext();
        scriptContext.setAttribute(ScriptEngine.FILENAME, "sample.py", ScriptContext.ENGINE_SCOPE);
        try {
            pythonEngine.eval("foo", scriptContext);
        } catch (ScriptException e) {
            assertEquals("sample.py", e.getFileName());
            return;
View Full Code Here

  protected boolean storeScriptVariables = true; // By default everything is stored (backwards compatibility)
 
  public ScriptBindings(List<Resolver> scriptResolvers, VariableScope variableScope) {
    this.scriptResolvers = scriptResolvers;
    this.variableScope = variableScope;
    this.defaultBindings = new SimpleScriptContext().getBindings(SimpleScriptContext.ENGINE_SCOPE);
  }
View Full Code Here

        // create globals
        _G = JsePlatform.standardGlobals();
     
      // set up context
      ScriptContext ctx = new SimpleScriptContext();
      ctx.setBindings(createBindings(), ScriptContext.ENGINE_SCOPE);
        setContext(ctx);
       
        // set special values
        put(LANGUAGE_VERSION, __LANGUAGE_VERSION__);
        put(LANGUAGE, __LANGUAGE__);
View Full Code Here

        final ScriptEngineManager manager = new ScriptEngineManager();
        final ScriptEngine engine = manager.getEngineByName((String) this.options.get("engineName"));

        //new context for the execution of this script
        final ScriptContext newContext = new SimpleScriptContext();

        //creating the bidings object for the current execution
        final Bindings bindings = newContext.getBindings(ScriptContext.ENGINE_SCOPE);

        bindings.put("user", this.userData.user);
        bindings.put("password", this.userData.pass);

        final List<String> myGroups;
View Full Code Here

TOP

Related Classes of javax.script.SimpleScriptContext

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.