KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
24  * Expression node for boolean literals.
25  *
26  * @author Dan Greff
27  */

28 class JmsBooleanLiteral extends JmsDataType
29 {
30   private static final short JMS_TRUE = 1;
31   private static final short JMS_FALSE = 2;
32   private static final short JMS_UNKNOWN = 3;
33
34   static final JmsBooleanLiteral TRUE = new JmsBooleanLiteral(JMS_TRUE);
35   static final JmsBooleanLiteral FALSE = new JmsBooleanLiteral(JMS_FALSE);
36   static final JmsBooleanLiteral UNKNOWN = new JmsBooleanLiteral(JMS_UNKNOWN);
37
38   private final short type;
39
40     /////////////////////////////////////////////////////////////////////////
41
// Constructor //
42
/////////////////////////////////////////////////////////////////////////
43

44   /**
45    * Protected constructor to guarntee that only the three static instances
46    * above exist in the JVM.
47    */

48   protected JmsBooleanLiteral(short type) {
49     super(false); // make sure this instance isn't tracked
50
this.type = type;
51
52     // Initialize the stringRepresentation final variable from
53
// JmsDataType so that the unParse() method works correctly
54
switch (type) {
55     case (JMS_TRUE):
56       stringRepresentation = "TRUE";
57       break;
58     case (JMS_FALSE):
59       stringRepresentation = "FALSE";
60       break;
61     default:
62       stringRepresentation = "UNKNOWN";
63     }
64   }
65
66     /////////////////////////////////////////////////////////////////////////
67
// Package Methods //
68
/////////////////////////////////////////////////////////////////////////
69

70   JmsBooleanLiteral eq(JmsDataType value) throws SelectorFalseException
71   {
72     if (! (value instanceof JmsBooleanLiteral))
73       throw SelectorFalseException.getInstance();
74
75     // NOTE!! this only works because the only way to get an instance
76
// of an JmsBooleanLiteral is through the static final instances above!
77
if (this == UNKNOWN || value == UNKNOWN)
78       return UNKNOWN;
79     if(this == value)
80       return JmsBooleanLiteral.TRUE;
81     else
82       return JmsBooleanLiteral.FALSE;
83   }
84
85   /**
86    * Used to identify this object in places where instanceof is
87    * inapplicable.
88    */

89   short getType() { return JmsOperand.JMS_BOOLEAN_LITERAL; }
90
91 }
92
Popular Tags