KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
27  * Expression node for the SQL add operation
28  *
29  * @author Dan Greff
30  */

31 final class JmsBinaryAdd extends JmsBinaryOperand
32 {
33
34   static {
35     STRING_REP = "+"; // Used in unparse
36
}
37
38
39     /////////////////////////////////////////////////////////////////////////
40
// Static Methods //
41
/////////////////////////////////////////////////////////////////////////
42
static JmsBinaryAdd getInstance(JmsOperand lvalue, JmsOperand rvalue)
43   {
44     JmsBinaryAdd retval;
45
46     retval = (JmsBinaryAdd) getInstanceReflective(JmsOperand.JMS_BINARY_ADD, lvalue, rvalue);
47     if (retval == null)
48       retval = new JmsBinaryAdd(lvalue, rvalue);
49
50     return retval;
51   }
52
53     /////////////////////////////////////////////////////////////////////////
54
// Constructor //
55
/////////////////////////////////////////////////////////////////////////
56
protected JmsBinaryAdd(JmsOperand lvalue, JmsOperand rvalue) {
57     super(lvalue, rvalue);
58   }
59
60     /////////////////////////////////////////////////////////////////////////
61
// Package Methods //
62
/////////////////////////////////////////////////////////////////////////
63

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