Package javax.script

Examples of javax.script.CompiledScript


  public void failExprTest( String script)
  {
    try
    {
      CompiledScript res = compiler.compile(script);

    fail( "Script '" + script + "' should fail " );

    }
    catch(ScriptException ex)
View Full Code Here


   * @param expectedResult Object The expected result.
   * @return Object The result.
   */
  public Object doQuery( Object bean, String expr, Object expectedResult)
  {
    CompiledScript cscript = compileScript(expr);
    try
    {
      if(bean!=null)
      {
      context.setAttribute( "this", bean, ScriptContext.ENGINE_SCOPE );
      context.setAttribute( "self", bean, ScriptContext.ENGINE_SCOPE );
      }
      Object res = cscript.eval(context);
      assertEquals( expr, expectedResult, res);
      return res;
    }
    catch(ScriptException ex)
    {
View Full Code Here

    return doQuery( null, expr, expectedResult );
  }

  public void doFailQuery( String expr )
  {
    CompiledScript cscript = compileScript(expr);
    try
    {
      Object res = cscript.eval(context);
      fail( "expr '" + expr + "' should fail (got '" + res + "')" );
    }
    catch(ScriptException ex)
    { // Should fail with this exception
    }
View Full Code Here

  public void testRegisteredCompilerEL()
    throws ScriptException
  {
    String language = "el";
    // Try with language specified in script
    CompiledScript res = CompiledScriptFactory.compileScript( "script1", language);
    assertNotNull("Result found", res);
    assertEquals("Found right compiler", language, res.getEngine().getFactory().getLanguageName());
  }
View Full Code Here

  }

  public void testDefaultCompiler()
    throws ScriptException
   {
    CompiledScript res = CompiledScriptFactory.compileScript( "a" );
    assertNotNull("Result found", res);
   }
View Full Code Here

   }

   public void testRhinoScript()
     throws javax.script.ScriptException
    {
     CompiledScript compiledScript = CompiledScriptFactory.getInstance().compileScript( "a", "rhino" );

     javax.script.Namespace context = compiledScript.getEngine().createNamespace();
     context.put( "a", new Integer(123));
     Object res = compiledScript.eval( context);

     assertNotNull("Result found", res);
     assertEquals("Result found", new Integer(123), res);
    }
View Full Code Here

     * @throws ScriptException
     * @throws IOException
     */
    public static CompiledScript compileScriptFile(String filePath) throws ScriptException, IOException {
        Assert.notNull("filePath", filePath);
        CompiledScript script = parsedScripts.get(filePath);
        if (script == null) {
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByExtension(getFileExtension(filePath));
            if (engine == null) {
                throw new IllegalArgumentException("The script type is not supported for location: " + filePath);
View Full Code Here

     * @throws ScriptException
     */
    public static CompiledScript compileScriptString(String language, String script) throws ScriptException {
        Assert.notNull("language", language, "script", script);
        String cacheKey = language.concat("://").concat(script);
        CompiledScript compiledScript = parsedScripts.get(cacheKey);
        if (compiledScript == null) {
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName(language);
            if (engine == null) {
                throw new IllegalArgumentException("The script type is not supported for language: " + language);
View Full Code Here

        Assert.notNull("context", context);
        if (scriptClass != null) {
            return InvokerHelper.createScript(scriptClass, GroovyUtil.getBinding(context)).run();
        }
        try {
            CompiledScript compiledScript = compileScriptString(language, script);
            if (compiledScript != null) {
                return executeScript(compiledScript, null, createScriptContext(context), null);
            }
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName(language);
View Full Code Here

        Assert.notNull("filePath", filePath, "scriptContext", scriptContext);
        scriptContext.setAttribute(ScriptEngine.FILENAME, filePath, ScriptContext.ENGINE_SCOPE);
        if (functionName == null) {
            // The Rhino script engine will not work when invoking a function on a compiled script.
            // The test for null can be removed when the engine is fixed.
            CompiledScript script = compileScriptFile(filePath);
            if (script != null) {
                return executeScript(script, functionName, scriptContext, args);
            }
        }
        String fileExtension = getFileExtension(filePath);
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.