1 43 44 package org.exolab.jms.selector; 45 46 import java.io.StringReader ; 47 48 import javax.jms.InvalidSelectorException ; 49 import javax.jms.Message ; 50 51 import org.exolab.jms.selector.parser.SelectorLexer; 52 import org.exolab.jms.selector.parser.SelectorParser; 53 import org.exolab.jms.selector.parser.SelectorTreeParser; 54 55 56 214 public class Selector { 215 216 219 private final Expression _evaluator; 220 221 222 229 public Selector(final String expression) throws InvalidSelectorException { 230 try { 231 if (expression == null || expression.length() == 0) { 232 _evaluator = Literal.booleanLiteral(true); 234 } else { 235 SelectorLexer lexer = new SelectorLexer( 236 new StringReader (expression)); 237 lexer.initialise(); 238 239 SelectorParser parser = new SelectorParser(lexer); 240 parser.initialise(); 241 parser.selector(); 243 SelectorTreeParser builder = new SelectorTreeParser(); 244 builder.initialise(new DefaultExpressionFactory()); 245 _evaluator = builder.selector(parser.getAST()); 246 } 247 } catch (Exception exception) { 248 throw new InvalidSelectorException (exception.toString()); 249 } 250 } 251 252 259 public boolean selects(final Message message) { 260 boolean result = false; 261 try { 262 SObject value = _evaluator.evaluate(message); 263 if (value instanceof SBool) { 264 result = ((SBool) value).value(); 265 } 266 } catch (TypeMismatchException ignore) { 267 } 268 return result; 269 } 270 271 } | Popular Tags |