001: /**
002: * MVEL (The MVFLEX Expression Language)
003: *
004: * Copyright (C) 2007 Christopher Brock, MVFLEX/Valhalla Project and the Codehaus
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: */package org.mvel.compiler;
019:
020: import org.mvel.ast.Safe;
021: import org.mvel.integration.VariableResolverFactory;
022: import org.mvel.util.ParseTools;
023:
024: /**
025: * @author Christopher Brock
026: */
027: public class ExecutableLiteral implements ExecutableStatement, Safe {
028: private Object literal;
029: private int integer32;
030: private boolean intOptimized;
031:
032: public ExecutableLiteral(Object literal) {
033: this .literal = ParseTools.handleParserEgress(literal, false);
034: }
035:
036: public ExecutableLiteral(int literal) {
037: this .literal = this .integer32 = literal;
038: this .intOptimized = true;
039: }
040:
041: public int getInteger32() {
042: return integer32;
043: }
044:
045: public void setInteger32(int integer32) {
046: this .integer32 = integer32;
047: }
048:
049: public Object getValue(Object staticContext,
050: VariableResolverFactory factory) {
051: return literal;
052: }
053:
054: public void setKnownIngressType(Class type) {
055:
056: }
057:
058: public void setKnownEgressType(Class type) {
059:
060: }
061:
062: public Class getKnownIngressType() {
063: return null;
064: }
065:
066: public Class getKnownEgressType() {
067: return this .literal == null ? Object.class : this .literal
068: .getClass();
069: }
070:
071: public boolean isConvertableIngressEgress() {
072: return false;
073: }
074:
075: public void computeTypeConversionRule() {
076:
077: }
078:
079: public Object getValue(Object ctx, Object elCtx,
080: VariableResolverFactory variableFactory) {
081: return literal;
082: }
083:
084: public Object getLiteral() {
085: return literal;
086: }
087:
088: public boolean intOptimized() {
089: return intOptimized;
090: }
091:
092: public Object setValue(Object ctx, Object elCtx,
093: VariableResolverFactory variableFactory, Object value) {
094: // not implemented
095: return null;
096: }
097:
098: public boolean isLiteralOnly() {
099: return true;
100: }
101: }
|