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.ASTNode;
021: import org.mvel.ast.Safe;
022: import org.mvel.integration.VariableResolverFactory;
023: import static org.mvel.util.ParseTools.handleParserEgress;
024:
025: public class ExecutableAccessorSafe implements ExecutableStatement,
026: Safe {
027: private ASTNode node;
028:
029: private Class ingress;
030: private Class egress;
031: private boolean convertable;
032:
033: private boolean returnBigDecimal;
034:
035: public ExecutableAccessorSafe(ASTNode node, boolean returnBigDecimal) {
036: this .node = node;
037: this .returnBigDecimal = returnBigDecimal;
038: }
039:
040: public ExecutableAccessorSafe(ASTNode node,
041: boolean returnBigDecimal, Class returnType) {
042: this .node = node;
043: this .returnBigDecimal = returnBigDecimal;
044: this .egress = returnType;
045: }
046:
047: public Object getValue(Object ctx, Object elCtx,
048: VariableResolverFactory variableFactory) {
049: return handleParserEgress(node.getReducedValueAccelerated(ctx,
050: elCtx, variableFactory), returnBigDecimal);
051: }
052:
053: public Object getValue(Object staticContext,
054: VariableResolverFactory factory) {
055: return handleParserEgress(node.getReducedValueAccelerated(
056: staticContext, staticContext, factory),
057: returnBigDecimal);
058:
059: }
060:
061: public void setKnownIngressType(Class type) {
062: this .ingress = type;
063: }
064:
065: public void setKnownEgressType(Class type) {
066: this .egress = type;
067: }
068:
069: public Class getKnownIngressType() {
070: return ingress;
071: }
072:
073: public Class getKnownEgressType() {
074: return egress;
075: }
076:
077: public boolean isConvertableIngressEgress() {
078: return convertable;
079: }
080:
081: public void computeTypeConversionRule() {
082: if (ingress != null && egress != null) {
083: convertable = ingress.isAssignableFrom(egress);
084: }
085: }
086:
087: public boolean intOptimized() {
088: return false;
089: }
090:
091: public ASTNode getNode() {
092: return node;
093: }
094:
095: public Object setValue(Object ctx, Object elCtx,
096: VariableResolverFactory variableFactory, Object value) {
097: return null;
098: }
099:
100: public boolean isLiteralOnly() {
101: return false;
102: }
103: }
|