public void checkTld(String checkedTld) throws Exception {
List tagsAttributes = getTagAttributeList(checkedTld);
List errors = new ArrayList();
Iterator iterator = tagsAttributes.iterator();
while (iterator.hasNext())
{
TagAttribute attribute = (TagAttribute) iterator.next();
if (log.isDebugEnabled())
{
log.debug("testing " + attribute);
}
String className = attribute.getTagClass();
Class tagClass = null;
try
{
tagClass = Class.forName(className);
}
catch (ClassNotFoundException e)
{
errors.add("unable to find declared tag class [" + className + "]");
continue;
}
if (!TagSupport.class.isAssignableFrom(tagClass))
{
errors.add("Declared class [" + className + "] doesn't extend TagSupport");
continue;
}
// load it
Object tagObject = null;
try
{
tagObject = tagClass.newInstance();
}
catch (Throwable e)
{
errors.add("unable to instantiate declared tag class [" + className + "]");
continue;
}
if (!PropertyUtils.isWriteable(tagObject, attribute.getAttributeName()))
{
errors.add("Setter for attribute [" + attribute.getAttributeName() + "] not found in " + className);
continue;
}
Class propertyType = PropertyUtils.getPropertyType(tagObject, attribute.getAttributeName());
String tldType = attribute.getAttributeType();
if (tldType != null)
{
Class tldTypeClass = getClassFromName(tldType);
if (!propertyType.isAssignableFrom(tldTypeClass))
{
errors.add("Tag attribute ["
+ attribute.getAttributeName()
+ "] declared in tld as ["
+ tldType
+ "], class declare ["
+ propertyType.getName()
+ "]");
continue;
}
}
}
if (errors.size() > 0)
{
if (log.isInfoEnabled())
{
log.info(errors.size() + " errors found in tag classes: " + errors);
}
fail(errors.size() + " errors found in tag classes: " + errors);
}
}
Check the given tld. Assure then:
- Any tag class is loadable
- the tag class has a setter for any of the declared attribute
- the type declared in the dtd for an attribute (if any) matches the type accepted by the getter
|