KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > tag > ui > RepeatHandler


1 package com.sun.facelets.tag.ui;
2
3 import java.beans.Introspector JavaDoc;
4 import java.beans.PropertyDescriptor JavaDoc;
5 import java.util.HashSet JavaDoc;
6 import java.util.Map JavaDoc;
7 import java.util.Set JavaDoc;
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 JavaDoc 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 JavaDoc[] attrs;
41
42         public TagMetaData(Class JavaDoc type) {
43             Set JavaDoc s = new HashSet JavaDoc();
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 JavaDoc[] 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 JavaDoc e) {
61                 // do nothing
62
}
63             this.attrs = (String JavaDoc[]) s.toArray(new String JavaDoc[s.size()]);
64         }
65
66         public void applyMetadata(FaceletContext ctx, Object JavaDoc instance) {
67             UIComponent c = (UIComponent) instance;
68             Map JavaDoc 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