Class regexMatchFunction
- java.lang.Object
-
- org.apache.activemq.filter.function.regexMatchFunction
-
- All Implemented Interfaces:
FilterFunction
public class regexMatchFunction extends Object implements FilterFunction
Filter function that matches a value against a regular expression.REGEX( 'A.B', 'A-B' )
Note that the regular expression is not anchored; use the anchor characters, ^ and $, as-needed. For example, REGEX( 'AA', 'XAAX' ) evaluates to true while REGEX( '^AA$' , 'XAAX' ) evaluates to false.
-
-
Field Summary
Fields Modifier and Type Field Description protected static LRUCache<String,Pattern>
compiledExprCache
-
Constructor Summary
Constructors Constructor Description regexMatchFunction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
evaluate(FunctionCallExpression expr, MessageEvaluationContext message)
Evalutate the given expression, which consists of a call to this function, in the context given.protected Pattern
getCompiledPattern(String reg_ex_str)
Retrieve a compiled pattern for the given pattern string.boolean
isValid(FunctionCallExpression expr)
Check whether the given expression is a valid call of this function.boolean
returnsBoolean(FunctionCallExpression expr)
Indicate that this Filter Function evaluates to a Boolean result.
-
-
-
Method Detail
-
isValid
public boolean isValid(FunctionCallExpression expr)
Check whether the given expression is a valid call of this function. Two arguments are required. When evaluated, the arguments are converted to strings if they are not already strings.- Specified by:
isValid
in interfaceFilterFunction
- Parameters:
expr
- - the expression consisting of a call to this function.- Returns:
- true - if the expression is valid; false - otherwise.
-
returnsBoolean
public boolean returnsBoolean(FunctionCallExpression expr)
Indicate that this Filter Function evaluates to a Boolean result.- Specified by:
returnsBoolean
in interfaceFilterFunction
- Parameters:
expr
- - the expression consisting of a call to this function.- Returns:
- true - this function always evaluates to a Boolean result.
-
evaluate
public Object evaluate(FunctionCallExpression expr, MessageEvaluationContext message) throws JMSException
Evalutate the given expression, which consists of a call to this function, in the context given. Returns an indication of whether the second argument matches the regular expression in the first argument.- Specified by:
evaluate
in interfaceFilterFunction
- Parameters:
expr
- - the expression consisting of a call to this function.message
- - the context in which the call is being evaluated.- Returns:
- true - if the value matches the regular expression; false - otherwise.
- Throws:
JMSException
-
getCompiledPattern
protected Pattern getCompiledPattern(String reg_ex_str)
Retrieve a compiled pattern for the given pattern string. A cache of recently used strings is maintained to improve performance.- Parameters:
reg_ex_str
- - the string specifying the regular expression.- Returns:
- Pattern - compiled form of the regular expression.
-
-