1 18 package org.apache.activemq.filter; 19 20 import javax.jms.JMSException ; 21 22 27 public abstract class LogicExpression extends BinaryExpression implements BooleanExpression { 28 29 public static BooleanExpression createOR(BooleanExpression lvalue, BooleanExpression rvalue) { 30 return new LogicExpression(lvalue, rvalue) { 31 32 public Object evaluate(MessageEvaluationContext message) throws JMSException { 33 34 Boolean lv = (Boolean ) left.evaluate(message); 35 if (lv !=null && lv.booleanValue()) { 37 return Boolean.TRUE; 38 } 39 40 Boolean rv = (Boolean ) right.evaluate(message); 41 return rv==null ? null : rv; 42 } 43 44 public String getExpressionSymbol() { 45 return "OR"; 46 } 47 }; 48 } 49 50 public static BooleanExpression createAND(BooleanExpression lvalue, BooleanExpression rvalue) { 51 return new LogicExpression(lvalue, rvalue) { 52 53 public Object evaluate(MessageEvaluationContext message) throws JMSException { 54 55 Boolean lv = (Boolean ) left.evaluate(message); 56 57 if (lv == null) 59 return null; 60 if (!lv.booleanValue()) { 61 return Boolean.FALSE; 62 } 63 64 Boolean rv = (Boolean ) right.evaluate(message); 65 return rv == null ? null : rv; 66 } 67 68 public String getExpressionSymbol() { 69 return "AND"; 70 } 71 }; 72 } 73 74 78 public LogicExpression(BooleanExpression left, BooleanExpression right) { 79 super(left, right); 80 } 81 82 abstract public Object evaluate(MessageEvaluationContext message) throws JMSException ; 83 84 public boolean matches(MessageEvaluationContext message) throws JMSException { 85 Object object = evaluate(message); 86 return object!=null && object==Boolean.TRUE; 87 } 88 89 } 90 | Popular Tags |