1 14 15 package com.sun.facelets.tag; 16 17 import java.util.ArrayList ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 21 import com.sun.facelets.FaceletHandler; 22 23 30 public abstract class TagHandler implements FaceletHandler { 31 32 protected final String tagId; 33 34 protected final Tag tag; 35 36 protected final FaceletHandler nextHandler; 37 38 public TagHandler(TagConfig config) { 39 this.tagId = config.getTagId(); 40 this.tag = config.getTag(); 41 this.nextHandler = config.getNextHandler(); 42 } 43 44 51 protected final TagAttribute getAttribute(String localName) { 52 return this.tag.getAttributes().get(localName); 53 } 54 55 64 protected final TagAttribute getRequiredAttribute(String localName) 65 throws TagException { 66 TagAttribute attr = this.getAttribute(localName); 67 if (attr == null) { 68 throw new TagException(this.tag, "Attribute '" + localName 69 + "' is required"); 70 } 71 return attr; 72 } 73 74 82 protected final Iterator findNextByType(Class type) { 83 List found = new ArrayList (); 84 if (type.isAssignableFrom(this.nextHandler.getClass())) { 85 found.add(this.nextHandler); 86 } else if (this.nextHandler instanceof CompositeFaceletHandler) { 87 FaceletHandler[] h = ((CompositeFaceletHandler) this.nextHandler).getHandlers(); 88 for (int i = 0; i < h.length; i++) { 89 if (type.isAssignableFrom(h[i].getClass())) { 90 found.add(h[i]); 91 } 92 } 93 } 94 return found.iterator(); 95 } 96 97 public String toString() { 98 return this.tag.toString(); 99 } 100 } 101 | Popular Tags |