Package javax.script

Examples of javax.script.ScriptEngineManager


public class ExecuteGroovyFromJSR223 {
    private static Logger log = Logger.getLogger(ExecuteGroovyFromJSR223.class.getName());
   
    public static void main(String[] args) {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("groovy");
        try {
            engine.eval("println 'Hello, Groovy!'");
            engine.eval(new FileReader("src/mjg/scripting/hello_world.groovy"));
           
            engine.put("street","Blackheath Avenue");
View Full Code Here


        }
    }
   
    @Test
    public void testLatLngJSR223() {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("groovy");
        engine.put("street", "Blackheath Avenue");
        engine.put("city","Greenwich");
        engine.put("state", "UK");
        try {
            engine.eval(new FileReader("src/geocodeV3.groovy"));
View Full Code Here

      throw new ScriptCompilationException(script, "Execution failure", ex);
    }
  }

  protected ScriptEngine discoverEngine(ScriptSource script, Map<String, Object> arguments) {
    ScriptEngineManager engineManager = new ScriptEngineManager(classLoader);
    ScriptEngine engine = null;

    if (StringUtils.hasText(language)) {
      engine = engineManager.getEngineByName(language);
    }
    else {
      // make use the extension (enhanced ScriptSource interface)
      Assert.hasText(extension, "no language or extension specified");
      engine = engineManager.getEngineByExtension(extension);
    }

    Assert.notNull(engine, "No suitable engine found for "
        + (StringUtils.hasText(language) ? "language " + language : "extension " + extension));
View Full Code Here

        eventFrame.setLocation(900, 100);
        eventFrame.setSize(600, 200);
        eventFrame.setContentPane(eventContentPane);
        eventFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

        scriptEngineManager = new ScriptEngineManager();
        scriptEngine = scriptEngineManager.getEngineByMimeType("application/javascript");

        mediaPlayerFactory = new MediaPlayerFactory();
        mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();
View Full Code Here

  }

  private String signDecipher(final String signature, final String playercode) {
    try {
      final ScriptEngine engine = new ScriptEngineManager()
      .getEngineByName("nashorn");
      engine.eval(new FileReader(Constants.DATA_PATH
          + "scripts/decrypt.js"));
      final Invocable invocable = (Invocable) engine;
View Full Code Here

    Map<ScriptEngineManager, ClassLoader> managers=new HashMap<ScriptEngineManager, ClassLoader>();
    try {
      for(String factoryName: findFactoryCandidates(context)){
        //We do not really need the class, but we need the classloader
        ClassLoader factoryLoader=Class.forName(factoryName).getClassLoader();
        ScriptEngineManager manager=new ScriptEngineManager(factoryLoader);
        manager.setBindings(bindings);
        managers.put(manager, factoryLoader);
      }
      return managers;
    } catch (IOException ioe) {
      throw new RuntimeException(ioe);
View Full Code Here

          factoryCandidates.add(line.trim());
          //Just for testing:
         
          try {
            Class engineFactory=Class.forName(line.trim());
            ScriptEngineManager manager=new ScriptEngineManager(engineFactory.getClassLoader());
            for (ScriptEngineFactory f: manager.getEngineFactories()){
              ClassLoader old=Thread.currentThread().getContextClassLoader();
              Thread.currentThread().setContextClassLoader(engineFactory.getClassLoader());
              ScriptEngine e=f.getScriptEngine();//.eval(f.getOutputStatement("Hello world"));
              Thread.currentThread().setContextClassLoader(old);
              e.eval("File.new(\"\")");
View Full Code Here

    return factoryCandidates;
  }
  public ScriptEngineManager getManagerFor(String factoryName) throws ClassNotFoundException{
    Class factory=Class.forName(factoryName);
    String a;
    ScriptEngineManager manager=new ScriptEngineManager(factory.getClassLoader());
    //Does this manager know the factory?
    boolean flag=false;
    for (ScriptEngineFactory fac : manager.getEngineFactories()){
      if(fac.getClass().equals(factory)) flag=true;
    }
    return manager;
   
  }
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

    protected boolean matches(Exchange exchange, Object scriptValue) {
        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) {
View Full Code Here

TOP

Related Classes of javax.script.ScriptEngineManager

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.