KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > el > parser > AstIdentifier


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  *
21  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
22  */
/* Generated By:JJTree: Do not edit this line. AstIdentifier.java */
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 /**
36  * @author Jacob Hookom [jacob@hookom.net]
37  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: kchung $
38  */

39 public final class AstIdentifier extends SimpleNode {
40     public AstIdentifier(int id) {
41         super(id);
42     }
43
44     public Class JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc invokeTarget(EvaluationContext ctx, Object JavaDoc target,
95             Object JavaDoc[] 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 JavaDoc invoke(EvaluationContext ctx, Class JavaDoc[] paramTypes,
112             Object JavaDoc[] paramValues) throws ELException {
113         return this.getMethodExpression(ctx).invoke(ctx.getELContext(), paramValues);
114     }
115     
116
117     public MethodInfo getMethodInfo(EvaluationContext ctx, Class JavaDoc[] 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 JavaDoc obj = null;
125
126         // case A: ValueExpression exists, getValue which must
127
// be a MethodExpression
128
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         // case B: evaluate the identity against the ELResolver, again, must be
138
// a MethodExpression to be able to invoke
139
if (ve == null) {
140             ctx.setPropertyResolved(false);
141             obj = ctx.getELResolver().getValue(ctx, null, this.image);
142         }
143
144         // finally provide helpful hints
145
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