1 28 29 package com.caucho.jsp.cfg; 30 31 import com.caucho.config.Config; 32 import com.caucho.config.ConfigException; 33 import com.caucho.config.DependencyBean; 34 import com.caucho.jsp.JspParseException; 35 import com.caucho.util.L10N; 36 import com.caucho.vfs.PersistentDependency; 37 38 import javax.servlet.jsp.tagext.SimpleTag ; 39 import javax.servlet.jsp.tagext.Tag ; 40 import javax.servlet.jsp.tagext.TagAttributeInfo ; 41 import javax.servlet.jsp.tagext.TagExtraInfo ; 42 import javax.servlet.jsp.tagext.TagVariableInfo ; 43 import javax.servlet.jsp.tagext.VariableInfo ; 44 import java.util.ArrayList ; 45 import java.util.logging.Logger ; 46 47 50 public class TldTag implements DependencyBean { 51 private final static L10N L = new L10N(TldTag.class); 52 private final static Logger log 53 = Logger.getLogger(TldTag.class.getName()); 54 55 private String _name; 56 private String _tagClassName; 57 private String _teiClassName; 58 private String _bodyContent; 59 private String _displayName; 60 private String _info; 61 private String _smallIcon; 62 private String _largeIcon; 63 private String _description; 64 private ArrayList <TagVariableInfo > _variableList = 65 new ArrayList <TagVariableInfo >(); 66 private ArrayList <TagAttributeInfo > _attributeList = 67 new ArrayList <TagAttributeInfo >(); 68 private ArrayList <TldFragmentAttribute> _fragmentAttributeList = 69 new ArrayList <TldFragmentAttribute>(); 70 private boolean _dynamicAttributes; 71 private String _dynamicAttributeName; 72 private String _example; 73 74 private String _configLocation; 75 private JspParseException _configException; 76 77 private ArrayList <PersistentDependency> _dependencyList 78 = new ArrayList <PersistentDependency>(); 79 80 83 public void setConfigLocation(String filename, int line) 84 { 85 _configLocation = filename + ":" + line + ": "; 86 } 87 88 91 public void addDependency(PersistentDependency dependency) 92 { 93 _dependencyList.add(dependency); 94 } 95 96 99 public ArrayList <PersistentDependency> getDependencyList() 100 { 101 return _dependencyList; 102 } 103 104 107 public void setName(String name) 108 { 109 _name = name; 110 } 111 112 115 public String getName() 116 { 117 return _name; 118 } 119 120 123 public void setIcon(com.caucho.config.types.Icon icon) 124 { 125 if (icon != null) { 126 _smallIcon = icon.getSmallIcon(); 127 _largeIcon = icon.getLargeIcon(); 128 } 129 } 130 131 134 public void setTagClass(String tagClassName) 135 throws ConfigException 136 { 137 _tagClassName = tagClassName; 138 139 Class tagClass = null; 140 141 try { 142 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 143 144 tagClass = Class.forName(tagClassName, false, loader); 145 146 Config.checkCanInstantiate(tagClass); 147 } catch (ConfigException e) { 148 throw e; 149 } catch (Throwable e) { 150 log.warning(_configLocation + e); 151 152 if (_configException == null) 153 _configException = new JspParseException(_configLocation + e); 154 155 return; 156 } 157 158 if (! Tag .class.isAssignableFrom(tagClass) && 159 ! SimpleTag .class.isAssignableFrom(tagClass)) 160 throw new ConfigException(L.l("{0} must either implement Tag or SimpleTag.", 161 tagClass.getName())); 162 } 163 164 167 public void setTagclass(String tagClassName) 168 throws ConfigException, InstantiationException , IllegalAccessException 169 { 170 setTagClass(tagClassName); 171 } 172 173 176 public Class getTagClass() 177 { 178 try { 179 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 180 181 return Class.forName(_tagClassName, false, loader); 182 } catch (ClassNotFoundException e) { 183 throw new RuntimeException (e); 184 } 185 } 186 187 190 public String getTagClassName() 191 { 192 return _tagClassName; 193 } 194 195 198 public void setTeiClass(String teiClassName) 199 throws ConfigException 200 { 201 _teiClassName = teiClassName; 202 203 try { 204 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 205 206 Class teiClass = Class.forName(teiClassName, false, loader); 207 208 Config.validate(teiClass, TagExtraInfo .class); 209 } catch (ConfigException e) { 210 throw e; 211 } catch (Throwable e) { 212 log.warning(_configLocation + e); 213 214 if (_configException == null) 215 _configException = new JspParseException(_configLocation + e); 216 217 return; 218 } 219 } 220 221 224 public void setTeiclass(String teiClassName) 225 throws ConfigException 226 { 227 setTeiClass(teiClassName); 228 } 229 230 233 public String getTeiClassName() 234 { 235 return _teiClassName; 236 } 237 238 241 public TagExtraInfo getTagExtraInfo() 242 { 243 try { 244 if (_teiClassName == null) 245 return null; 246 else { 247 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 248 249 Class teiClass = Class.forName(_teiClassName, false, loader); 250 251 return (TagExtraInfo ) teiClass.newInstance(); 252 } 253 } catch (Exception e) { 254 throw new RuntimeException (e); 255 } 256 } 257 258 261 public void setBodyContent(String bodyContent) 262 { 263 _bodyContent = bodyContent; 264 } 265 266 269 public String getBodyContent() 270 { 271 return _bodyContent; 272 } 273 274 277 public void setDisplayName(String displayName) 278 { 279 _displayName = displayName; 280 } 281 282 285 public String getDisplayName() 286 { 287 return _displayName; 288 } 289 290 293 public void setInfo(String info) 294 { 295 _info = info; 296 } 297 298 301 public String getInfo() 302 { 303 return _info; 304 } 305 306 309 public void setSmallIcon(String smallIcon) 310 { 311 _smallIcon = smallIcon; 312 } 313 314 317 public String getSmallIcon() 318 { 319 return _smallIcon; 320 } 321 322 325 public void setLargeIcon(String largeIcon) 326 { 327 _largeIcon = largeIcon; 328 } 329 330 333 public String getLargeIcon() 334 { 335 return _largeIcon; 336 } 337 338 341 public void setDescription(String description) 342 { 343 _description = description; 344 } 345 346 349 public String getDescription() 350 { 351 return _description; 352 } 353 354 357 public void addVariable(TldVariable variable) 358 throws ConfigException 359 { 360 TagVariableInfo varInfo; 361 362 String scopeName = variable.getScope(); 363 int scope; 364 365 if (scopeName == null) 366 scope = VariableInfo.NESTED; 367 else if (scopeName.equals("NESTED")) 368 scope = VariableInfo.NESTED; 369 else if (scopeName.equals("AT_BEGIN")) 370 scope = VariableInfo.AT_BEGIN; 371 else if (scopeName.equals("AT_END")) 372 scope = VariableInfo.AT_END; 373 else 374 throw new ConfigException(L.l("{0} expects a valid scope at `{1}'", 375 variable.getNameGiven(), scopeName)); 376 377 varInfo = new TagVariableInfo (variable.getNameGiven(), 378 variable.getNameFromAttribute(), 379 variable.getVariableClass(), 380 variable.getDeclare(), 381 scope); 382 383 _variableList.add(varInfo); 384 } 385 386 389 public ArrayList <TagVariableInfo > getVariableList() 390 { 391 return _variableList; 392 } 393 394 397 public TagVariableInfo []getVariables() 398 { 399 TagVariableInfo []variables; 400 401 variables = new TagVariableInfo [_variableList.size()]; 402 403 return _variableList.toArray(variables); 404 } 405 406 409 public void addAttribute(TldAttribute attribute) 410 { 411 TagAttributeInfo attrInfo; 412 413 Class type = attribute.getType(); 414 attrInfo = new TagAttributeInfo (attribute.getName(), 415 attribute.getRequired(), 416 type == null ? null : type.getName(), 417 attribute.getRtexprvalue(), 418 attribute.isFragment(), 419 attribute.getDescription(), 420 attribute.getDeferredValue() != null, 421 attribute.getDeferredMethod() != null, 422 attribute.getExpectedType(), 423 attribute.getDeferredMethodSignature()); 424 425 _attributeList.add(attrInfo); 426 } 427 428 431 public ArrayList getAttributeList() 432 { 433 return _attributeList; 434 } 435 436 439 public TagAttributeInfo []getAttributes() 440 { 441 TagAttributeInfo []attributes; 442 443 attributes = new TagAttributeInfo [_attributeList.size()]; 444 445 return (TagAttributeInfo []) _attributeList.toArray(attributes); 446 } 447 448 451 public void addFragmentAttribute(TldFragmentAttribute attribute) 452 { 453 _fragmentAttributeList.add(attribute); 454 } 455 456 459 public ArrayList getFragmentAttributes() 460 { 461 return _fragmentAttributeList; 462 } 463 464 467 public void setExample(String example) 468 { 469 _example = example; 470 } 471 472 475 public boolean getDynamicAttributes() 476 { 477 return _dynamicAttributes; 478 } 479 480 483 public void setDynamicAttributes(boolean dynamicAttributes) 484 { 485 _dynamicAttributes = dynamicAttributes; 486 } 487 488 491 public String getDynamicAttributeName() 492 { 493 return _dynamicAttributeName; 494 } 495 496 499 public void setDynamicAttributeName(String name) 500 { 501 _dynamicAttributeName = name; 502 } 503 504 507 public String getExample() 508 { 509 return _example; 510 } 511 512 515 public void validate() 516 throws JspParseException 517 { 518 if (_configException != null) 519 throw _configException; 520 } 521 } 522 | Popular Tags |