01: /**
02: *
03: * Copyright 2004 Hiram Chirino
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: **/package org.activemq.filter.mockrunner;
18:
19: import javax.jms.JMSException;
20: import javax.jms.Message;
21:
22: /**
23: * Alwin Ibba: Changed package
24: *
25: * A filter performing a comparison of two objects
26: *
27: * @version $Revision: 1.3 $
28: */
29: public abstract class LogicExpression extends BinaryExpression
30: implements BooleanExpression {
31:
32: public static BooleanExpression createOR(BooleanExpression lvalue,
33: BooleanExpression rvalue) {
34: return new LogicExpression(lvalue, rvalue) {
35:
36: public Object evaluate(Message message) throws JMSException {
37:
38: Boolean lv = (Boolean) left.evaluate(message);
39: // Can we do an OR shortcut??
40: if (lv != null && lv.booleanValue()) {
41: return Boolean.TRUE;
42: }
43:
44: Boolean rv = (Boolean) right.evaluate(message);
45: return rv == null ? null : rv;
46: }
47:
48: public String getExpressionSymbol() {
49: return "OR";
50: }
51: };
52: }
53:
54: public static BooleanExpression createAND(BooleanExpression lvalue,
55: BooleanExpression rvalue) {
56: return new LogicExpression(lvalue, rvalue) {
57:
58: public Object evaluate(Message message) throws JMSException {
59:
60: Boolean lv = (Boolean) left.evaluate(message);
61:
62: // Can we do an AND shortcut??
63: if (lv == null)
64: return null;
65: if (!lv.booleanValue()) {
66: return Boolean.FALSE;
67: }
68:
69: Boolean rv = (Boolean) right.evaluate(message);
70: return rv == null ? null : rv;
71: }
72:
73: public String getExpressionSymbol() {
74: return "AND";
75: }
76: };
77: }
78:
79: /**
80: * @param left
81: * @param right
82: */
83: public LogicExpression(BooleanExpression left,
84: BooleanExpression right) {
85: super (left, right);
86: }
87:
88: abstract public Object evaluate(Message message)
89: throws JMSException;
90:
91: }
|