1 28 29 package com.caucho.jsp.cfg; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.config.types.Signature; 33 import com.caucho.util.L10N; 34 35 import javax.annotation.PostConstruct; 36 import javax.servlet.jsp.tagext.FunctionInfo ; 37 import java.lang.reflect.Method ; 38 import java.lang.reflect.Modifier ; 39 40 43 public class TldFunction { 44 private static L10N L = new L10N(TldFunction.class); 45 46 private String _name; 47 private Class _functionClass; 48 private Signature _signature; 49 private String _displayName; 50 private String _description; 51 private String _example; 52 53 private Method _method; 54 55 58 public void setName(String name) 59 { 60 _name = name; 61 } 62 63 66 public String getName() 67 { 68 return _name; 69 } 70 71 74 public void setFunctionClass(Class functionClass) 75 { 76 _functionClass = functionClass; 77 } 78 79 82 public Class getFunctionClass() 83 { 84 return _functionClass; 85 } 86 87 90 public void setFunctionSignature(Signature signature) 91 { 92 _signature = signature; 93 } 94 95 98 public Signature getFunctionSignature() 99 { 100 return _signature; 101 } 102 103 106 public void setDisplayName(String displayName) 107 { 108 _displayName = displayName; 109 } 110 111 114 public String getDisplayName() 115 { 116 return _displayName; 117 } 118 119 122 public void setDescription(String description) 123 { 124 _description = description; 125 } 126 127 130 public String getDescription() 131 { 132 return _description; 133 } 134 135 138 public void setExample(String example) 139 { 140 _example = example; 141 } 142 143 146 public String getExample() 147 { 148 return _example; 149 } 150 151 154 public Method getMethod() 155 { 156 return _method; 157 } 158 159 162 @PostConstruct 163 public void init() 164 throws ConfigException 165 { 166 if (_name == null) 167 throw new ConfigException(L.l("function needs <name>")); 168 169 if (_signature == null) 170 throw new ConfigException(L.l("function requires <signature>")); 171 172 Method []methods = _functionClass.getMethods(); 173 174 loop: 175 for (int i = 0; i < methods.length; i++) { 176 Method method = methods[i]; 177 178 if (! Modifier.isPublic(method.getModifiers())) 179 continue; 180 181 if (Modifier.isAbstract(method.getModifiers())) 182 continue; 183 184 if (_signature.matches(method)) { 185 _method = method; 186 187 if (! Modifier.isPublic(_method.getModifiers())) 188 throw new ConfigException(L.l("function `{0}' must be public", 189 _method)); 190 if (! Modifier.isStatic(_method.getModifiers())) 191 throw new ConfigException(L.l("function `{0}' must be static", 192 _method)); 193 if (Modifier.isAbstract(_method.getModifiers())) 194 throw new ConfigException(L.l("function `{0}' must be concrete", 195 _method)); 196 return; 197 } 198 } 199 200 throw new ConfigException(L.l("No public method in `{0}' matches the signature `{1}'", 201 _functionClass.getName(), 202 _signature.getSignature())); 203 } 204 205 public FunctionInfo toFunctionInfo() 206 { 207 return new FunctionInfo (_name, 208 _functionClass.getName(), 209 _signature.getSignature()); 210 } 211 212 public String toString() 213 { 214 return "TldFunction[" + _signature.getSignature() + "]"; 215 } 216 } 217 | Popular Tags |