001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.internal.parsing;
038:
039: import oracle.toplink.essentials.expressions.*;
040:
041: /**
042: * INTERNAL
043: * <p><b>Purpose</b>: Represent a BETWEEN in EJBQL
044: * <p><b>Responsibilities</b>:<ul>
045: * <li> Generate the correct expression for a BETWEEN in EJBQL
046: * </ul>
047: * @author Jon Driscoll and Joel Lucuik
048: * @since TopLink 4.0
049: */
050: public class BetweenNode extends SimpleConditionalExpressionNode {
051: protected Node rightForBetween;
052: protected Node rightForAnd;
053:
054: /**
055: * BetweenNode constructor comment.
056: */
057: public BetweenNode() {
058: super ();
059: }
060:
061: /**
062: * INTERNAL
063: * Check the child nodes for an unqualified field access and if there are
064: * any, replace them by a qualified field access.
065: */
066: public Node qualifyAttributeAccess(ParseTreeContext context) {
067: if (left != null) {
068: left = left.qualifyAttributeAccess(context);
069: }
070: if (rightForBetween != null) {
071: rightForBetween = rightForBetween
072: .qualifyAttributeAccess(context);
073: }
074: if (rightForAnd != null) {
075: rightForAnd = rightForAnd.qualifyAttributeAccess(context);
076: }
077: return this ;
078: }
079:
080: /**
081: * INTERNAL
082: * Validate node and calcualte its type.
083: */
084: public void validate(ParseTreeContext context) {
085: Object type = null;
086: if (left != null) {
087: left.validate(context);
088: type = left.getType();
089: }
090: if (rightForBetween != null) {
091: rightForBetween.validate(context);
092: rightForBetween.validateParameter(context, type);
093: }
094: if (rightForAnd != null) {
095: rightForAnd.validate(context);
096: rightForAnd.validateParameter(context, type);
097: }
098: TypeHelper typeHelper = context.getTypeHelper();
099: setType(typeHelper.getBooleanType());
100: }
101:
102: /**
103: * INTERNAL
104: * Return a TopLink expression by 'BETWEEN' and 'AND'ing the expressions from the left,
105: * rightForBetween and rightForAnd nodes
106: */
107: public Expression generateExpression(GenerationContext context) {
108: // Get the left expression
109: Expression whereClause = getLeft().generateExpression(context);
110:
111: // Between it with whatever the rightForBetween expression and rightForAnd expressions are
112: whereClause = whereClause.between(getRightForBetween()
113: .generateExpression(context), getRightForAnd()
114: .generateExpression(context));
115:
116: // and return the expression...
117: return whereClause;
118: }
119:
120: public Node getRightForAnd() {
121: return rightForAnd;
122: }
123:
124: public Node getRightForBetween() {
125: return rightForBetween;
126: }
127:
128: public boolean hasRightForAnd() {
129: return rightForAnd != null;
130: }
131:
132: public boolean hasRightForBetween() {
133: return rightForBetween != null;
134: }
135:
136: public void setRightForAnd(Node newRightForAnd) {
137: rightForAnd = newRightForAnd;
138: }
139:
140: public void setRightForBetween(Node newRightForBetween) {
141: rightForBetween = newRightForBetween;
142: }
143: }
|