org.apache.camel.builder.script
Class ScriptBuilder<E extends Exchange>

java.lang.Object
  extended by org.apache.camel.builder.script.ScriptBuilder<E>
All Implemented Interfaces:
Expression<E>, Predicate<E>, Processor

public class ScriptBuilder<E extends Exchange>
extends Object
implements Expression<E>, Predicate<E>, Processor

A builder class for creating Processor, Expression and Predicate objects using the JSR 223 scripting engine.

Version:
$Revision: 700514 $

Constructor Summary
ScriptBuilder(String scriptEngineName)
           
ScriptBuilder(String scriptEngineName, org.springframework.core.io.Resource scriptResource)
           
ScriptBuilder(String scriptEngineName, String scriptText)
           
 
Method Summary
 void assertMatches(String text, E 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
static ScriptBuilder beanShell(File scriptFile)
          Deprecated. will be removed in Camel 2.0
static ScriptBuilder beanShell(org.springframework.core.io.Resource scriptResource)
          Deprecated. will be removed in Camel 2.0
static ScriptBuilder beanShell(String scriptText)
          Deprecated. will be removed in Camel 2.0
static ScriptBuilder beanShell(URL scriptURL)
          Deprecated. will be removed in Camel 2.0
protected  void checkInitialised()
           
protected  void compileScript(javax.script.Compilable compilable)
           
protected  ScriptEvaluationException createScriptCompileException(Exception e)
           
protected  javax.script.ScriptEngine createScriptEngine()
           
protected  ScriptEvaluationException createScriptEvaluationException(Throwable e)
           
protected  InputStreamReader createScriptReader()
           
 Object evaluate(E exchange)
           
protected  Object evaluateScript(Exchange exchange)
           
 javax.script.CompiledScript getCompiledScript()
           
 javax.script.ScriptEngine getEngine()
           
 javax.script.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()
           
 org.springframework.core.io.Resource getScriptResource()
           
 String getScriptText()
           
static ScriptBuilder groovy(File scriptFile)
          Creates a script builder for the groovy script File
static ScriptBuilder groovy(org.springframework.core.io.Resource scriptResource)
          Creates a script builder for the groovy script Resource
static ScriptBuilder groovy(String scriptText)
          Creates a script builder for the groovy script contents
static ScriptBuilder groovy(URL scriptURL)
          Creates a script builder for the groovy script URL
protected  boolean isPython()
           
static ScriptBuilder javaScript(File scriptFile)
          Creates a script builder for the JavaScript/ECMAScript script File
static ScriptBuilder javaScript(org.springframework.core.io.Resource scriptResource)
          Creates a script builder for the JavaScript/ECMAScript script
static ScriptBuilder javaScript(String scriptText)
          Creates a script builder for the JavaScript/ECMAScript script contents
static ScriptBuilder javaScript(URL scriptURL)
          Creates a script builder for the JavaScript/ECMAScript script URL
 boolean matches(E exchange)
           
protected  boolean matches(E exchange, Object scriptValue)
           
static ScriptBuilder php(File scriptFile)
          Creates a script builder for the PHP script File
static ScriptBuilder php(org.springframework.core.io.Resource scriptResource)
          Creates a script builder for the PHP script Resource
static ScriptBuilder php(String scriptText)
          Creates a script builder for the PHP script contents
static ScriptBuilder php(URL scriptURL)
          Creates a script builder for the PHP script URL
protected  void populateBindings(javax.script.ScriptEngine engine, Exchange exchange)
           
 void process(Exchange exchange)
           
static ScriptBuilder python(File scriptFile)
          Creates a script builder for the Python script File
static ScriptBuilder python(org.springframework.core.io.Resource scriptResource)
          Creates a script builder for the Python script Resource
static ScriptBuilder python(String scriptText)
          Creates a script builder for the Python script contents
static ScriptBuilder python(URL scriptURL)
          Creates a script builder for the Python script URL
static ScriptBuilder ruby(File scriptFile)
          Creates a script builder for the Ruby/JRuby script File
static ScriptBuilder ruby(org.springframework.core.io.Resource scriptResource)
          Creates a script builder for the Ruby/JRuby script Resource
static ScriptBuilder ruby(String scriptText)
          Creates a script builder for the Ruby/JRuby script contents
static ScriptBuilder ruby(URL scriptURL)
          Creates a script builder for the Ruby/JRuby script URL
protected  Object runScript()
           
static ScriptBuilder script(String language, File scriptFile)
          Creates a script builder for the named language and script File
static ScriptBuilder script(String language, org.springframework.core.io.Resource scriptResource)
          Creates a script builder for the named language and script Resource
static ScriptBuilder script(String language, String scriptText)
          Creates a script builder for the named language and script contents
static ScriptBuilder script(String language, URL scriptURL)
          Creates a script builder for the named language and script URL
 void setScriptContext(javax.script.ScriptContext scriptContext)
          Sets the context to use by the script
 void setScriptResource(org.springframework.core.io.Resource scriptResource)
           
 void setScriptText(String scriptText)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScriptBuilder

public ScriptBuilder(String scriptEngineName)

ScriptBuilder

public ScriptBuilder(String scriptEngineName,
                     String scriptText)

ScriptBuilder

public ScriptBuilder(String scriptEngineName,
                     org.springframework.core.io.Resource scriptResource)
Method Detail

toString

public String toString()
Overrides:
toString in class Object

evaluate

public Object evaluate(E exchange)
Specified by:
evaluate in interface Expression<E extends Exchange>

matches

public boolean matches(E exchange)
Specified by:
matches in interface Predicate<E extends Exchange>

assertMatches

public void assertMatches(String text,
                          E exchange)
                   throws AssertionError
Specified by:
assertMatches in interface Predicate<E extends Exchange>
Throws:
AssertionError

process

public void process(Exchange exchange)
Specified by:
process in interface Processor

attribute

public 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

Parameters:
name - the name of the attribute
value - the attribute value
Returns:
this builder

script

public static ScriptBuilder script(String language,
                                   String scriptText)
Creates a script builder for the named language and script contents

Parameters:
language - the language to use for the script
scriptText - the script text to be evaluted
Returns:
the builder

script

public static ScriptBuilder script(String language,
                                   org.springframework.core.io.Resource scriptResource)
Creates a script builder for the named language and script Resource

Parameters:
language - the language to use for the script
scriptResource - the resource used to load the script
Returns:
the builder

script

public static ScriptBuilder script(String language,
                                   File scriptFile)
Creates a script builder for the named language and script File

Parameters:
language - the language to use for the script
scriptFile - the file used to load the script
Returns:
the builder

script

public static ScriptBuilder script(String language,
                                   URL scriptURL)
Creates a script builder for the named language and script URL

Parameters:
language - the language to use for the script
scriptURL - the URL used to load the script
Returns:
the builder

beanShell

public static ScriptBuilder beanShell(String scriptText)
Deprecated. will be removed in Camel 2.0

Creates a script builder for the BeanShell script contents

Parameters:
scriptText - the script text to be evaluted
Returns:
the builder

beanShell

public static ScriptBuilder beanShell(org.springframework.core.io.Resource scriptResource)
Deprecated. will be removed in Camel 2.0

Creates a script builder for the BeanShell script Resource

Parameters:
scriptResource - the resource used to load the script
Returns:
the builder

beanShell

public static ScriptBuilder beanShell(File scriptFile)
Deprecated. will be removed in Camel 2.0

Creates a script builder for the BeanShell script File

Parameters:
scriptFile - the file used to load the script
Returns:
the builder

beanShell

public static ScriptBuilder beanShell(URL scriptURL)
Deprecated. will be removed in Camel 2.0

Creates a script builder for the BeanShell script URL

Parameters:
scriptURL - the URL used to load the script
Returns:
the builder

groovy

public static ScriptBuilder groovy(String scriptText)
Creates a script builder for the groovy script contents

Parameters:
scriptText - the script text to be evaluted
Returns:
the builder

groovy

public static ScriptBuilder groovy(org.springframework.core.io.Resource scriptResource)
Creates a script builder for the groovy script Resource

Parameters:
scriptResource - the resource used to load the script
Returns:
the builder

groovy

public static ScriptBuilder groovy(File scriptFile)
Creates a script builder for the groovy script File

Parameters:
scriptFile - the file used to load the script
Returns:
the builder

groovy

public static ScriptBuilder groovy(URL scriptURL)
Creates a script builder for the groovy script URL

Parameters:
scriptURL - the URL used to load the script
Returns:
the builder

javaScript

public static ScriptBuilder javaScript(String scriptText)
Creates a script builder for the JavaScript/ECMAScript script contents

Parameters:
scriptText - the script text to be evaluted
Returns:
the builder

javaScript

public static ScriptBuilder javaScript(org.springframework.core.io.Resource scriptResource)
Creates a script builder for the JavaScript/ECMAScript script

Parameters:
scriptResource - the resource used to load the script
Returns:
the builder

javaScript

public static ScriptBuilder javaScript(File scriptFile)
Creates a script builder for the JavaScript/ECMAScript script File

Parameters:
scriptFile - the file used to load the script
Returns:
the builder

javaScript

public static ScriptBuilder javaScript(URL scriptURL)
Creates a script builder for the JavaScript/ECMAScript script URL

Parameters:
scriptURL - the URL used to load the script
Returns:
the builder

php

public static ScriptBuilder php(String scriptText)
Creates a script builder for the PHP script contents

Parameters:
scriptText - the script text to be evaluted
Returns:
the builder

php

public static ScriptBuilder php(org.springframework.core.io.Resource scriptResource)
Creates a script builder for the PHP script Resource

Parameters:
scriptResource - the resource used to load the script
Returns:
the builder

php

public static ScriptBuilder php(File scriptFile)
Creates a script builder for the PHP script File

Parameters:
scriptFile - the file used to load the script
Returns:
the builder

php

public static ScriptBuilder php(URL scriptURL)
Creates a script builder for the PHP script URL

Parameters:
scriptURL - the URL used to load the script
Returns:
the builder

python

public static ScriptBuilder python(String scriptText)
Creates a script builder for the Python script contents

Parameters:
scriptText - the script text to be evaluted
Returns:
the builder

python

public static ScriptBuilder python(org.springframework.core.io.Resource scriptResource)
Creates a script builder for the Python script Resource

Parameters:
scriptResource - the resource used to load the script
Returns:
the builder

python

public static ScriptBuilder python(File scriptFile)
Creates a script builder for the Python script File

Parameters:
scriptFile - the file used to load the script
Returns:
the builder

python

public static ScriptBuilder python(URL scriptURL)
Creates a script builder for the Python script URL

Parameters:
scriptURL - the URL used to load the script
Returns:
the builder

ruby

public static ScriptBuilder ruby(String scriptText)
Creates a script builder for the Ruby/JRuby script contents

Parameters:
scriptText - the script text to be evaluted
Returns:
the builder

ruby

public static ScriptBuilder ruby(org.springframework.core.io.Resource scriptResource)
Creates a script builder for the Ruby/JRuby script Resource

Parameters:
scriptResource - the resource used to load the script
Returns:
the builder

ruby

public static ScriptBuilder ruby(File scriptFile)
Creates a script builder for the Ruby/JRuby script File

Parameters:
scriptFile - the file used to load the script
Returns:
the builder

ruby

public static ScriptBuilder ruby(URL scriptURL)
Creates a script builder for the Ruby/JRuby script URL

Parameters:
scriptURL - the URL used to load the script
Returns:
the builder

getEngine

public javax.script.ScriptEngine getEngine()

getCompiledScript

public javax.script.CompiledScript getCompiledScript()

getScriptText

public String getScriptText()

setScriptText

public void setScriptText(String scriptText)

getScriptEngineName

public String getScriptEngineName()

getScriptDescription

public String getScriptDescription()
Returns a description of the script

Returns:
the script description

getScriptContext

public javax.script.ScriptContext getScriptContext()
Access the script context so that it can be configured such as adding attributes


setScriptContext

public void setScriptContext(javax.script.ScriptContext scriptContext)
Sets the context to use by the script


getScriptResource

public org.springframework.core.io.Resource getScriptResource()

setScriptResource

public void setScriptResource(org.springframework.core.io.Resource scriptResource)

checkInitialised

protected void checkInitialised()

matches

protected boolean matches(E exchange,
                          Object scriptValue)

createScriptEngine

protected javax.script.ScriptEngine createScriptEngine()

compileScript

protected void compileScript(javax.script.Compilable compilable)

evaluateScript

protected Object evaluateScript(Exchange exchange)

runScript

protected Object runScript()
                    throws javax.script.ScriptException,
                           IOException
Throws:
javax.script.ScriptException
IOException

populateBindings

protected void populateBindings(javax.script.ScriptEngine engine,
                                Exchange exchange)

createScriptReader

protected InputStreamReader createScriptReader()
                                        throws IOException
Throws:
IOException

createScriptCompileException

protected ScriptEvaluationException createScriptCompileException(Exception e)

createScriptEvaluationException

protected ScriptEvaluationException createScriptEvaluationException(Throwable e)

isPython

protected boolean isPython()


Copyright © 2009 Apache Software Foundation. All Rights Reserved.