public class ScriptFilter extends ScriptOperation implements Filter<ScriptOperation.Context>
Tuple
values.
This Filter
is based on the Janino compiler.
Specifically this filter uses the ScriptEvaluator
,
thus the syntax from that class is inherited here.
A script may use field names directly as parameters in the expression, or field positions with the syntax
"$n", where n is an integer.
Given an argument tuple with the fields "a" and "b", the following script returns true: boolean result = (a + b == $0 + $1);
return boolean;
ExpressionFilter
, a "script" requires each line to end in an semi-colon
(@{code ;}) and the final line to be a return
statement.
Further, the types of the tuple elements will be coerced into the given parameterTypes. Regardless of the actual
tuple element values, they will be converted to the types expected by the script if possible.ScriptOperation.Context
block, parameterNames, parameterTypes, returnType
fieldDeclaration, numArgs, trace
Constructor and Description |
---|
ScriptFilter(String script)
Constructor ScriptFilter creates a new ScriptFilter instance.
|
ScriptFilter(String script,
Class[] expectedTypes)
Constructor ScriptFilter creates a new ScriptFilter instance.
|
ScriptFilter(String script,
String[] parameterNames,
Class[] parameterTypes)
Constructor ScriptFilter creates a new ScriptFilter instance.
|
ScriptFilter(String script,
String parameterName,
Class parameterType)
Constructor ScriptFilter creates a new ScriptFilter instance.
|
Modifier and Type | Method and Description |
---|---|
String |
getScript() |
boolean |
isRemove(FlowProcess flowProcess,
FilterCall<ScriptOperation.Context> filterCall)
Method isRemove returns true if input should be removed from the tuple stream.
|
equals, evaluate, getBlock, getEvaluator, getParameterNames, getParameterTypes, getReturnType, guessParameterNames, hashCode, prepare
cleanup, flush, getFieldDeclaration, getNumArgs, getTrace, isSafe, printOperationInternal, toString, toStringInternal
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
cleanup, flush, getFieldDeclaration, getNumArgs, isSafe, prepare
@ConstructorProperties(value="script") public ScriptFilter(String script)
script
- of type String@ConstructorProperties(value={"script","parameterName","parameterType"}) public ScriptFilter(String script, String parameterName, Class parameterType)
script
- of type StringparameterName
- of type StringparameterType
- of type Class@ConstructorProperties(value={"script","expectedTypes"}) public ScriptFilter(String script, Class[] expectedTypes)
OperationCall.getArgumentFields()
to source the parameterNames
and parameterTypes
required by the other constructors, but
use expectedTypes
to coerce the incoming types to before passing as parameters to the expression.script
- of type StringexpectedTypes
- of type Class[]@ConstructorProperties(value={"script","parameterNames","parameterTypes"}) public ScriptFilter(String script, String[] parameterNames, Class[] parameterTypes)
script
- of type StringparameterNames
- of type String[]parameterTypes
- of type Class[]public boolean isRemove(FlowProcess flowProcess, FilterCall<ScriptOperation.Context> filterCall)
Filter
isRemove
in interface Filter<ScriptOperation.Context>
flowProcess
- of type FlowProcessfilterCall
- of type FilterCallCopyright © 2007-2015 Concurrent, Inc. All Rights Reserved.