001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.internal.parsing;
038:
039: import oracle.toplink.essentials.queryframework.ObjectLevelReadQuery;
040: import oracle.toplink.essentials.queryframework.ReportQuery;
041:
042: import oracle.toplink.essentials.expressions.*;
043: import oracle.toplink.essentials.internal.expressions.*;
044:
045: /**
046: * INTERNAL
047: * <p><b>Purpose</b>: Superclass for literals (String, Integer, Float, Character, ...)
048: * <p><b>Responsibilities</b>:<ul>
049: * <li> Maintain the literal being represented
050: * <li> Print to a string
051: * <li> Answer if the node is completely built
052: * </ul>
053: * @author Jon Driscoll and Joel Lucuik
054: * @since TopLink 4.0
055: */
056: public class LiteralNode extends Node {
057: public java.lang.Object literal;
058:
059: /**
060: * Return a new LiteralNode.
061: */
062: public LiteralNode() {
063: super ();
064: }
065:
066: /**
067: * INTERNAL
068: * Apply this node to the passed query
069: */
070: public void applyToQuery(ObjectLevelReadQuery theQuery,
071: GenerationContext context) {
072: if (theQuery.isReportQuery()) {
073: ReportQuery reportQuery = (ReportQuery) theQuery;
074: reportQuery.addAttribute("CONSTANT",
075: generateExpression(context));
076: }
077:
078: }
079:
080: /**
081: * INTERNAL
082: * Generate the a new TopLink ConstantExpression for this node.
083: */
084: public Expression generateExpression(GenerationContext context) {
085: Expression whereClause = new ConstantExpression(getLiteral(),
086: new ExpressionBuilder());
087: return whereClause;
088: }
089:
090: /**
091: * INTERNAL
092: * Return the literal
093: */
094: public String getAsString() {
095: return getLiteral().toString();
096: }
097:
098: /**
099: * Insert the method's description here.
100: * Creation date: (12/21/00 10:51:48 AM)
101: * @return java.lang.Object
102: */
103: public java.lang.Object getLiteral() {
104: return literal;
105: }
106:
107: /**
108: * INTERNAL
109: * Is this a literal node
110: */
111: public boolean isLiteralNode() {
112: return true;
113: }
114:
115: /**
116: * Insert the method's description here.
117: * Creation date: (12/21/00 10:51:48 AM)
118: * @param newLiteral java.lang.Object
119: */
120: public void setLiteral(java.lang.Object newLiteral) {
121: literal = newLiteral;
122: }
123:
124: public String toString(int indent) {
125: StringBuffer buffer = new StringBuffer();
126: toStringIndent(indent, buffer);
127: buffer.append(toStringDisplayName() + "[" + getLiteral() + "]");
128: return buffer.toString();
129: }
130: }
|