Package ch.obermuhlner.scriptengine.java
Class JavaScriptEngine
- java.lang.Object
-
- ch.obermuhlner.scriptengine.java.JavaScriptEngine
-
- All Implemented Interfaces:
javax.script.Compilable
,javax.script.ScriptEngine
public class JavaScriptEngine extends java.lang.Object implements javax.script.ScriptEngine, javax.script.Compilable
Script engine to compile and run a Java class on the fly.
-
-
Field Summary
Fields Modifier and Type Field Description private ConstructorStrategy
constructorStrategy
private javax.script.ScriptContext
context
private java.lang.ClassLoader
executionClassLoader
private ExecutionStrategyFactory
executionStrategyFactory
private Isolation
isolation
private NameStrategy
nameStrategy
-
Constructor Summary
Constructors Constructor Description JavaScriptEngine()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.script.CompiledScript
compile(java.io.Reader reader)
JavaCompiledScript
compile(java.lang.String script)
javax.script.Bindings
createBindings()
java.lang.Object
eval(java.io.Reader reader)
java.lang.Object
eval(java.io.Reader reader, javax.script.Bindings bindings)
java.lang.Object
eval(java.io.Reader reader, javax.script.ScriptContext context)
java.lang.Object
eval(java.lang.String script)
java.lang.Object
eval(java.lang.String script, javax.script.Bindings bindings)
java.lang.Object
eval(java.lang.String script, javax.script.ScriptContext context)
java.lang.Object
get(java.lang.String key)
javax.script.Bindings
getBindings(int scope)
javax.script.ScriptContext
getContext()
javax.script.ScriptEngineFactory
getFactory()
void
put(java.lang.String key, java.lang.Object value)
private java.lang.String
readScript(java.io.Reader reader)
void
setBindings(javax.script.Bindings bindings, int scope)
void
setConstructorStrategy(ConstructorStrategy constructorStrategy)
Sets the constructor strategy used to construct a Java instance of a class.void
setContext(javax.script.ScriptContext context)
void
setExecutionClassLoader(java.lang.ClassLoader executionClassLoader)
Sets theClassLoader
used to load and execute the class.void
setExecutionStrategyFactory(ExecutionStrategyFactory executionStrategyFactory)
Sets the factory for the execution strategy used to execute a method of a class instance.void
setIsolation(Isolation isolation)
Sets the isolation of the script.void
setNameStrategy(NameStrategy nameStrategy)
Sets the name strategy used to determine the Java class name from a script.
-
-
-
Field Detail
-
nameStrategy
private NameStrategy nameStrategy
-
constructorStrategy
private ConstructorStrategy constructorStrategy
-
executionStrategyFactory
private ExecutionStrategyFactory executionStrategyFactory
-
isolation
private Isolation isolation
-
context
private javax.script.ScriptContext context
-
executionClassLoader
private java.lang.ClassLoader executionClassLoader
-
-
Method Detail
-
setNameStrategy
public void setNameStrategy(NameStrategy nameStrategy)
Sets the name strategy used to determine the Java class name from a script.- Parameters:
nameStrategy
- theNameStrategy
to use in this script engine
-
setConstructorStrategy
public void setConstructorStrategy(ConstructorStrategy constructorStrategy)
Sets the constructor strategy used to construct a Java instance of a class.- Parameters:
constructorStrategy
- theConstructorStrategy
to use in this script engine
-
setExecutionStrategyFactory
public void setExecutionStrategyFactory(ExecutionStrategyFactory executionStrategyFactory)
Sets the factory for the execution strategy used to execute a method of a class instance.- Parameters:
executionStrategyFactory
- theExecutionStrategyFactory
to use in this script engine
-
setExecutionClassLoader
public void setExecutionClassLoader(java.lang.ClassLoader executionClassLoader)
Sets theClassLoader
used to load and execute the class.- Parameters:
executionClassLoader
- the executionClassLoader
-
setIsolation
public void setIsolation(Isolation isolation)
Sets the isolation of the script.- Parameters:
isolation
- theIsolation
-
getContext
public javax.script.ScriptContext getContext()
- Specified by:
getContext
in interfacejavax.script.ScriptEngine
-
setContext
public void setContext(javax.script.ScriptContext context)
- Specified by:
setContext
in interfacejavax.script.ScriptEngine
-
createBindings
public javax.script.Bindings createBindings()
- Specified by:
createBindings
in interfacejavax.script.ScriptEngine
-
getBindings
public javax.script.Bindings getBindings(int scope)
- Specified by:
getBindings
in interfacejavax.script.ScriptEngine
-
setBindings
public void setBindings(javax.script.Bindings bindings, int scope)
- Specified by:
setBindings
in interfacejavax.script.ScriptEngine
-
put
public void put(java.lang.String key, java.lang.Object value)
- Specified by:
put
in interfacejavax.script.ScriptEngine
-
get
public java.lang.Object get(java.lang.String key)
- Specified by:
get
in interfacejavax.script.ScriptEngine
-
eval
public java.lang.Object eval(java.io.Reader reader) throws javax.script.ScriptException
- Specified by:
eval
in interfacejavax.script.ScriptEngine
- Throws:
javax.script.ScriptException
-
eval
public java.lang.Object eval(java.lang.String script) throws javax.script.ScriptException
- Specified by:
eval
in interfacejavax.script.ScriptEngine
- Throws:
javax.script.ScriptException
-
eval
public java.lang.Object eval(java.io.Reader reader, javax.script.ScriptContext context) throws javax.script.ScriptException
- Specified by:
eval
in interfacejavax.script.ScriptEngine
- Throws:
javax.script.ScriptException
-
eval
public java.lang.Object eval(java.lang.String script, javax.script.ScriptContext context) throws javax.script.ScriptException
- Specified by:
eval
in interfacejavax.script.ScriptEngine
- Throws:
javax.script.ScriptException
-
eval
public java.lang.Object eval(java.io.Reader reader, javax.script.Bindings bindings) throws javax.script.ScriptException
- Specified by:
eval
in interfacejavax.script.ScriptEngine
- Throws:
javax.script.ScriptException
-
eval
public java.lang.Object eval(java.lang.String script, javax.script.Bindings bindings) throws javax.script.ScriptException
- Specified by:
eval
in interfacejavax.script.ScriptEngine
- Throws:
javax.script.ScriptException
-
compile
public javax.script.CompiledScript compile(java.io.Reader reader) throws javax.script.ScriptException
- Specified by:
compile
in interfacejavax.script.Compilable
- Throws:
javax.script.ScriptException
-
compile
public JavaCompiledScript compile(java.lang.String script) throws javax.script.ScriptException
- Specified by:
compile
in interfacejavax.script.Compilable
- Throws:
javax.script.ScriptException
-
getFactory
public javax.script.ScriptEngineFactory getFactory()
- Specified by:
getFactory
in interfacejavax.script.ScriptEngine
-
readScript
private java.lang.String readScript(java.io.Reader reader) throws javax.script.ScriptException
- Throws:
javax.script.ScriptException
-
-