1 23 24 package com.sun.el.parser; 25 26 import javax.el.ELException; 27 import javax.el.MethodExpression; 28 import javax.el.MethodInfo; 29 import javax.el.MethodNotFoundException; 30 import javax.el.ValueExpression; 31 import javax.el.VariableMapper; 32 33 import com.sun.el.lang.EvaluationContext; 34 35 39 public final class AstIdentifier extends SimpleNode { 40 public AstIdentifier(int id) { 41 super(id); 42 } 43 44 public Class getType(EvaluationContext ctx) throws ELException { 45 VariableMapper varMapper = ctx.getVariableMapper(); 46 if (varMapper != null) { 47 ValueExpression expr = varMapper.resolveVariable(this.image); 48 if (expr != null) { 49 return expr.getType(ctx.getELContext()); 50 } 51 } 52 ctx.setPropertyResolved(false); 53 return ctx.getELResolver().getType(ctx, null, this.image); 54 } 55 56 public Object getValue(EvaluationContext ctx) throws ELException { 57 VariableMapper varMapper = ctx.getVariableMapper(); 58 if (varMapper != null) { 59 ValueExpression expr = varMapper.resolveVariable(this.image); 60 if (expr != null) { 61 return expr.getValue(ctx.getELContext()); 62 } 63 } 64 ctx.setPropertyResolved(false); 65 return ctx.getELResolver().getValue(ctx, null, this.image); 66 } 67 68 public boolean isReadOnly(EvaluationContext ctx) throws ELException { 69 VariableMapper varMapper = ctx.getVariableMapper(); 70 if (varMapper != null) { 71 ValueExpression expr = varMapper.resolveVariable(this.image); 72 if (expr != null) { 73 return expr.isReadOnly(ctx.getELContext()); 74 } 75 } 76 ctx.setPropertyResolved(false); 77 return ctx.getELResolver().isReadOnly(ctx, null, this.image); 78 } 79 80 public void setValue(EvaluationContext ctx, Object value) 81 throws ELException { 82 VariableMapper varMapper = ctx.getVariableMapper(); 83 if (varMapper != null) { 84 ValueExpression expr = varMapper.resolveVariable(this.image); 85 if (expr != null) { 86 expr.setValue(ctx.getELContext(), value); 87 return; 88 } 89 } 90 ctx.setPropertyResolved(false); 91 ctx.getELResolver().setValue(ctx, null, this.image, value); 92 } 93 94 private final Object invokeTarget(EvaluationContext ctx, Object target, 95 Object [] paramValues) throws ELException { 96 if (target instanceof MethodExpression) { 97 MethodExpression me = (MethodExpression) target; 98 return me.invoke(ctx.getELContext(), paramValues); 99 } else if (target == null) { 100 throw new MethodNotFoundException("Identity '" + this.image 101 + "' was null and was unable to invoke"); 102 } else { 103 throw new ELException( 104 "Identity '" 105 + this.image 106 + "' does not reference a MethodExpression instance, returned type: " 107 + target.getClass().getName()); 108 } 109 } 110 111 public Object invoke(EvaluationContext ctx, Class [] paramTypes, 112 Object [] paramValues) throws ELException { 113 return this.getMethodExpression(ctx).invoke(ctx.getELContext(), paramValues); 114 } 115 116 117 public MethodInfo getMethodInfo(EvaluationContext ctx, Class [] paramTypes) 118 throws ELException { 119 return this.getMethodExpression(ctx).getMethodInfo(ctx.getELContext()); 120 } 121 122 private final MethodExpression getMethodExpression(EvaluationContext ctx) 123 throws ELException { 124 Object obj = null; 125 126 VariableMapper varMapper = ctx.getVariableMapper(); 129 ValueExpression ve = null; 130 if (varMapper != null) { 131 ve = varMapper.resolveVariable(this.image); 132 if (ve != null) { 133 obj = ve.getValue(ctx); 134 } 135 } 136 137 if (ve == null) { 140 ctx.setPropertyResolved(false); 141 obj = ctx.getELResolver().getValue(ctx, null, this.image); 142 } 143 144 if (obj instanceof MethodExpression) { 146 return (MethodExpression) obj; 147 } else if (obj == null) { 148 throw new MethodNotFoundException("Identity '" + this.image 149 + "' was null and was unable to invoke"); 150 } else { 151 throw new ELException( 152 "Identity '" 153 + this.image 154 + "' does not reference a MethodExpression instance, returned type: " 155 + obj.getClass().getName()); 156 } 157 } 158 } 159 | Popular Tags |