KickJava   Java API By Example, From Geeks To Geeks.

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


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, 2006, 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 LOCATE
29  * <p><b>Responsibilities</b>:<ul>
30  * <li> Generate the correct expression for a LOCATE
31  * </ul>
32  * @author Jon Driscoll and Joel Lucuik
33  * @since TopLink 4.0
34  */

35 public class LocateNode extends ArithmeticFunctionNode {
36     private Node find = null;
37     private Node findIn = null;
38     private Node startPosition = null;
39
40     /**
41      * Return a new LocateNode.
42      */

43     public LocateNode() {
44         super();
45     }
46
47     /**
48      * INTERNAL
49      * Validate node and calculate its type.
50      */

51     public void validate(ParseTreeContext context) {
52         TypeHelper typeHelper = context.getTypeHelper();
53         if (findIn != null) {
54             findIn.validate(context);
55             findIn.validateParameter(context, typeHelper.getStringType());
56         }
57         if (find != null) {
58             find.validate(context);
59             find.validateParameter(context, typeHelper.getStringType());
60         }
61         if (startPosition != null) {
62             startPosition.validate(context);
63             startPosition.validateParameter(context, typeHelper.getIntType());
64         }
65         setType(typeHelper.getIntType());
66     }
67
68     /**
69      * INTERNAL
70      * Generate the TopLink expression for this node
71      */

72     public Expression generateExpression(GenerationContext context) {
73         Expression whereClause = getFindIn().generateExpression(context);
74         Expression findExpr = getFind().generateExpression(context);
75         if (startPosition != null) {
76             whereClause = whereClause.locate(findExpr, getStartPosition().generateExpression(context));
77         } else {
78             whereClause = whereClause.locate(findExpr);
79         }
80         return whereClause;
81     }
82
83     // Accessors
84
public Node getFind() {
85         return find;
86     }
87
88     public Node getFindIn() {
89         return findIn;
90     }
91
92     public void setFind(Node newFind) {
93         find = newFind;
94     }
95
96     public void setFindIn(Node newFindIn) {
97         findIn = newFindIn;
98     }
99
100     public Node getStartPosition() {
101         return startPosition;
102     }
103     
104     public void setStartPosition(Node newStartPosition) {
105         startPosition = newStartPosition;
106     }
107     
108 }
109
Popular Tags