Class JSRScriptEngineAdapter
- java.lang.Object
-
- org.webharvest.runtime.scripting.jsr.JSRScriptEngineAdapter
-
- All Implemented Interfaces:
ScriptEngine
public final class JSRScriptEngineAdapter extends Object implements ScriptEngine
Adapter design pattern implementation. Adapts providedScriptEngine
representing JSR-223 script engine to theScriptEngine
interface. This adapter is universal for all scripting language implementations supporting JSR-223 specification. It is important to bear in mind that this implementation is not thread-safe, that is,ScriptEngine
being adapted can not be shared between multiple threads. Bindings from scraper'sDynamicScopeContext
are copied directly to theScriptEngine
. This is performance trade-off, since currently creation of brand newScriptContext
instances each time script is evaluated is quite expensive.- Since:
- 2.1.0-SNAPSHOT
- Version:
- %I%, %G%
- Author:
- Piotr Dyraga
- See Also:
ScriptEngine
-
-
Constructor Summary
Constructors Constructor Description JSRScriptEngineAdapter(ScriptEngine adaptee)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
evaluate(DynamicScopeContext context, ScriptSource script)
Executes script provided inScriptSource
.
-
-
-
Constructor Detail
-
JSRScriptEngineAdapter
public JSRScriptEngineAdapter(ScriptEngine adaptee)
- Parameters:
adaptee
- adaptee reference; mandatory, must not benull
-
-
Method Detail
-
evaluate
public Object evaluate(DynamicScopeContext context, ScriptSource script)
Executes script provided inScriptSource
. Additionally, all variables defined inDynamicScopeContext
are copied to the script engine context, so that they are accessible within the script.- Specified by:
evaluate
in interfaceScriptEngine
- Parameters:
context
- notnull
reference to the currentDynamicScopeContext
script
- notnull
ScriptSource
representing script which is going to be executed- Returns:
- result of the script execution
-
-