KickJava   Java API By Example, From Geeks To Geeks.

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


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

35 public class LikeNode extends SimpleConditionalExpressionNode {
36     private EscapeNode escape = null;
37
38     /**
39      * LikeNode constructor comment.
40      */

41     public LikeNode() {
42         super();
43     }
44
45     /**
46      * INTERNAL
47      * Validate the current node and calculates its type.
48      */

49     public void validate(ParseTreeContext context) {
50         TypeHelper typeHelper = context.getTypeHelper();
51         if (left != null) {
52             left.validate(context);
53             left.validateParameter(context, typeHelper.getStringType());
54         }
55         if (right != null) {
56             right.validate(context);
57             right.validateParameter(context, typeHelper.getStringType());
58         }
59         
60         if (escape != null) {
61             escape.validate(context);
62         }
63         
64         setType(typeHelper.getBooleanType());
65     }
66
67     /**
68      * INTERNAL
69      * Return a TopLink expression for this node.
70      */

71     public Expression generateExpression(GenerationContext context) {
72         Expression whereClause = getLeft().generateExpression(context);
73         if (!hasEscape()) {
74             whereClause = whereClause.like(getRight().generateExpression(context));
75         } else {
76             whereClause = whereClause.like(getRight().generateExpression(context), getEscapeNode().generateExpression(context));
77         }
78         return whereClause;
79     }
80
81     public boolean hasEscape() {
82         return getEscapeNode() != null;
83     }
84
85     // Accessors
86
public EscapeNode getEscapeNode() {
87         return escape;
88     }
89
90     public void setEscapeNode(EscapeNode node) {
91         escape = node;
92     }
93 }
94
Popular Tags