KickJava   Java API By Example, From Geeks To Geeks.

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


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

35 public class SubstringNode extends StringFunctionNode {
36     private Node startPosition = null;
37     private Node stringLength = null;
38
39     /**
40      * SubstringNode constructor comment.
41      */

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

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

67     public Expression generateExpression(GenerationContext context) {
68         Expression whereClause = getLeft().generateExpression(context);
69         Expression startPosition = getStartPosition().generateExpression(context);
70         Expression stringLength = getStringLength().generateExpression(context);
71         whereClause = whereClause.substring(startPosition, stringLength);
72         return whereClause;
73     }
74
75     /**
76      * Return the start position object
77      */

78     private Node getStartPosition() {
79         return startPosition;
80     }
81
82     /**
83      * Return the string length object
84      */

85     private Node getStringLength() {
86         return stringLength;
87     }
88
89     /**
90      * Insert the method's description here.
91      * Creation date: (1/19/01 3:41:55 PM)
92      * @param newStartPosition java.lang.Integer
93      */

94     public void setStartPosition(Node newStartPosition) {
95         startPosition = newStartPosition;
96     }
97
98     /**
99      * Insert the method's description here.
100      * Creation date: (1/19/01 3:42:26 PM)
101      * @param newStringLength java.lang.Integer
102      */

103     public void setStringLength(Node newStringLength) {
104         stringLength = newStringLength;
105     }
106 }
107
Popular Tags