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 | 0 | { |
43 | 0 | _name = name; |
44 | 0 | _value = value; |
45 | 0 | } |
46 | |
|
47 | |
public void applyMetadata(FaceletContext ctx, Object instance) |
48 | |
{ |
49 | 0 | ((UIComponent) instance).getPassThroughAttributes().put(_name, _value); |
50 | 0 | } |
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 | 0 | { |
63 | 0 | _name = name; |
64 | 0 | _attr = attr; |
65 | 0 | _type = type; |
66 | 0 | } |
67 | |
|
68 | |
public void applyMetadata(FaceletContext ctx, Object instance) |
69 | |
{ |
70 | 0 | ((UIComponent) instance).getPassThroughAttributes().put( |
71 | |
_name, _attr.getValueExpression(ctx, _type)); |
72 | 0 | } |
73 | |
} |
74 | |
|
75 | 0 | public final static PassthroughRuleImpl INSTANCE = new PassthroughRuleImpl(); |
76 | |
|
77 | |
public PassthroughRuleImpl() |
78 | |
{ |
79 | 0 | super(); |
80 | 0 | } |
81 | |
|
82 | |
public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) |
83 | |
{ |
84 | 0 | if (meta.isTargetInstanceOf(UIComponent.class)) |
85 | |
{ |
86 | |
|
87 | 0 | if (!attribute.isLiteral()) |
88 | |
{ |
89 | 0 | Class<?> type = meta.getPropertyType(name); |
90 | 0 | if (type == null) |
91 | |
{ |
92 | 0 | type = Object.class; |
93 | |
} |
94 | |
|
95 | 0 | if ("class".equalsIgnoreCase(name)) |
96 | |
{ |
97 | 0 | type = Object.class; |
98 | |
} |
99 | |
|
100 | 0 | return new ValueExpressionMetadata(name, type, attribute); |
101 | |
} |
102 | |
else |
103 | |
{ |
104 | 0 | return new LiteralAttributeMetadata(name, attribute.getValue()); |
105 | |
} |
106 | |
} |
107 | 0 | return null; |
108 | |
} |
109 | |
} |