KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Generated By:JJTree: Do not edit this line. AstFunction.java */
2
3 package org.apache.el.parser;
4
5 import java.lang.reflect.InvocationTargetException JavaDoc;
6 import java.lang.reflect.Method JavaDoc;
7
8 import javax.el.ELException;
9 import javax.el.FunctionMapper;
10
11 import org.apache.el.lang.EvaluationContext;
12 import org.apache.el.util.MessageFactory;
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 AstFunction extends SimpleNode {
20
21     protected String JavaDoc localName = "";
22
23     protected String JavaDoc prefix = "";
24
25     public AstFunction(int id) {
26         super(id);
27     }
28
29     public String JavaDoc getLocalName() {
30         return localName;
31     }
32
33     public String JavaDoc getOutputName() {
34         if (this.prefix == null) {
35             return this.localName;
36         } else {
37             return this.prefix + ":" + this.localName;
38         }
39     }
40
41     public String JavaDoc getPrefix() {
42         return prefix;
43     }
44
45     public Class JavaDoc getType(EvaluationContext ctx)
46             throws ELException {
47         
48         FunctionMapper fnMapper = ctx.getFunctionMapper();
49         
50         // quickly validate again for this request
51
if (fnMapper == null) {
52             throw new ELException(MessageFactory.get("error.fnMapper.null"));
53         }
54         Method JavaDoc m = fnMapper.resolveFunction(this.prefix, this.localName);
55         if (m == null) {
56             throw new ELException(MessageFactory.get("error.fnMapper.method",
57                     this.getOutputName()));
58         }
59         return m.getReturnType();
60     }
61
62     public Object JavaDoc getValue(EvaluationContext ctx)
63             throws ELException {
64         
65         FunctionMapper fnMapper = ctx.getFunctionMapper();
66         
67         // quickly validate again for this request
68
if (fnMapper == null) {
69             throw new ELException(MessageFactory.get("error.fnMapper.null"));
70         }
71         Method JavaDoc m = fnMapper.resolveFunction(this.prefix, this.localName);
72         if (m == null) {
73             throw new ELException(MessageFactory.get("error.fnMapper.method",
74                     this.getOutputName()));
75         }
76
77         Class JavaDoc[] paramTypes = m.getParameterTypes();
78         Object JavaDoc[] params = null;
79         Object JavaDoc result = null;
80         int numParams = this.jjtGetNumChildren();
81         if (numParams > 0) {
82             params = new Object JavaDoc[numParams];
83             try {
84                 for (int i = 0; i < numParams; i++) {
85                     params[i] = this.children[i].getValue(ctx);
86                     params[i] = coerceToType(params[i], paramTypes[i]);
87                 }
88             } catch (ELException ele) {
89                 throw new ELException(MessageFactory.get("error.function", this
90                         .getOutputName()), ele);
91             }
92         }
93         try {
94             result = m.invoke(null, params);
95         } catch (IllegalAccessException JavaDoc iae) {
96             throw new ELException(MessageFactory.get("error.function", this
97                     .getOutputName()), iae);
98         } catch (InvocationTargetException JavaDoc ite) {
99             throw new ELException(MessageFactory.get("error.function", this
100                     .getOutputName()), ite.getCause());
101         }
102         return result;
103     }
104
105     public void setLocalName(String JavaDoc localName) {
106         this.localName = localName;
107     }
108
109     public void setPrefix(String JavaDoc prefix) {
110         this.prefix = prefix;
111     }
112     
113     
114     public String JavaDoc toString()
115     {
116         return ELParserTreeConstants.jjtNodeName[id] + "[" + this.getOutputName() + "]";
117     }
118 }
119
Popular Tags