public class ScriptBuilder
extends org.apache.camel.support.ServiceSupport
implements org.apache.camel.Expression, org.apache.camel.Predicate, org.apache.camel.Processor
Processor
, Expression
and
Predicate
objects using the JSR 223 scripting engine.Constructor and Description |
---|
ScriptBuilder(String scriptEngineName)
Constructor.
|
ScriptBuilder(String scriptEngineName,
String scriptText)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addScriptEngineArguments(ScriptEngine engine,
org.apache.camel.Exchange exchange) |
void |
assertMatches(String text,
org.apache.camel.Exchange exchange) |
ScriptBuilder |
attribute(String name,
Object value)
Sets the attribute on the context so that it is available to the script
as a variable in the
ScriptContext.ENGINE_SCOPE |
protected void |
checkInitialised(org.apache.camel.Exchange exchange) |
protected void |
compileScript(Compilable compilable,
org.apache.camel.Exchange exchange) |
protected ScriptEvaluationException |
createScriptCompileException(Exception e) |
protected ScriptEngine |
createScriptEngine() |
protected ScriptEvaluationException |
createScriptEvaluationException(Throwable e) |
protected InputStreamReader |
createScriptReader(org.apache.camel.Exchange exchange) |
protected void |
doStart() |
protected void |
doStop() |
Object |
evaluate(org.apache.camel.Exchange exchange) |
<T> T |
evaluate(org.apache.camel.Exchange exchange,
Class<T> type) |
protected Object |
evaluateScript(org.apache.camel.Exchange exchange) |
CompiledScript |
getCompiledScript() |
ScriptEngine |
getEngine() |
ScriptContext |
getScriptContext()
Access the script context so that it can be configured such as adding attributes
|
String |
getScriptDescription()
Returns a description of the script
|
String |
getScriptEngineName() |
String |
getScriptText() |
static ScriptBuilder |
groovy(String scriptText)
Creates a script builder for the groovy script contents
|
protected boolean |
isBeanShell() |
protected boolean |
isPython() |
static ScriptBuilder |
javaScript(String scriptText)
Creates a script builder for the JavaScript/ECMAScript script contents
|
boolean |
matches(org.apache.camel.Exchange exchange) |
protected boolean |
matches(org.apache.camel.Exchange exchange,
Object scriptValue) |
static ScriptBuilder |
php(String scriptText)
Creates a script builder for the PHP script contents
|
protected void |
populateBindings(ScriptEngine engine,
org.apache.camel.Exchange exchange) |
void |
process(org.apache.camel.Exchange exchange) |
static ScriptBuilder |
python(String scriptText)
Creates a script builder for the Python script contents
|
static ScriptBuilder |
ruby(String scriptText)
Creates a script builder for the Ruby/JRuby script contents
|
protected Object |
runScript(org.apache.camel.Exchange exchange) |
static ScriptBuilder |
script(String language,
String scriptText)
Creates a script builder for the named language and script contents
|
void |
setScriptContext(ScriptContext scriptContext)
Sets the context to use by the script
|
void |
setScriptText(String scriptText) |
String |
toString() |
public static final String ARGUMENTS
public ScriptBuilder(String scriptEngineName)
scriptEngineName
- the name of the scripting languagepublic Object evaluate(org.apache.camel.Exchange exchange)
public <T> T evaluate(org.apache.camel.Exchange exchange, Class<T> type)
evaluate
in interface org.apache.camel.Expression
public boolean matches(org.apache.camel.Exchange exchange)
matches
in interface org.apache.camel.Predicate
public void assertMatches(String text, org.apache.camel.Exchange exchange) throws AssertionError
AssertionError
public void process(org.apache.camel.Exchange exchange)
process
in interface org.apache.camel.Processor
public ScriptBuilder attribute(String name, Object value)
ScriptContext.ENGINE_SCOPE
name
- the name of the attributevalue
- the attribute valuepublic static ScriptBuilder script(String language, String scriptText)
language
- the language to use for the scriptscriptText
- the script text to be evaluated, or a reference to a script resourcepublic static ScriptBuilder groovy(String scriptText)
scriptText
- the script text to be evaluated, or a reference to a script resourcepublic static ScriptBuilder javaScript(String scriptText)
scriptText
- the script text to be evaluated, or a reference to a script resourcepublic static ScriptBuilder php(String scriptText)
scriptText
- the script text to be evaluated, or a reference to a script resourcepublic static ScriptBuilder python(String scriptText)
scriptText
- the script text to be evaluated, or a reference to a script resourcepublic static ScriptBuilder ruby(String scriptText)
scriptText
- the script text to be evaluated, or a reference to a script resourcepublic ScriptEngine getEngine()
public CompiledScript getCompiledScript()
public String getScriptText()
public void setScriptText(String scriptText)
public String getScriptEngineName()
public String getScriptDescription()
public ScriptContext getScriptContext()
public void setScriptContext(ScriptContext scriptContext)
protected void checkInitialised(org.apache.camel.Exchange exchange)
protected boolean matches(org.apache.camel.Exchange exchange, Object scriptValue)
protected ScriptEngine createScriptEngine()
protected void compileScript(Compilable compilable, org.apache.camel.Exchange exchange)
protected Object evaluateScript(org.apache.camel.Exchange exchange)
protected Object runScript(org.apache.camel.Exchange exchange) throws ScriptException, IOException
ScriptException
IOException
protected void populateBindings(ScriptEngine engine, org.apache.camel.Exchange exchange)
protected void addScriptEngineArguments(ScriptEngine engine, org.apache.camel.Exchange exchange)
protected InputStreamReader createScriptReader(org.apache.camel.Exchange exchange) throws IOException
IOException
protected ScriptEvaluationException createScriptCompileException(Exception e)
protected ScriptEvaluationException createScriptEvaluationException(Throwable e)
protected boolean isPython()
protected boolean isBeanShell()
protected void doStart() throws Exception
doStart
in class org.apache.camel.support.ServiceSupport
Exception
Apache Camel