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.beans.PropertyDescriptor; |
22 | |
|
23 | |
import javax.el.ValueExpression; |
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 | |
final class RetargetMethodExpressionRule extends MetaRule |
38 | |
{ |
39 | |
final static class RetargetValueExpressionMapper extends Metadata |
40 | |
{ |
41 | |
private final TagAttribute _attr; |
42 | |
|
43 | |
private final String _name; |
44 | |
|
45 | |
public RetargetValueExpressionMapper(TagAttribute attr, String name) |
46 | 0 | { |
47 | 0 | this._attr = attr; |
48 | 0 | this._name = name; |
49 | 0 | } |
50 | |
|
51 | |
public void applyMetadata(FaceletContext ctx, Object instance) |
52 | |
{ |
53 | 0 | ValueExpression expr = _attr.getValueExpression(ctx, Object.class); |
54 | 0 | ((UIComponent) instance).getAttributes().put(_name, expr); |
55 | 0 | } |
56 | |
} |
57 | |
|
58 | 0 | public final static RetargetMethodExpressionRule INSTANCE = new RetargetMethodExpressionRule(); |
59 | |
|
60 | |
public RetargetMethodExpressionRule() |
61 | |
{ |
62 | 0 | super(); |
63 | 0 | } |
64 | |
|
65 | |
public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) |
66 | |
{ |
67 | |
|
68 | |
|
69 | 0 | if ("action".equals(name) || |
70 | |
"actionListener".equals(name) || |
71 | |
"validator".equals(name) || |
72 | |
"valueChangeListener".equals(name)) |
73 | |
{ |
74 | 0 | return new RetargetValueExpressionMapper(attribute, name); |
75 | |
} |
76 | |
else |
77 | |
{ |
78 | 0 | PropertyDescriptor propertyDescriptor = meta.getProperty(name); |
79 | |
|
80 | 0 | if (propertyDescriptor != null && |
81 | |
propertyDescriptor.getValue("type") == null) |
82 | |
{ |
83 | 0 | ValueExpression methodSignatureExpression = |
84 | |
(ValueExpression) propertyDescriptor.getValue("method-signature"); |
85 | |
|
86 | 0 | if (methodSignatureExpression != null) |
87 | |
{ |
88 | 0 | return new RetargetValueExpressionMapper(attribute, name); |
89 | |
} |
90 | |
|
91 | 0 | ValueExpression targetAttributeNameVE = |
92 | |
(ValueExpression)propertyDescriptor.getValue("targetAttributeName"); |
93 | 0 | if (targetAttributeNameVE != null) |
94 | |
{ |
95 | 0 | return new RetargetValueExpressionMapper(attribute, name); |
96 | |
} |
97 | |
|
98 | |
|
99 | 0 | ValueExpression targets = |
100 | |
(ValueExpression)propertyDescriptor.getValue("targets"); |
101 | |
|
102 | 0 | if (targets != null) |
103 | |
{ |
104 | 0 | return new RetargetValueExpressionMapper(attribute, name); |
105 | |
} |
106 | |
} |
107 | |
} |
108 | 0 | return null; |
109 | |
} |
110 | |
} |