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.composite; |
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 | |
|
37 | |
|
38 | |
final class CompositeComponentRule extends MetaRule |
39 | |
{ |
40 | |
|
41 | |
final class LiteralAttributeMetadata extends Metadata |
42 | |
{ |
43 | |
private final String _name; |
44 | |
private final String _value; |
45 | |
|
46 | |
public LiteralAttributeMetadata(String name, String value) |
47 | 0 | { |
48 | 0 | _name = name; |
49 | 0 | _value = value; |
50 | 0 | } |
51 | |
|
52 | |
public void applyMetadata(FaceletContext ctx, Object instance) |
53 | |
{ |
54 | 0 | ((UIComponent) instance).getAttributes().put(_name, _value); |
55 | 0 | } |
56 | |
} |
57 | |
|
58 | |
final class TypedLiteralAttributeMetadata extends Metadata |
59 | |
{ |
60 | |
private final String _name; |
61 | |
private final TagAttribute _attr; |
62 | |
private final Class<?> _type; |
63 | |
|
64 | |
public TypedLiteralAttributeMetadata(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).getAttributes().put(_name, _attr.getObject(ctx, _type)); |
74 | 0 | } |
75 | |
} |
76 | |
|
77 | |
final static class ValueExpressionMetadata extends Metadata |
78 | |
{ |
79 | |
private final String _name; |
80 | |
|
81 | |
private final TagAttribute _attr; |
82 | |
|
83 | |
private final Class<?> _type; |
84 | |
|
85 | |
public ValueExpressionMetadata(String name, Class<?> type, TagAttribute attr) |
86 | 0 | { |
87 | 0 | _name = name; |
88 | 0 | _attr = attr; |
89 | 0 | _type = type; |
90 | 0 | } |
91 | |
|
92 | |
public void applyMetadata(FaceletContext ctx, Object instance) |
93 | |
{ |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | 0 | ((UIComponent) instance).setValueExpression(_name, _attr.getValueExpression(ctx, _type)); |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | 0 | } |
107 | |
} |
108 | |
|
109 | |
|
110 | 0 | private final static Logger log = Logger.getLogger(CompositeComponentRule.class.getName()); |
111 | |
|
112 | 0 | public final static CompositeComponentRule INSTANCE = new CompositeComponentRule(); |
113 | |
|
114 | |
public CompositeComponentRule() |
115 | |
{ |
116 | 0 | super(); |
117 | 0 | } |
118 | |
|
119 | |
public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) |
120 | |
{ |
121 | 0 | if (meta.isTargetInstanceOf(UIComponent.class)) |
122 | |
{ |
123 | |
|
124 | 0 | if (!attribute.isLiteral()) |
125 | |
{ |
126 | 0 | Class<?> type = meta.getPropertyType(name); |
127 | 0 | if (type == null) |
128 | |
{ |
129 | 0 | type = Object.class; |
130 | |
} |
131 | |
|
132 | 0 | return new ValueExpressionMetadata(name, type, attribute); |
133 | |
} |
134 | 0 | else if (meta.getWriteMethod(name) == null) |
135 | |
{ |
136 | 0 | Class<?> type = meta.getPropertyType(name); |
137 | 0 | if (type == null) |
138 | |
{ |
139 | 0 | if (meta.getProperty(name) == null) |
140 | |
{ |
141 | |
|
142 | 0 | warnAttr(attribute, meta.getTargetClass(), name); |
143 | |
} |
144 | |
|
145 | 0 | return new LiteralAttributeMetadata(name, attribute.getValue()); |
146 | |
} |
147 | |
else |
148 | |
{ |
149 | 0 | return new TypedLiteralAttributeMetadata(name, type, attribute); |
150 | |
} |
151 | |
} |
152 | |
} |
153 | 0 | return null; |
154 | |
} |
155 | |
|
156 | |
private static void warnAttr(TagAttribute attr, Class<?> type, String n) |
157 | |
{ |
158 | 0 | if (log.isLoggable(Level.FINER)) |
159 | |
{ |
160 | 0 | log.finer(attr + " Property '" + n + "' is not on type: " + type.getName()); |
161 | |
} |
162 | 0 | } |
163 | |
|
164 | |
} |