KickJava   Java API By Example, From Geeks To Geeks.

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


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.queryframework.ObjectLevelReadQuery;
25 import oracle.toplink.essentials.queryframework.ReportQuery;
26
27 import oracle.toplink.essentials.expressions.*;
28 import oracle.toplink.essentials.internal.expressions.*;
29
30 /**
31  * INTERNAL
32  * <p><b>Purpose</b>: Superclass for literals (String, Integer, Float, Character, ...)
33  * <p><b>Responsibilities</b>:<ul>
34  * <li> Maintain the literal being represented
35  * <li> Print to a string
36  * <li> Answer if the node is completely built
37  * </ul>
38  * @author Jon Driscoll and Joel Lucuik
39  * @since TopLink 4.0
40  */

41 public class LiteralNode extends Node {
42     public java.lang.Object JavaDoc literal;
43
44     /**
45      * Return a new LiteralNode.
46      */

47     public LiteralNode() {
48         super();
49     }
50
51     /**
52      * INTERNAL
53      * Apply this node to the passed query
54      */

55     public void applyToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) {
56         if (theQuery.isReportQuery()) {
57             ReportQuery reportQuery = (ReportQuery)theQuery;
58             reportQuery.addAttribute("CONSTANT", generateExpression(context));
59         }
60         
61     }
62
63     /**
64      * INTERNAL
65      * Generate the a new TopLink ConstantExpression for this node.
66      */

67     public Expression generateExpression(GenerationContext context) {
68         Expression whereClause = new ConstantExpression(getLiteral(), new ExpressionBuilder());
69         return whereClause;
70     }
71
72     /**
73      * INTERNAL
74      * Return the literal
75      */

76     public String JavaDoc getAsString() {
77         return getLiteral().toString();
78     }
79
80     /**
81      * Insert the method's description here.
82      * Creation date: (12/21/00 10:51:48 AM)
83      * @return java.lang.Object
84      */

85     public java.lang.Object JavaDoc getLiteral() {
86         return literal;
87     }
88
89     /**
90      * INTERNAL
91      * Is this a literal node
92      */

93     public boolean isLiteralNode() {
94         return true;
95     }
96
97     /**
98      * Insert the method's description here.
99      * Creation date: (12/21/00 10:51:48 AM)
100      * @param newLiteral java.lang.Object
101      */

102     public void setLiteral(java.lang.Object JavaDoc newLiteral) {
103         literal = newLiteral;
104     }
105
106     public String JavaDoc toString(int indent) {
107         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
108         toStringIndent(indent, buffer);
109         buffer.append(toStringDisplayName() + "[" + getLiteral() + "]");
110         return buffer.toString();
111     }
112 }
113
Popular Tags