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 | 0 | { |
46 | 0 | _name = name; |
47 | 0 | _value = value; |
48 | 0 | } |
49 | |
|
50 | |
public void applyMetadata(FaceletContext ctx, Object instance) |
51 | |
{ |
52 | 0 | ((UIComponent) instance).getAttributes().put(_name, _value); |
53 | 0 | } |
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 | 0 | { |
66 | 0 | _name = name; |
67 | 0 | _attr = attr; |
68 | 0 | _type = type; |
69 | 0 | } |
70 | |
|
71 | |
public void applyMetadata(FaceletContext ctx, Object instance) |
72 | |
{ |
73 | 0 | ((UIComponent) instance).setValueExpression(_name, _attr.getValueExpression(ctx, _type)); |
74 | 0 | } |
75 | |
} |
76 | |
|
77 | |
|
78 | 0 | private final static Logger log = Logger.getLogger(ComponentRule.class.getName()); |
79 | |
|
80 | 0 | public final static ComponentRule INSTANCE = new ComponentRule(); |
81 | |
|
82 | |
public ComponentRule() |
83 | |
{ |
84 | 0 | super(); |
85 | 0 | } |
86 | |
|
87 | |
public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) |
88 | |
{ |
89 | 0 | if (meta.isTargetInstanceOf(UIComponent.class)) |
90 | |
{ |
91 | |
|
92 | 0 | if (!attribute.isLiteral()) |
93 | |
{ |
94 | 0 | Class<?> type = meta.getPropertyType(name); |
95 | 0 | if (type == null) |
96 | |
{ |
97 | 0 | type = Object.class; |
98 | |
} |
99 | |
|
100 | 0 | return new ValueExpressionMetadata(name, type, attribute); |
101 | |
} |
102 | 0 | else if (meta.getWriteMethod(name) == null) |
103 | |
{ |
104 | |
|
105 | |
|
106 | 0 | warnAttr(attribute, meta.getTargetClass(), name); |
107 | |
|
108 | 0 | return new LiteralAttributeMetadata(name, attribute.getValue()); |
109 | |
} |
110 | |
} |
111 | 0 | return null; |
112 | |
} |
113 | |
|
114 | |
private static void warnAttr(TagAttribute attr, Class<?> type, String n) |
115 | |
{ |
116 | 0 | if (log.isLoggable(Level.FINER)) |
117 | |
{ |
118 | 0 | log.finer(attr + " Property '" + n + "' is not on type: " + type.getName()); |
119 | |
} |
120 | 0 | } |
121 | |
|
122 | |
} |