001: /* Generated By:JJTree: Do not edit this line. AstIdentifier.java */
002:
003: package org.apache.el.parser;
004:
005: import javax.el.ELException;
006: import javax.el.MethodExpression;
007: import javax.el.MethodInfo;
008: import javax.el.MethodNotFoundException;
009: import javax.el.ValueExpression;
010: import javax.el.VariableMapper;
011:
012: import org.apache.el.lang.EvaluationContext;
013:
014: /**
015: * @author Jacob Hookom [jacob@hookom.net]
016: * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: markt $
017: */
018: public final class AstIdentifier extends SimpleNode {
019: public AstIdentifier(int id) {
020: super (id);
021: }
022:
023: public Class getType(EvaluationContext ctx) throws ELException {
024: VariableMapper varMapper = ctx.getVariableMapper();
025: if (varMapper != null) {
026: ValueExpression expr = varMapper
027: .resolveVariable(this .image);
028: if (expr != null) {
029: return expr.getType(ctx.getELContext());
030: }
031: }
032: ctx.setPropertyResolved(false);
033: return ctx.getELResolver().getType(ctx, null, this .image);
034: }
035:
036: public Object getValue(EvaluationContext ctx) throws ELException {
037: VariableMapper varMapper = ctx.getVariableMapper();
038: if (varMapper != null) {
039: ValueExpression expr = varMapper
040: .resolveVariable(this .image);
041: if (expr != null) {
042: return expr.getValue(ctx.getELContext());
043: }
044: }
045: ctx.setPropertyResolved(false);
046: return ctx.getELResolver().getValue(ctx, null, this .image);
047: }
048:
049: public boolean isReadOnly(EvaluationContext ctx) throws ELException {
050: VariableMapper varMapper = ctx.getVariableMapper();
051: if (varMapper != null) {
052: ValueExpression expr = varMapper
053: .resolveVariable(this .image);
054: if (expr != null) {
055: return expr.isReadOnly(ctx.getELContext());
056: }
057: }
058: ctx.setPropertyResolved(false);
059: return ctx.getELResolver().isReadOnly(ctx, null, this .image);
060: }
061:
062: public void setValue(EvaluationContext ctx, Object value)
063: throws ELException {
064: VariableMapper varMapper = ctx.getVariableMapper();
065: if (varMapper != null) {
066: ValueExpression expr = varMapper
067: .resolveVariable(this .image);
068: if (expr != null) {
069: expr.setValue(ctx.getELContext(), value);
070: return;
071: }
072: }
073: ctx.setPropertyResolved(false);
074: ctx.getELResolver().setValue(ctx, null, this .image, value);
075: }
076:
077: private final Object invokeTarget(EvaluationContext ctx,
078: Object target, Object[] paramValues) throws ELException {
079: if (target instanceof MethodExpression) {
080: MethodExpression me = (MethodExpression) target;
081: return me.invoke(ctx.getELContext(), paramValues);
082: } else if (target == null) {
083: throw new MethodNotFoundException("Identity '" + this .image
084: + "' was null and was unable to invoke");
085: } else {
086: throw new ELException(
087: "Identity '"
088: + this .image
089: + "' does not reference a MethodExpression instance, returned type: "
090: + target.getClass().getName());
091: }
092: }
093:
094: public Object invoke(EvaluationContext ctx, Class[] paramTypes,
095: Object[] paramValues) throws ELException {
096: return this .getMethodExpression(ctx).invoke(ctx.getELContext(),
097: paramValues);
098: }
099:
100: public MethodInfo getMethodInfo(EvaluationContext ctx,
101: Class[] paramTypes) throws ELException {
102: return this .getMethodExpression(ctx).getMethodInfo(
103: ctx.getELContext());
104: }
105:
106: private final MethodExpression getMethodExpression(
107: EvaluationContext ctx) throws ELException {
108: Object obj = null;
109:
110: // case A: ValueExpression exists, getValue which must
111: // be a MethodExpression
112: VariableMapper varMapper = ctx.getVariableMapper();
113: ValueExpression ve = null;
114: if (varMapper != null) {
115: ve = varMapper.resolveVariable(this .image);
116: if (ve != null) {
117: obj = ve.getValue(ctx);
118: }
119: }
120:
121: // case B: evaluate the identity against the ELResolver, again, must be
122: // a MethodExpression to be able to invoke
123: if (ve == null) {
124: ctx.setPropertyResolved(false);
125: obj = ctx.getELResolver().getValue(ctx, null, this .image);
126: }
127:
128: // finally provide helpful hints
129: if (obj instanceof MethodExpression) {
130: return (MethodExpression) obj;
131: } else if (obj == null) {
132: throw new MethodNotFoundException("Identity '" + this .image
133: + "' was null and was unable to invoke");
134: } else {
135: throw new ELException(
136: "Identity '"
137: + this .image
138: + "' does not reference a MethodExpression instance, returned type: "
139: + obj.getClass().getName());
140: }
141: }
142: }
|