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.jsf;
20
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23
24 import javax.faces.component.UIComponent;
25 import javax.faces.view.facelets.FaceletContext;
26 import javax.faces.view.facelets.MetaRule;
27 import javax.faces.view.facelets.Metadata;
28 import javax.faces.view.facelets.MetadataTarget;
29 import javax.faces.view.facelets.TagAttribute;
30
31
32
33
34
35
36 final class ComponentRule extends MetaRule
37 {
38
39 final class LiteralAttributeMetadata extends Metadata
40 {
41 private final String _name;
42 private final String _value;
43
44 public LiteralAttributeMetadata(String name, String value)
45 {
46 _name = name;
47 _value = value;
48 }
49
50 public void applyMetadata(FaceletContext ctx, Object instance)
51 {
52 ((UIComponent) instance).getAttributes().put(_name, _value);
53 }
54 }
55
56 final static class ValueExpressionMetadata extends Metadata
57 {
58 private final String _name;
59
60 private final TagAttribute _attr;
61
62 private final Class<?> _type;
63
64 public ValueExpressionMetadata(String name, Class<?> type, TagAttribute attr)
65 {
66 _name = name;
67 _attr = attr;
68 _type = type;
69 }
70
71 public void applyMetadata(FaceletContext ctx, Object instance)
72 {
73 ((UIComponent) instance).setValueExpression(_name, _attr.getValueExpression(ctx, _type));
74 }
75 }
76
77
78 private final static Logger log = Logger.getLogger(ComponentRule.class.getName());
79
80 public final static ComponentRule INSTANCE = new ComponentRule();
81
82 public ComponentRule()
83 {
84 super();
85 }
86
87 public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
88 {
89 if (meta.isTargetInstanceOf(UIComponent.class))
90 {
91
92 if (!attribute.isLiteral())
93 {
94 Class<?> type = meta.getPropertyType(name);
95 if (type == null)
96 {
97 type = Object.class;
98 }
99
100 return new ValueExpressionMetadata(name, type, attribute);
101 }
102 else if (meta.getWriteMethod(name) == null)
103 {
104
105
106 warnAttr(attribute, meta.getTargetClass(), name);
107
108 return new LiteralAttributeMetadata(name, attribute.getValue());
109 }
110 }
111 return null;
112 }
113
114 private static void warnAttr(TagAttribute attr, Class<?> type, String n)
115 {
116 if (log.isLoggable(Level.FINER))
117 {
118 log.finer(attr + " Property '" + n + "' is not on type: " + type.getName());
119 }
120 }
121
122 }