KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > presumo > jms > selector > JmsBinarySub


1 /**
2  * This file is part of Presumo.
3  *
4  * Presumo is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Presumo is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Presumo; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  *
19  * Copyright 2001 Dan Greff
20  */

21 package com.presumo.jms.selector;
22
23 import javax.jms.Message JavaDoc;
24
25 /**
26  * Expression node for the SQL substraction operation
27  *
28  * @author Dan Greff
29  */

30 final class JmsBinarySub extends JmsBinaryOperand
31 {
32   static
33   {
34     STRING_REP = " - "; // Used in unparse
35
}
36     /////////////////////////////////////////////////////////////////////////
37
// Static Methods //
38
/////////////////////////////////////////////////////////////////////////
39

40   static JmsBinarySub getInstance(JmsOperand lvalue, JmsOperand rvalue)
41   {
42     JmsBinarySub retval;
43
44     retval = (JmsBinarySub) getInstanceNonReflective(JmsOperand.JMS_BINARY_SUB, lvalue, rvalue);
45     if (retval == null)
46       retval = new JmsBinarySub(lvalue, rvalue);
47
48     return retval;
49   }
50   
51     /////////////////////////////////////////////////////////////////////////
52
// Constructor //
53
/////////////////////////////////////////////////////////////////////////
54
protected JmsBinarySub(JmsOperand lvalue, JmsOperand rvalue)
55   {
56     super(lvalue, rvalue);
57   }
58
59     /////////////////////////////////////////////////////////////////////////
60
// Package Methods //
61
/////////////////////////////////////////////////////////////////////////
62

63   JmsOperand evaluate(Message JavaDoc msg) throws SelectorFalseException
64   {
65
66     try {
67       JmsNumericLiteral leftSide = (JmsNumericLiteral) lvalue.evaluateOnce(msg);
68       if (leftSide == null)
69         return JmsBooleanLiteral.UNKNOWN;
70   
71       JmsNumericLiteral rightSide = (JmsNumericLiteral) rvalue.evaluateOnce(msg);
72       if (rightSide == null)
73         return JmsBooleanLiteral.UNKNOWN;
74
75       return leftSide.sub(rightSide);
76     } catch (ClassCastException JavaDoc e) {
77       throw SelectorFalseException.getInstance();
78     }
79   }
80
81   short getType() { return JmsOperand.JMS_BINARY_SUB; }
82   
83 }
84
Popular Tags