org.apache.activemq.filter.function
Class regexMatchFunction

java.lang.Object
  extended by 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
protected static LRUCache<String,Pattern> compiledExprCache
           
 
Constructor Summary
regexMatchFunction()
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

compiledExprCache

protected static final LRUCache<String,Pattern> compiledExprCache
Constructor Detail

regexMatchFunction

public regexMatchFunction()
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 interface FilterFunction
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 interface FilterFunction
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 interface FilterFunction
Parameters:
expr - - the expression consisting of a call to this function.
message_ctx - - 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.


Copyright © 2005–2013 The Apache Software Foundation. All rights reserved.