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