KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > josql > expressions > BooleanExpression


1 /*
2  * Copyright 2004-2005 Gary Bentley
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may
5  * not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */

15 package org.josql.expressions;
16
17 import org.josql.Query;
18 import org.josql.QueryExecutionException;
19 import org.josql.QueryParseException;
20
21 /**
22  * This class represents a "boolean" expression, either <code>true</code> or <code>false</code>.
23  * <p>
24  * Last Modified By: $Author: barrygently $<br />
25  * Last Modified On: $Date: 2004/12/24 16:15:37 $<br />
26  * Current Revision: $Revision: 1.3 $<br />
27  */

28 public class BooleanExpression extends ValueExpression
29 {
30
31     private Boolean JavaDoc value = null;
32
33     public BooleanExpression ()
34     {
35
36     }
37
38     /**
39      * Always returns <code>true</code> since it represents a constant.
40      *
41      * @param q The Query object.
42      * @return <code>true</code> always.
43      */

44     public boolean hasFixedResult (Query q)
45     {
46
47     return true;
48
49     }
50
51     /**
52      * Returns a string version of this expression.
53      * Basically returns: true | false.
54      *
55      * @return A string version of this expression.
56      */

57     public String JavaDoc toString ()
58     {
59
60     if (this.isBracketed ())
61     {
62
63         return "(" + this.value.toString () + ")";
64
65     }
66
67     return this.value.toString ();
68
69     }
70
71     /**
72      * Get the expected return type.
73      *
74      * @param q The Query object.
75      * @return Always returns: <code>java.lang.Boolean.TYPE</code>.
76      */

77     public Class JavaDoc getExpectedReturnType (Query q)
78     {
79
80     return Boolean.TYPE;
81
82     }
83
84     /**
85      * Init this expression. Actually does nothing since it is a constant.
86      *
87      * @param q The Query object.
88      */

89     public void init (Query q)
90     {
91
92     // Nothing to do...
93

94     }
95
96     public void setValue (Boolean JavaDoc b)
97     {
98
99     this.value = b;
100
101     }
102
103     /**
104      * Returns whether this expression is <code>true</code> or <code>false</code>.
105      *
106      * @param o The current object, not used in this method.
107      * @param q The Query object, not used in this method.
108      * @return The value of this expression.
109      */

110     public boolean isTrue (Object JavaDoc o,
111                Query q)
112     {
113
114     return this.value.booleanValue ();
115
116     }
117
118     /**
119      * Get the value of this boolean.
120      *
121      * @param o The current object, not used in this method.
122      * @param q The Query object, not used in this method.
123      * @return The value of this expression.
124      */

125     public Object JavaDoc getValue (Object JavaDoc o,
126                 Query q)
127     {
128
129     return this.value;
130
131     }
132
133     /**
134      * Get the value of this boolean.
135      *
136      * @param o The current object, not used in this method.
137      * @param q The Query object, not used in this method.
138      * @return The value of this expression.
139      */

140     public Object JavaDoc evaluate (Object JavaDoc o,
141                 Query q)
142     {
143
144     return this.value;
145
146     }
147
148 }
149
Popular Tags