KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > el > parser > AstIdentifier


1 /* Generated By:JJTree: Do not edit this line. AstIdentifier.java */
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 /**
16  * @author Jacob Hookom [jacob@hookom.net]
17  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: markt $
18  */

19 public final class AstIdentifier extends SimpleNode {
20     public AstIdentifier(int id) {
21         super(id);
22     }
23
24     public Class JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc invokeTarget(EvaluationContext ctx, Object JavaDoc target,
75             Object JavaDoc[] 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 JavaDoc invoke(EvaluationContext ctx, Class JavaDoc[] paramTypes,
92             Object JavaDoc[] paramValues) throws ELException {
93         return this.getMethodExpression(ctx).invoke(ctx.getELContext(), paramValues);
94     }
95     
96
97     public MethodInfo getMethodInfo(EvaluationContext ctx, Class JavaDoc[] 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 JavaDoc obj = null;
105
106         // case A: ValueExpression exists, getValue which must
107
// be a MethodExpression
108
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         // case B: evaluate the identity against the ELResolver, again, must be
118
// a MethodExpression to be able to invoke
119
if (ve == null) {
120             ctx.setPropertyResolved(false);
121             obj = ctx.getELResolver().getValue(ctx, null, this.image);
122         }
123
124         // finally provide helpful hints
125
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