Package javax.script

Examples of javax.script.ScriptEngine


    List<String> factoryCandidates=this.getAllEngineFactoryCandidates();
    for (String candidate: factoryCandidates){
      System.out.println("Candidate: "+candidate);
      Class factoryClazz=this.getClass().getClassLoader().loadClass(candidate);
      ScriptEngineFactory factory=(ScriptEngineFactory) factoryClazz.newInstance();
      ScriptEngine engine=factory.getScriptEngine();
      try {
        engine.eval("puts 'Hello world'");
      } catch (ScriptException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if(manager.getEngineByName(factory.getLanguageName())!=null){
View Full Code Here


   * @throws EngineNotFoundException
   */
  public void setLanguage(String name) throws EngineNotFoundException{
    OSGiScriptEngineManager manager=(OSGiScriptEngineManager)engineManager;
    manager.reloadManagers();
    ScriptEngine newEngine=manager.getEngineByName(name);
    if(newEngine!=null) {
      engine=newEngine;
      language=engine.getFactory().getLanguageName();
      for(String key: engineManager.getBindings().keySet()){
        System.out.println(key);
View Full Code Here

  }
  public String getProgram(String... statements) {
    return factory.getProgram(statements);
  }
  public ScriptEngine getScriptEngine() {
    ScriptEngine engine=null;
    if(contextClassLoader!=null){
    ClassLoader old=Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(contextClassLoader);
    engine=factory.getScriptEngine();
    Thread.currentThread().setContextClassLoader(old);
View Full Code Here

        }).when(output).close();

        when(socketFactory.createSocket(any(InetAddress.class),
            anyInt())).thenReturn(socket);

        ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
        Compilable compilable = (Compilable) engine;
        unpickleScript = compilable.compile(UNPICKLER_SCRIPT);
    }
View Full Code Here

        return ObjectConverter.toBool(scriptValue);
    }

    protected ScriptEngine createScriptEngine() {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = null;
        try {
            engine = manager.getEngineByName(scriptEngineName);
        } catch (NoClassDefFoundError ex) {
            LOG.error("Cannot load the scriptEngine for " + scriptEngineName + ", the exception is " + ex
                      + ", please ensure correct JARs is provided on classpath.");
        }
        if (engine == null) {
            engine = checkForOSGiEngine();
        }
        if (engine == null) {
            throw new IllegalArgumentException("No script engine could be created for: " + getScriptEngineName());
        }
        if (isPython()) {
            ScriptContext context = engine.getContext();
            context.setAttribute("com.sun.script.jython.comp.mode", "eval", ScriptContext.ENGINE_SCOPE);
        }
        return engine;
    }
View Full Code Here

            final String ext, final Writer out) {
        try {
            parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            ScriptEngineManager mgr = new ScriptEngineManager();
            ScriptEngine engine = mgr.getEngineByExtension(ext);
            engine.getContext().setWriter(out);
            engine.getContext().setErrorWriter(out);
            engine.put("session", model.getClientSession().getSession());
            engine.put("binding", model.getClientSession().getSession().getBinding());
            engine.put("out", new PrintWriter(out));
            engine.eval(new FileReader(file));
        } catch (Exception ex) {
            ClientHelper.showError(null, ex);
        } finally {
            parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
View Full Code Here

        }

        @Override
        public void execute() {
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByExtension("js");
            u.p("engine = " + engine);
            engine.put("ctx",context);
            try {
                u.p("js = " + engine.eval(new InputStreamReader(new FileInputStream(file))));
            } catch (Exception e) {
                e.printStackTrace();
            }

View Full Code Here

    public Object evaluate(final String language, final String script) throws ScriptException {
        if (!ENGINE_FACTORIES.containsKey(language)) {
            throw new IllegalArgumentException("can't find factory for language " + language + ". You probably need to add the jar to openejb libs.");
        }

        final ScriptEngine engine = engine(language);
        return engine.eval(script);
    }
View Full Code Here

        final ScriptEngine engine = engine(language);
        return engine.eval(script);
    }

    private static ScriptEngine engine(String language) {
        ScriptEngine engine = ENGINES.get().get(language);
        if (engine == null) {
            final ScriptEngineFactory factory = ENGINE_FACTORIES.get(language);
            engine = factory.getScriptEngine();
            engine.setBindings(binding(), ScriptContext.ENGINE_SCOPE);
            ENGINES.get().put(language, engine);
        }
        return engine;
    }
View Full Code Here

    public ScriptEngine getEngineByExtension(String extension) {
        ScriptEngineFactory factory = state.extensionAssociations.get(extension);
        if (factory == null) return null;

        ScriptEngine engine = factory.getScriptEngine();

        //We do not support global scope for now
        //engine.setBindings(globalScope, ScriptContext.GLOBAL_SCOPE);

        return engine;
View Full Code Here

TOP

Related Classes of javax.script.ScriptEngine

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.