Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/filter/LogicExpression.java


1   /** 
2    * 
3    * Copyright 2004 Hiram Chirino
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * 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   **/
18  package org.activemq.filter;
19  
20  import javax.jms.JMSException;
21  import javax.jms.Message;
22  
23  /**
24   * A filter performing a comparison of two objects
25   * 
26   * @version $Revision: 1.1.1.1 $
27   */
28  public abstract class LogicExpression extends BinaryExpression implements BooleanExpression {
29  
30      public static BooleanExpression createOR(BooleanExpression lvalue, BooleanExpression rvalue) {
31          return new LogicExpression(lvalue, rvalue) {
32            
33              public Object evaluate(Message message) throws JMSException {
34                  
35                Boolean lv = (Boolean) left.evaluate(message);
36                  // Can we do an OR shortcut??
37                if (lv !=null && lv.booleanValue()) {
38                      return Boolean.TRUE;
39                  }
40                
41                  Boolean rv = (Boolean) right.evaluate(message);
42                  return rv==null ? null : rv;
43              }
44  
45              public String getExpressionSymbol() {
46                  return "OR";
47              }
48          };
49      }
50  
51      public static BooleanExpression createAND(BooleanExpression lvalue, BooleanExpression rvalue) {
52          return new LogicExpression(lvalue, rvalue) {
53              
54            public Object evaluate(Message message) throws JMSException {
55                  
56                Boolean lv = (Boolean) left.evaluate(message);
57                
58                  // Can we do an AND shortcut??
59                if( lv==null )
60                  return null;
61                if (!lv.booleanValue()) {
62                      return Boolean.FALSE;
63                  }
64                
65                  Boolean rv = (Boolean) right.evaluate(message);
66                  return rv==null ? null : rv;
67              }
68  
69              public String getExpressionSymbol() {
70                  return "AND";
71              }
72          };
73      }
74  
75      /**
76       * @param left
77       * @param right
78       */
79      public LogicExpression(BooleanExpression left, BooleanExpression right) {
80          super(left, right);
81      }
82  
83      abstract public Object evaluate(Message message) throws JMSException;
84  
85  
86  }