Package javax.script

Examples of javax.script.CompiledScript


    }

    public void testCompilable() throws Exception {
        assertTrue("Engine should implement Compilable", engine instanceof Compilable);
        Compilable cengine = (Compilable) engine;
        CompiledScript script = cengine.compile("40 + 2");
        assertEquals(Integer.valueOf(42), script.eval());
        assertEquals(Integer.valueOf(42), script.eval());
    }
View Full Code Here


     * @throws ScriptException in case of an exception
     */
    public final static Object NOT_DONE = new Object();
    public Object interpret(String line) throws ScriptException
    {
      CompiledScript cs = addInput(line);
      if (cs != null) {
          try {
              Object result = cs.eval(this.bindings);
              return result;
          }
          finally
          {
              reset();
View Full Code Here

      }
    }
    private CompiledScript tryCompiling(String string, int lineCount, int lastLineLength)
        throws ScriptException
    {
        CompiledScript result = null;
        try
        {
            Compilable c = (Compilable)this.engine;
            result = c.compile(string);
        } catch (ScriptException se) {}
View Full Code Here

                return null;
        }
        ++this.pendingLineCount;       
        this.sb.append(line);
        this.sb.append("\n");
        CompiledScript cs = tryCompiling(this.sb.toString(), getPendingLineCount(), line.length());

        if (cs == null) {
            return null;
        } else if (shouldEvaluatePendingInput(line.isEmpty())) {
          return cs;
View Full Code Here

    ODatabaseRecordInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (db != null && !(db instanceof ODatabaseRecordTx))
      db = db.getUnderlying();

    final OScriptManager scriptManager = Orient.instance().getScriptManager();
    CompiledScript compiledScript = request.getCompiledScript();

    if (compiledScript == null) {
      ScriptEngine scriptEngine = scriptManager.getEngine(language);

      if (!(scriptEngine instanceof Compilable))
        throw new OCommandExecutionException("Language '" + language + "' does not support compilation");

      // COMPILE FUNCTION LIBRARY
      String lib = scriptManager.getLibrary(db, language);
      if (lib == null)
        lib = "";

      parserText = lib + parserText;

      Compilable c = (Compilable) scriptEngine;
      try {
        compiledScript = c.compile(parserText);
      } catch (ScriptException e) {
        scriptManager.getErrorMessage(e, parserText);
      }

      request.setCompiledScript(compiledScript);
    }

    final Bindings binding = scriptManager.bind(compiledScript.getEngine().getBindings(ScriptContext.ENGINE_SCOPE),
        (ODatabaseRecordTx) db, iContext, iArgs);

    try {
      final Object ob = compiledScript.eval(binding);

      return OCommandExecutorUtility.transformResult(ob);
    } catch (ScriptException e) {
      throw new OCommandScriptException("Error on execution of the script", request.getText(), e.getColumnNumber(), e);
View Full Code Here

      } else if (cl.hasOption(script.getOpt())) {
        String inlineScript = cl.getOptionValue(script.getOpt());
        try {
          if (engine instanceof Compilable) {
            Compilable compiledEng = (Compilable) engine;
            CompiledScript script = compiledEng.compile(inlineScript);
            script.eval(ctx);
            if (invoke) {
              this.invokeFunctionOrMethod(shellState, engine, cl, argArray);
            }
          } else {
            engine.eval(inlineScript, ctx);
View Full Code Here

    Compilable eng = (Compilable) engine;
    FileInputStream fis = null;
   
    BufferedReader buff = null;
    InputStreamReader isr = null;
    CompiledScript cs = null;
   
    try{
     
      fis = new FileInputStream(file);
      isr = new InputStreamReader(fis);
View Full Code Here

        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);
View Full Code Here

  public Object eval(ScriptEngine engine, String script, ScriptContext context) throws ScriptException
  {
    if(engine instanceof Compilable && Config.SCRIPT_ALLOW_COMPILATION)
    {
      Compilable eng = (Compilable) engine;
      CompiledScript cs = eng.compile(script);
      return context != null ? cs.eval(context) : cs.eval();
    }
    return context != null ? engine.eval(script, context) : engine.eval(script);
  }
View Full Code Here

            Compilable compilable = (Compilable) engine;
            Bindings bindings = engine.createBindings();
            bindings.put("invokers", invokersCopy);
            bindings.put("invocation", invocation);
            bindings.put("context", RpcContext.getContext());
            CompiledScript function = compilable.compile(rule);
            Object obj = function.eval(bindings);
            if (obj instanceof Invoker[]) {
                invokersCopy = Arrays.asList((Invoker<T>[]) obj);
            } else if (obj instanceof Object[]) {
                invokersCopy = new ArrayList<Invoker<T>>();
                for (Object inv : (Object[]) obj) {
View Full Code Here

TOP

Related Classes of javax.script.CompiledScript

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.