KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 /**
21  * Represents an "IS NULL" (or "IS NOT NULL") expression.
22  * <p>
23  * Last Modified By: $Author: barrygently $<br />
24  * Last Modified On: $Date: 2004/12/20 16:22:43 $<br />
25  * Current Revision: $Revision: 1.2 $<br />
26  */

27 public class IsNullExpression extends BinaryExpression
28 {
29
30     private boolean not = false;
31
32     public boolean isNot ()
33     {
34
35     return this.not;
36
37     }
38
39     public void setNot (boolean v)
40     {
41
42     this.not = v;
43
44     }
45
46     /**
47      * Return a string representation of this expression.
48      * In the form: {@link Expression#toString()} IS [ NOT ] NULL
49      *
50      * @return A string representation of this expression.
51      */

52     public String JavaDoc toString ()
53     {
54
55     StringBuffer JavaDoc buf = new StringBuffer JavaDoc ("IS ");
56     
57     if (this.not)
58     {
59
60         buf.append ("NOT ");
61
62     }
63
64     buf.append (this.left.toString ());
65
66     if (this.isBracketed ())
67     {
68
69         buf.insert (0,
70             "(");
71         buf.append (")");
72
73     }
74
75     return buf.toString ();
76
77     }
78
79     /**
80      * Determine whether the LHS of this expression is or is not null.
81      * Note that this is equivalent to: <code>LHS = null</code> or:
82      * <code>LHS != null</code>.
83      *
84      * @param o The current object to perform the expression on.
85      * @param q The Query object.
86      * @return <code>true</code> if the LHS is null (or not null is specified).
87      * @throws QueryExecutionException If the expression cannot be evaluated.
88      */

89     public boolean isTrue (Object JavaDoc o,
90                Query q)
91                        throws QueryExecutionException
92     {
93
94     // Get the left...
95
o = this.left.getValue (o,
96                 q);
97
98     if (o == null)
99     {
100
101         if (this.not)
102         {
103
104         return false;
105
106         }
107
108         return true;
109
110     }
111
112     if (this.not)
113     {
114
115         return true;
116
117     }
118
119     return false;
120
121     }
122
123 }
124
Popular Tags