public class ScriptBuilder extends Object 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(org.apache.camel.CamelContext camelContext,
String scriptLanguage,
String scriptText)
Constructor.
|
ScriptBuilder(org.apache.camel.CamelContext camelContext,
String scriptLanguage,
String scriptText,
ScriptEngineFactory scriptEngineFactory)
Constructor.
|
ScriptBuilder(String scriptLanguage,
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 static ScriptEngine |
createScriptEngine(String language,
boolean allowNull) |
protected ScriptEvaluationException |
createScriptEvaluationException(Throwable e) |
protected static InputStreamReader |
createScriptReader(org.apache.camel.spi.ClassResolver classResolver,
String resource) |
protected Object |
doEvaluateScript(org.apache.camel.Exchange exchange,
ScriptEngine scriptEngine) |
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() |
String |
getScriptDescription()
Returns a description of the script
|
String |
getScriptLanguage() |
static ScriptBuilder |
groovy(String scriptText)
Creates a script builder for the groovy script contents
|
static ScriptBuilder |
javaScript(String scriptText)
Creates a script builder for the JavaScript/ECMAScript script contents
|
protected static ScriptEngineFactory |
lookupScriptEngineFactory(String language) |
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 ScriptContext |
populateBindings(ScriptEngine engine,
org.apache.camel.Exchange exchange,
Map<String,Object> attributes) |
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(ScriptEngine engine,
org.apache.camel.Exchange exchange,
ScriptContext context) |
static ScriptBuilder |
script(String language,
String scriptText)
Creates a script builder for the named language and script contents
|
static boolean |
supportScriptLanguage(String language)
Whether the given language is a language that is supported by a scripting engine.
|
String |
toString() |
public static final String ARGUMENTS
public ScriptBuilder(String scriptLanguage, String scriptText)
scriptLanguage
- the name of the scripting languagescriptText
- the script text to be evaluated, or a reference to a script resourcepublic ScriptBuilder(org.apache.camel.CamelContext camelContext, String scriptLanguage, String scriptText)
scriptLanguage
- the name of the scripting languagescriptText
- the script text to be evaluated, or a reference to a script resourcepublic ScriptBuilder(org.apache.camel.CamelContext camelContext, String scriptLanguage, String scriptText, ScriptEngineFactory scriptEngineFactory)
scriptLanguage
- the name of the scripting languagescriptText
- the script text to be evaluated, or a reference to a script resourcescriptEngineFactory
- the script engine factorypublic 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 static boolean supportScriptLanguage(String language)
public CompiledScript getCompiledScript()
public String getScriptLanguage()
public String getScriptDescription()
protected boolean matches(org.apache.camel.Exchange exchange, Object scriptValue)
protected static ScriptEngineFactory lookupScriptEngineFactory(String language)
protected static ScriptEngine createScriptEngine(String language, boolean allowNull)
protected Object evaluateScript(org.apache.camel.Exchange exchange)
protected Object doEvaluateScript(org.apache.camel.Exchange exchange, ScriptEngine scriptEngine) throws ScriptException, IOException
ScriptException
IOException
protected Object runScript(ScriptEngine engine, org.apache.camel.Exchange exchange, ScriptContext context) throws ScriptException, IOException
ScriptException
IOException
protected ScriptContext populateBindings(ScriptEngine engine, org.apache.camel.Exchange exchange, Map<String,Object> attributes)
protected void addScriptEngineArguments(ScriptEngine engine, org.apache.camel.Exchange exchange)
protected static InputStreamReader createScriptReader(org.apache.camel.spi.ClassResolver classResolver, String resource) throws IOException
IOException
protected ScriptEvaluationException createScriptEvaluationException(Throwable e)
Apache Camel