1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag.ui;
20
21 import java.beans.Introspector;
22 import java.beans.PropertyDescriptor;
23 import java.util.HashSet;
24 import java.util.Map;
25 import java.util.Set;
26
27 import javax.faces.component.UIComponent;
28 import javax.faces.view.facelets.ComponentConfig;
29 import javax.faces.view.facelets.ComponentHandler;
30 import javax.faces.view.facelets.FaceletContext;
31 import javax.faces.view.facelets.MetaRuleset;
32 import javax.faces.view.facelets.Metadata;
33 import javax.faces.view.facelets.TagAttribute;
34
35
36
37
38
39 public class RepeatHandler extends ComponentHandler
40 {
41
42 public RepeatHandler(ComponentConfig config)
43 {
44 super(config);
45 }
46
47 @Override
48 protected MetaRuleset createMetaRuleset(Class type)
49 {
50 MetaRuleset meta = super.createMetaRuleset(type);
51
52 if (!UILibrary.NAMESPACE.equals(this.tag.getNamespace()) &&
53 !UILibrary.ALIAS_NAMESPACE.equals(this.tag.getNamespace()))
54 {
55 meta.add(new TagMetaData(type));
56 }
57
58 meta.alias("class", "styleClass");
59
60 return meta;
61 }
62
63 private class TagMetaData extends Metadata
64 {
65 private final String[] _attrs;
66
67 public TagMetaData(Class<?> type)
68 {
69 Set<String> names = new HashSet<String>();
70 for (TagAttribute attribute : tag.getAttributes().getAll())
71 {
72 if ("class".equals(attribute.getLocalName()))
73 {
74 names.add("styleClass");
75 }
76 else
77 {
78 names.add(attribute.getLocalName());
79 }
80 }
81
82 try
83 {
84 for (PropertyDescriptor descriptor : Introspector.getBeanInfo(type).getPropertyDescriptors())
85 {
86 if (descriptor.getWriteMethod() != null)
87 {
88 names.remove(descriptor.getName());
89 }
90 }
91 }
92 catch (Exception e)
93 {
94
95 }
96
97 _attrs = names.toArray(new String[names.size()]);
98 }
99
100 @Override
101 public void applyMetadata(FaceletContext ctx, Object instance)
102 {
103 UIComponent component = (UIComponent) instance;
104 Map<String, Object> attrs = component.getAttributes();
105 attrs.put("alias.element", tag.getQName());
106 if (_attrs.length > 0)
107 {
108 attrs.put("alias.attributes", _attrs);
109 }
110 }
111 }
112 }