1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.commons.converter;
20
21 import java.lang.reflect.InvocationTargetException;
22 import java.lang.reflect.Method;
23
24 import com.sun.facelets.FaceletContext;
25 import com.sun.facelets.el.LegacyValueBinding;
26 import com.sun.facelets.tag.MetaRule;
27 import com.sun.facelets.tag.Metadata;
28 import com.sun.facelets.tag.MetadataTarget;
29 import com.sun.facelets.tag.TagAttribute;
30 import com.sun.facelets.tag.TagAttributeException;
31
32 final class _LocaleRule extends MetaRule {
33
34 final static class ValueBindingMetadata extends Metadata {
35
36 private final String name;
37
38 private final TagAttribute attr;
39
40 private final Class type;
41
42 public ValueBindingMetadata(String name, Class type,
43 TagAttribute attr) {
44 this.name = name;
45 this.attr = attr;
46 this.type = type;
47 }
48
49 public void applyMetadata(FaceletContext ctx, Object instance) {
50 ((ConverterBase) instance).setValueBinding(this.name, new LegacyValueBinding(this.attr
51 .getValueExpression(ctx, this.type)));
52 }
53
54 }
55
56 final static class LiteralPropertyMetadata extends Metadata
57 {
58
59 private final Method method;
60
61 private final TagAttribute attribute;
62
63 private Object[] value;
64
65 public LiteralPropertyMetadata(Method method, TagAttribute attribute)
66 {
67 this.method = method;
68 this.attribute = attribute;
69 }
70
71 public void applyMetadata(FaceletContext ctx, Object instance)
72 {
73 if (value == null)
74 {
75 String str = this.attribute.getValue();
76 value = new Object[] { org.apache.myfaces.commons.util.TagUtils.getLocale( str ) };
77 }
78 try
79 {
80 method.invoke(instance, this.value);
81 }
82 catch (InvocationTargetException e)
83 {
84 throw new TagAttributeException(this.attribute, e.getCause());
85 }
86 catch (Exception e)
87 {
88 throw new TagAttributeException(this.attribute, e);
89 }
90 }
91
92 }
93
94 public final static _LocaleRule Instance = new _LocaleRule();
95
96 public _LocaleRule() {
97 super();
98 }
99
100 public Metadata applyRule(String name, TagAttribute attribute,
101 MetadataTarget meta) {
102 if (meta.isTargetInstanceOf(ConverterBase.class)) {
103
104 if ("locale".equals(name))
105 {
106
107 if (!attribute.isLiteral()) {
108 return new ValueBindingMetadata(name, Object.class, attribute);
109 }
110 else
111 {
112 Method m = meta.getWriteMethod(name);
113
114 return new LiteralPropertyMetadata(m, attribute);
115 }
116 }
117 }
118 return null;
119 }
120 }