KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > parsing > BetweenNode


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.parsing;
23
24 import oracle.toplink.essentials.expressions.*;
25
26 /**
27  * INTERNAL
28  * <p><b>Purpose</b>: Represent a BETWEEN in EJBQL
29  * <p><b>Responsibilities</b>:<ul>
30  * <li> Generate the correct expression for a BETWEEN in EJBQL
31  * </ul>
32  * @author Jon Driscoll and Joel Lucuik
33  * @since TopLink 4.0
34  */

35 public class BetweenNode extends SimpleConditionalExpressionNode {
36     protected Node rightForBetween;
37     protected Node rightForAnd;
38
39     /**
40      * BetweenNode constructor comment.
41      */

42     public BetweenNode() {
43         super();
44     }
45
46     /**
47      * INTERNAL
48      * Validate node and calcualte its type.
49      */

50     public void validate(ParseTreeContext context) {
51         Object JavaDoc type = null;
52         if (left != null) {
53             left.validate(context);
54             type = left.getType();
55         }
56         if (rightForBetween != null) {
57             rightForBetween.validate(context);
58             rightForBetween.validateParameter(context, type);
59         }
60         if (rightForAnd != null) {
61             rightForAnd.validate(context);
62             rightForAnd.validateParameter(context, type);
63         }
64         TypeHelper typeHelper = context.getTypeHelper();
65         setType(typeHelper.getBooleanType());
66     }
67
68     /**
69      * INTERNAL
70      * Return a TopLink expression by 'BETWEEN' and 'AND'ing the expressions from the left,
71      * rightForBetween and rightForAnd nodes
72      */

73     public Expression generateExpression(GenerationContext context) {
74         // Get the left expression
75
Expression whereClause = getLeft().generateExpression(context);
76
77         // Between it with whatever the rightForBetween expression and rightForAnd expressions are
78
whereClause = whereClause.between(getRightForBetween().generateExpression(context), getRightForAnd().generateExpression(context));
79
80         // and return the expression...
81
return whereClause;
82     }
83
84     public Node getRightForAnd() {
85         return rightForAnd;
86     }
87
88     public Node getRightForBetween() {
89         return rightForBetween;
90     }
91
92     public boolean hasRightForAnd() {
93         return rightForAnd != null;
94     }
95
96     public boolean hasRightForBetween() {
97         return rightForBetween != null;
98     }
99
100     public void setRightForAnd(Node newRightForAnd) {
101         rightForAnd = newRightForAnd;
102     }
103
104     public void setRightForBetween(Node newRightForBetween) {
105         rightForBetween = newRightForBetween;
106     }
107 }
108
Popular Tags