org.clapper.util.scripting
Class UnifiedScriptEngine

java.lang.Object
  extended by org.clapper.util.scripting.UnifiedScriptEngine
Direct Known Subclasses:
BSFScriptEngine, JavaxScriptEngine

public abstract class UnifiedScriptEngine
extends java.lang.Object

A script engine interface that provides a common set of methods that can map both the Apache Jakarta Bean Scripting Framework (BSF) and the Java 6 JSR 223 (javax.script) framework, allowing callers to use either underlying framework without changing code. This class is modeled on the JSR 223 interface, though it is much simpler.

Version:
$Revision: 6753 $

Constructor Summary
UnifiedScriptEngine()
           
 
Method Summary
 UnifiedCompiledScript compile(java.io.File scriptFile)
          Compile a script, if possible, returning an object that implements the UnifiedCompiledScript interface.
abstract  UnifiedCompiledScript compile(java.io.Reader scriptReader)
          Compile a script, if possible, returning an object that implements the UnifiedCompiledScript interface.
 UnifiedCompiledScript compile(java.lang.String scriptString)
          Compile a script, if possible, returning an object that implements the UnifiedCompiledScript interface.
abstract  java.lang.Object eval(java.lang.String scriptString)
          Evaluate a script or a script snippet and return the value of the evaluation.
 void exec(java.io.File scriptFile)
          Execute a script.
abstract  void exec(java.io.Reader scriptReader)
          Execute a script.
 void exec(java.lang.String scriptString)
          Execute a script.
abstract  void exec(UnifiedCompiledScript compiledScript)
          Execute a previously compiled script.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnifiedScriptEngine

public UnifiedScriptEngine()
Method Detail

compile

public abstract UnifiedCompiledScript compile(java.io.Reader scriptReader)
                                       throws UnifiedScriptException
Compile a script, if possible, returning an object that implements the UnifiedCompiledScript interface. (The interface's name was deliberately chosen to avoid conflicts with the JSR 223 CompiledScript interface. If the underlying script engine does not support compilation, then this routine simply returns null (rather than throwing an exception).

Parameters:
scriptReader - a Reader that will produce the script
Returns:
a representation of the compiled script, or null if the underlying scripting engine does not support compilation
Throws:
UnifiedScriptException - compilation error
See Also:
compile(String), compile(File)

compile

public final UnifiedCompiledScript compile(java.lang.String scriptString)
                                    throws UnifiedScriptException
Compile a script, if possible, returning an object that implements the UnifiedCompiledScript interface. (The interface's name was deliberately chosen to avoid conflicts with the JSR 223 CompiledScript interface. If the underlying script engine does not support compilation, then this routine simply returns null (rather than throwing an exception).

Parameters:
scriptString - a String containing the script
Returns:
a representation of the compiled script, or null if the underlying scripting engine does not support compilation
Throws:
UnifiedScriptException - compilation error
See Also:
compile(File), compile(Reader)

compile

public final UnifiedCompiledScript compile(java.io.File scriptFile)
                                    throws UnifiedScriptException
Compile a script, if possible, returning an object that implements the UnifiedCompiledScript interface. (The interface's name was deliberately chosen to avoid conflicts with the JSR 223 CompiledScript interface. If the underlying script engine does not support compilation, then this routine simply returns null (rather than throwing an exception).

Parameters:
scriptFile - file containing the script; the file's extension is used to determine the language
Returns:
a representation of the compiled script, or null if the underlying scripting engine does not support compilation
Throws:
java.io.IOException - error reading script
UnifiedScriptException - compilation error
See Also:
compile(String), compile(Reader)

exec

public abstract void exec(java.io.Reader scriptReader)
                   throws UnifiedScriptException
Execute a script.

Parameters:
scriptReader - a Reader that will produce the script
Throws:
UnifiedScriptException - compilation error
See Also:
exec(String), exec(File)

exec

public final void exec(java.io.File scriptFile)
                throws UnifiedScriptException
Execute a script.

Parameters:
scriptFile - file containing the script; the file's extension is used to determine the language
Throws:
UnifiedScriptException - compilation error
See Also:
exec(String), exec(Reader)

exec

public final void exec(java.lang.String scriptString)
                throws UnifiedScriptException
Execute a script.

Parameters:
scriptString - string containing the script
Throws:
UnifiedScriptException - compilation error
See Also:
exec(File), exec(Reader)

exec

public abstract void exec(UnifiedCompiledScript compiledScript)
                   throws UnifiedScriptException
Execute a previously compiled script.

Parameters:
compiledScript - the compiled script
Throws:
UnifiedScriptException - compilation error
See Also:
exec(File), exec(Reader)

eval

public abstract java.lang.Object eval(java.lang.String scriptString)
                               throws UnifiedScriptException
Evaluate a script or a script snippet and return the value of the evaluation.

Parameters:
scriptString - the script string
Returns:
the result of the evaluation, if anything
Throws:
UnifiedScriptException - on error


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.