KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > expressions > LiteralExpression


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.expressions;
23
24 import java.io.*;
25 import java.util.*;
26 import oracle.toplink.essentials.queryframework.*;
27 import oracle.toplink.essentials.expressions.*;
28 import oracle.toplink.essentials.internal.sessions.AbstractRecord;
29 import oracle.toplink.essentials.internal.sessions.AbstractSession;
30
31 /**
32  * Used for wrapping literal values.
33  */

34 public class LiteralExpression extends Expression {
35     protected String JavaDoc value;
36     protected Expression localBase;
37
38     public LiteralExpression() {
39         super();
40     }
41
42     public LiteralExpression(String JavaDoc newValue, Expression baseExpression) {
43         super();
44         value = newValue;
45         localBase = baseExpression;
46     }
47
48     /**
49      * INTERNAL:
50      * Used for debug printing.
51      */

52     public String JavaDoc descriptionOfNodeType() {
53         return "Literal";
54     }
55
56     /**
57      * Return the expression builder which is the ultimate base of this expression, or
58      * null if there isn't one (shouldn't happen if we start from a root)
59      */

60     public ExpressionBuilder getBuilder() {
61         return getLocalBase().getBuilder();
62     }
63
64     protected Expression getLocalBase() {
65         return localBase;
66     }
67
68     public String JavaDoc getValue() {
69         return value;
70     }
71
72     public boolean isLiteralExpression() {
73         return true;
74     }
75
76     /**
77      * INTERNAL:
78      * Used for cloning.
79      */

80     protected void postCopyIn(Dictionary alreadyDone) {
81         super.postCopyIn(alreadyDone);
82         localBase = localBase.copiedVersionFrom(alreadyDone);
83     }
84
85     /**
86      * INTERNAL:
87      * Print SQL onto the stream, using the ExpressionPrinter for context
88      */

89     public void printSQL(ExpressionSQLPrinter printer) {
90         printer.printString(value);
91     }
92
93     /**
94      * INTERNAL:
95      * Print SQL, this is called from functions, so must not be converted through the mapping.
96      */

97     public void printSQLWithoutConversion(ExpressionSQLPrinter printer) {
98         printSQL(printer);
99     }
100
101     /**
102      * INTERNAL:
103      * This expression is built on a different base than the one we want. Rebuild it and
104      * return the root of the new tree
105      */

106     public Expression rebuildOn(Expression newBase) {
107         Expression result = (LiteralExpression)clone();
108         result.setLocalBase(getLocalBase().rebuildOn(newBase));
109         return result;
110     }
111
112     public void setLocalBase(Expression e) {
113         localBase = e;
114     }
115
116     /**
117      * INTERNAL:
118      * Rebuild myself against the base, with the values of parameters supplied by the context
119      * expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping)
120      * into part of some larger expression. You normally would not call this directly, instead calling twist
121      * See the comment there for more details"
122      */

123     public Expression twistedForBaseAndContext(Expression newBase, Expression context) {
124         return (Expression)this.clone();
125     }
126
127     /**
128      * INTERNAL:
129      * Return the value for in memory comparison.
130      * This is only valid for valueable expressions.
131      */

132     public Object JavaDoc valueFromObject(Object JavaDoc object, AbstractSession session, AbstractRecord translationRow, InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean isObjectUnregistered) {
133         return getLocalBase().getFieldValue(getValue());
134     }
135
136     /**
137      * INTERNAL:
138      * Used to print a debug form of the expression tree.
139      */

140     public void writeDescriptionOn(BufferedWriter writer) throws IOException {
141         writer.write(getValue().toString());
142     }
143 }
144
Popular Tags