KickJava   Java API By Example, From Geeks To Geeks.

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


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 greater than expression. There is no
27  * implementation for greater than equals ">=" because the parser
28  * represents such statements as a less than with the operands switched.
29  *
30  * @author Dan Greff
31  */

32 final class JmsGreater extends JmsBinaryOperand
33 {
34   static
35   {
36     STRING_REP = " - "; // Used in unparse
37
}
38
39
40     /////////////////////////////////////////////////////////////////////////
41
// Static Methods //
42
/////////////////////////////////////////////////////////////////////////
43

44   static JmsGreater getInstance(JmsOperand lvalue, JmsOperand rvalue)
45   {
46     JmsGreater retval;
47
48     retval = (JmsGreater) getInstanceNonReflective(JmsOperand.JMS_GREATER, lvalue, rvalue);
49     if (retval == null)
50       retval = new JmsGreater(lvalue, rvalue);
51
52     return retval;
53   }
54
55     /////////////////////////////////////////////////////////////////////////
56
// Constructor //
57
/////////////////////////////////////////////////////////////////////////
58

59   protected JmsGreater(JmsOperand lvalue, JmsOperand rvalue)
60   {
61     super(lvalue, rvalue);
62   }
63
64     /////////////////////////////////////////////////////////////////////////
65
// Package Methods //
66
/////////////////////////////////////////////////////////////////////////
67

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