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 javax.faces.component.UIComponent;
22 import javax.faces.view.facelets.FaceletContext;
23 import javax.faces.view.facelets.MetaRule;
24 import javax.faces.view.facelets.Metadata;
25 import javax.faces.view.facelets.MetadataTarget;
26 import javax.faces.view.facelets.TagAttribute;
27 import org.apache.myfaces.view.facelets.PassthroughRule;
28
29
30
31
32
33 final class PassthroughRuleImpl extends MetaRule implements PassthroughRule
34 {
35
36 final static class LiteralAttributeMetadata extends Metadata
37 {
38 private final String _name;
39 private final String _value;
40
41 public LiteralAttributeMetadata(String name, String value)
42 {
43 _name = name;
44 _value = value;
45 }
46
47 public void applyMetadata(FaceletContext ctx, Object instance)
48 {
49 ((UIComponent) instance).getPassThroughAttributes().put(_name, _value);
50 }
51 }
52
53 final static class ValueExpressionMetadata extends Metadata
54 {
55 private final String _name;
56
57 private final TagAttribute _attr;
58
59 private final Class<?> _type;
60
61 public ValueExpressionMetadata(String name, Class<?> type, TagAttribute attr)
62 {
63 _name = name;
64 _attr = attr;
65 _type = type;
66 }
67
68 public void applyMetadata(FaceletContext ctx, Object instance)
69 {
70 ((UIComponent) instance).getPassThroughAttributes().put(
71 _name, _attr.getValueExpression(ctx, _type));
72 }
73 }
74
75 public final static PassthroughRuleImpl INSTANCE = new PassthroughRuleImpl();
76
77 public PassthroughRuleImpl()
78 {
79 super();
80 }
81
82 public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
83 {
84 if (meta.isTargetInstanceOf(UIComponent.class))
85 {
86
87 if (!attribute.isLiteral())
88 {
89 Class<?> type = meta.getPropertyType(name);
90 if (type == null)
91 {
92 type = Object.class;
93 }
94
95 if ("class".equalsIgnoreCase(name))
96 {
97 type = Object.class;
98 }
99
100 return new ValueExpressionMetadata(name, type, attribute);
101 }
102 else
103 {
104 return new LiteralAttributeMetadata(name, attribute.getValue());
105 }
106 }
107 return null;
108 }
109 }