Examples of ScriptEngine


Examples of javax.script.ScriptEngine

     return engine;
  }

  public ScriptEngine getEngineByMimeType(String mimeType) {
    //TODO this is a hack to deal with context class loader issues
    ScriptEngine engine=null;
    for(ScriptEngineManager manager: classLoaders.keySet()){
      ClassLoader old=Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(classLoaders.get(manager));
      engine=manager.getEngineByMimeType(mimeType);
      Thread.currentThread().setContextClassLoader(old);
View Full Code Here

Examples of javax.script.ScriptEngine

  public ScriptEngine getEngineByName(String shortName) {
    //TODO this is a hack to deal with context class loader issues
    for(ScriptEngineManager manager: classLoaders.keySet()){
      ClassLoader old=Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(classLoaders.get(manager));
      ScriptEngine engine=manager.getEngineByName(shortName);
      Thread.currentThread().setContextClassLoader(old);
      if (engine!=null){
        return new OSGiScriptEngine(engine, new OSGiScriptEngineFactory(engine.getFactory(), classLoaders.get(manager)));
      }
    }
    return null;
  }
View Full Code Here

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

Examples of javax.script.ScriptEngine

   * @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

Examples of javax.script.ScriptEngine

  }
  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

Examples of javax.script.ScriptEngine

        }).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

Examples of javax.script.ScriptEngine

        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

Examples of javax.script.ScriptEngine

            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

Examples of javax.script.ScriptEngine

        }

        @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

Examples of javax.script.ScriptEngine

    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
TOP
Copyright © 2018 www.massapi.com. 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.