use of javax.servlet.jsp.tagext.Tag in project sling by apache.
the class TagHandlerPool method get.
/**
* Gets the next available tag handler from this tag handler pool,
* instantiating one if this tag handler pool is empty.
*
* @param handlerClass Tag handler class
*
* @return Reused or newly instantiated tag handler
*
* @throws JspException if a tag handler cannot be instantiated
*/
public Tag get(Class handlerClass) throws JspException {
Tag handler = null;
synchronized (this) {
if (current >= 0) {
handler = handlers[current--];
return handler;
}
}
// wait for us to construct a tag for this thread.
try {
Tag instance = (Tag) handlerClass.newInstance();
AnnotationHelper.postConstruct(annotationProcessor, instance);
return instance;
} catch (Exception e) {
throw new JspException(e.getMessage(), e);
}
}
use of javax.servlet.jsp.tagext.Tag in project spring-framework by spring-projects.
the class TagUtilsTests method hasAncestorOfTypeFalseScenario.
@Test
public void hasAncestorOfTypeFalseScenario() throws Exception {
Tag a = new TagA();
Tag b = new TagB();
Tag anotherB = new TagB();
a.setParent(b);
b.setParent(anotherB);
assertFalse(TagUtils.hasAncestorOfType(a, TagC.class));
}
use of javax.servlet.jsp.tagext.Tag in project spring-framework by spring-projects.
the class TagUtils method hasAncestorOfType.
/**
* Determine whether the supplied {@link Tag} has any ancestor tag
* of the supplied type.
* @param tag the tag whose ancestors are to be checked
* @param ancestorTagClass the ancestor {@link Class} being searched for
* @return {@code true} if the supplied {@link Tag} has any ancestor tag
* of the supplied type
* @throws IllegalArgumentException if either of the supplied arguments is {@code null};
* or if the supplied {@code ancestorTagClass} is not type-assignable to
* the {@link Tag} class
*/
public static boolean hasAncestorOfType(Tag tag, Class<?> ancestorTagClass) {
Assert.notNull(tag, "Tag cannot be null");
Assert.notNull(ancestorTagClass, "Ancestor tag class cannot be null");
if (!Tag.class.isAssignableFrom(ancestorTagClass)) {
throw new IllegalArgumentException("Class '" + ancestorTagClass.getName() + "' is not a valid Tag type");
}
Tag ancestor = tag.getParent();
while (ancestor != null) {
if (ancestorTagClass.isAssignableFrom(ancestor.getClass())) {
return true;
}
ancestor = ancestor.getParent();
}
return false;
}
Aggregations