KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > jdo > jdoql > LocalVariable


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

17
18 /**
19  * Encapsulates a variable local to the JDOQL query. This can be either a
20  * variable or a parameter. Variables must be at some point bound to values
21  * either directly by the user of the query (if a parameter) or during
22  * evaluation of the query.
23  *
24  * @author <a HREF="mailto:tomdz@apache.org">Thomas Dudziak</a>
25  */

26 public class LocalVariable extends QueryTreeNode
27 {
28     /** The name of the variable */
29     private String JavaDoc _name;
30     /** The type of the variable */
31     private Type _type;
32     /** Whether this variable is already bound to a value */
33     private boolean _isBound = false;
34     /** The value of the variable */
35     private Object JavaDoc _value;
36
37     /**
38      * Creates a new variable object.
39      *
40      * @param type The type of the variable
41      * @param name The name of the variable
42      */

43     public LocalVariable(Type type, String JavaDoc name)
44     {
45         _type = type;
46         _name = name;
47     }
48     
49     /**
50      * Returns the type of the variable.
51      *
52      * @return The type
53      */

54     public Type getType()
55     {
56         return _type;
57     }
58
59     /**
60      * Returns the value of this variable
61      *
62      * @return The value
63      */

64     public Object JavaDoc getValue()
65     {
66         return _value;
67     }
68
69     /**
70      * Sets the value of the variable.
71      *
72      * @param value The value
73      */

74     public void setValue(Object JavaDoc value)
75     {
76         _value = value;
77         _isBound = true;
78     }
79
80     /**
81      * Returns whether this variable is bound to a value.
82      *
83      * @return <code>true</code> if the variable has a value
84      */

85     public boolean isBound()
86     {
87         return _isBound;
88     }
89
90     /**
91      * Returns the name of the variable.
92      *
93      * @return The name
94      */

95     public String JavaDoc getName()
96     {
97         return _name;
98     }
99
100     /* (non-Javadoc)
101      * @see org.apache.ojb.jdo.jdoql.Acceptor#accept(org.apache.ojb.jdo.jdoql.Visitor)
102      */

103     public void accept(Visitor visitor)
104     {
105         visitor.visit(this);
106     }
107
108     /* (non-Javadoc)
109      * @see java.lang.Object#toString()
110      */

111     public String JavaDoc toString()
112     {
113         return _type.toString() + " " + _name;
114     }
115 }
116
Popular Tags