1 23 24 package com.sun.el.parser; 25 26 import java.lang.reflect.InvocationTargetException ; 27 import java.lang.reflect.Method ; 28 29 import javax.el.ELException; 30 import javax.el.FunctionMapper; 31 32 import com.sun.el.lang.EvaluationContext; 33 import com.sun.el.util.MessageFactory; 34 35 39 public final class AstFunction extends SimpleNode { 40 41 protected String localName = ""; 42 43 protected String prefix = ""; 44 45 public AstFunction(int id) { 46 super(id); 47 } 48 49 public String getLocalName() { 50 return localName; 51 } 52 53 public String getOutputName() { 54 if (this.prefix == null) { 55 return this.localName; 56 } else { 57 return this.prefix + ":" + this.localName; 58 } 59 } 60 61 public String getPrefix() { 62 return prefix; 63 } 64 65 public Class getType(EvaluationContext ctx) 66 throws ELException { 67 68 FunctionMapper fnMapper = ctx.getFunctionMapper(); 69 70 if (fnMapper == null) { 72 throw new ELException(MessageFactory.get("error.fnMapper.null")); 73 } 74 Method m = fnMapper.resolveFunction(this.prefix, this.localName); 75 if (m == null) { 76 throw new ELException(MessageFactory.get("error.fnMapper.method", 77 this.getOutputName())); 78 } 79 return m.getReturnType(); 80 } 81 82 public Object getValue(EvaluationContext ctx) 83 throws ELException { 84 85 FunctionMapper fnMapper = ctx.getFunctionMapper(); 86 87 if (fnMapper == null) { 89 throw new ELException(MessageFactory.get("error.fnMapper.null")); 90 } 91 Method m = fnMapper.resolveFunction(this.prefix, this.localName); 92 if (m == null) { 93 throw new ELException(MessageFactory.get("error.fnMapper.method", 94 this.getOutputName())); 95 } 96 97 Class [] paramTypes = m.getParameterTypes(); 98 Object [] params = null; 99 Object result = null; 100 int numParams = this.jjtGetNumChildren(); 101 if (numParams > 0) { 102 params = new Object [numParams]; 103 try { 104 for (int i = 0; i < numParams; i++) { 105 params[i] = this.children[i].getValue(ctx); 106 params[i] = coerceToType(params[i], paramTypes[i]); 107 } 108 } catch (ELException ele) { 109 throw new ELException(MessageFactory.get("error.function", this 110 .getOutputName()), ele); 111 } 112 } 113 try { 114 result = m.invoke(null, params); 115 } catch (IllegalAccessException iae) { 116 throw new ELException(MessageFactory.get("error.function", this 117 .getOutputName()), iae); 118 } catch (InvocationTargetException ite) { 119 throw new ELException(MessageFactory.get("error.function", this 120 .getOutputName()), ite.getCause()); 121 } 122 return result; 123 } 124 125 public void setLocalName(String localName) { 126 this.localName = localName; 127 } 128 129 public void setPrefix(String prefix) { 130 this.prefix = prefix; 131 } 132 133 134 public String toString() 135 { 136 return ELParserTreeConstants.jjtNodeName[id] + "[" + this.getOutputName() + "]"; 137 } 138 } 139 | Popular Tags |