1 2 3 package org.apache.el.parser; 4 5 import javax.el.ELException; 6 import javax.el.MethodExpression; 7 import javax.el.MethodInfo; 8 import javax.el.MethodNotFoundException; 9 import javax.el.ValueExpression; 10 import javax.el.VariableMapper; 11 12 import org.apache.el.lang.EvaluationContext; 13 14 15 19 public final class AstIdentifier extends SimpleNode { 20 public AstIdentifier(int id) { 21 super(id); 22 } 23 24 public Class getType(EvaluationContext ctx) throws ELException { 25 VariableMapper varMapper = ctx.getVariableMapper(); 26 if (varMapper != null) { 27 ValueExpression expr = varMapper.resolveVariable(this.image); 28 if (expr != null) { 29 return expr.getType(ctx.getELContext()); 30 } 31 } 32 ctx.setPropertyResolved(false); 33 return ctx.getELResolver().getType(ctx, null, this.image); 34 } 35 36 public Object getValue(EvaluationContext ctx) throws ELException { 37 VariableMapper varMapper = ctx.getVariableMapper(); 38 if (varMapper != null) { 39 ValueExpression expr = varMapper.resolveVariable(this.image); 40 if (expr != null) { 41 return expr.getValue(ctx.getELContext()); 42 } 43 } 44 ctx.setPropertyResolved(false); 45 return ctx.getELResolver().getValue(ctx, null, this.image); 46 } 47 48 public boolean isReadOnly(EvaluationContext ctx) throws ELException { 49 VariableMapper varMapper = ctx.getVariableMapper(); 50 if (varMapper != null) { 51 ValueExpression expr = varMapper.resolveVariable(this.image); 52 if (expr != null) { 53 return expr.isReadOnly(ctx.getELContext()); 54 } 55 } 56 ctx.setPropertyResolved(false); 57 return ctx.getELResolver().isReadOnly(ctx, null, this.image); 58 } 59 60 public void setValue(EvaluationContext ctx, Object value) 61 throws ELException { 62 VariableMapper varMapper = ctx.getVariableMapper(); 63 if (varMapper != null) { 64 ValueExpression expr = varMapper.resolveVariable(this.image); 65 if (expr != null) { 66 expr.setValue(ctx.getELContext(), value); 67 return; 68 } 69 } 70 ctx.setPropertyResolved(false); 71 ctx.getELResolver().setValue(ctx, null, this.image, value); 72 } 73 74 private final Object invokeTarget(EvaluationContext ctx, Object target, 75 Object [] paramValues) throws ELException { 76 if (target instanceof MethodExpression) { 77 MethodExpression me = (MethodExpression) target; 78 return me.invoke(ctx.getELContext(), paramValues); 79 } else if (target == null) { 80 throw new MethodNotFoundException("Identity '" + this.image 81 + "' was null and was unable to invoke"); 82 } else { 83 throw new ELException( 84 "Identity '" 85 + this.image 86 + "' does not reference a MethodExpression instance, returned type: " 87 + target.getClass().getName()); 88 } 89 } 90 91 public Object invoke(EvaluationContext ctx, Class [] paramTypes, 92 Object [] paramValues) throws ELException { 93 return this.getMethodExpression(ctx).invoke(ctx.getELContext(), paramValues); 94 } 95 96 97 public MethodInfo getMethodInfo(EvaluationContext ctx, Class [] paramTypes) 98 throws ELException { 99 return this.getMethodExpression(ctx).getMethodInfo(ctx.getELContext()); 100 } 101 102 private final MethodExpression getMethodExpression(EvaluationContext ctx) 103 throws ELException { 104 Object obj = null; 105 106 VariableMapper varMapper = ctx.getVariableMapper(); 109 ValueExpression ve = null; 110 if (varMapper != null) { 111 ve = varMapper.resolveVariable(this.image); 112 if (ve != null) { 113 obj = ve.getValue(ctx); 114 } 115 } 116 117 if (ve == null) { 120 ctx.setPropertyResolved(false); 121 obj = ctx.getELResolver().getValue(ctx, null, this.image); 122 } 123 124 if (obj instanceof MethodExpression) { 126 return (MethodExpression) obj; 127 } else if (obj == null) { 128 throw new MethodNotFoundException("Identity '" + this.image 129 + "' was null and was unable to invoke"); 130 } else { 131 throw new ELException( 132 "Identity '" 133 + this.image 134 + "' does not reference a MethodExpression instance, returned type: " 135 + obj.getClass().getName()); 136 } 137 } 138 } 139 | Popular Tags |