1 package com.sun.facelets.tag.ui; 2 3 import java.beans.Introspector ; 4 import java.beans.PropertyDescriptor ; 5 import java.util.HashSet ; 6 import java.util.Map ; 7 import java.util.Set ; 8 9 import javax.faces.component.UIComponent; 10 11 import com.sun.facelets.FaceletContext; 12 import com.sun.facelets.tag.MetaRule; 13 import com.sun.facelets.tag.MetaRuleset; 14 import com.sun.facelets.tag.Metadata; 15 import com.sun.facelets.tag.MetadataTarget; 16 import com.sun.facelets.tag.TagAttribute; 17 import com.sun.facelets.tag.jsf.ComponentConfig; 18 import com.sun.facelets.tag.jsf.ComponentHandler; 19 20 public class RepeatHandler extends ComponentHandler { 21 22 public RepeatHandler(ComponentConfig config) { 23 super(config); 24 } 25 26 protected MetaRuleset createMetaRuleset(Class type) { 27 MetaRuleset meta = super.createMetaRuleset(type); 28 29 if (!UILibrary.Namespace.equals(this.tag.getNamespace())) { 30 meta.add(new TagMetaData(type)); 31 } 32 33 meta.alias("class", "styleClass"); 34 35 return meta; 36 } 37 38 private class TagMetaData extends Metadata { 39 40 private final String [] attrs; 41 42 public TagMetaData(Class type) { 43 Set s = new HashSet (); 44 TagAttribute[] ta = tag.getAttributes().getAll(); 45 for (int i = 0; i < ta.length; i++) { 46 if ("class".equals(ta[i].getLocalName())) { 47 s.add("styleClass"); 48 } else { 49 s.add(ta[i].getLocalName()); 50 } 51 } 52 try { 53 PropertyDescriptor [] pd = Introspector.getBeanInfo(type) 54 .getPropertyDescriptors(); 55 for (int i = 0; i < pd.length; i++) { 56 if (pd[i].getWriteMethod() != null) { 57 s.remove(pd[i].getName()); 58 } 59 } 60 } catch (Exception e) { 61 } 63 this.attrs = (String []) s.toArray(new String [s.size()]); 64 } 65 66 public void applyMetadata(FaceletContext ctx, Object instance) { 67 UIComponent c = (UIComponent) instance; 68 Map attrs = c.getAttributes(); 69 attrs.put("alias.element", tag.getQName()); 70 if (this.attrs.length > 0) { 71 attrs.put("alias.attributes", this.attrs); 72 } 73 } 74 75 } 76 77 } 78 | Popular Tags |