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 javax.faces.view.facelets.FaceletContext;
25 import javax.faces.view.facelets.MetaRule;
26 import javax.faces.view.facelets.Metadata;
27 import javax.faces.view.facelets.MetadataTarget;
28 import javax.faces.view.facelets.TagAttribute;
29 import javax.faces.view.facelets.TagAttributeException;
30
31 final class _TimeZoneRule extends MetaRule {
32
33 final static class ValueExpressionMetadata extends Metadata {
34
35 private final String name;
36
37 private final TagAttribute attr;
38
39 private final Class type;
40
41 public ValueExpressionMetadata(String name, Class type,
42 TagAttribute attr) {
43 this.name = name;
44 this.attr = attr;
45 this.type = type;
46 }
47
48 public void applyMetadata(FaceletContext ctx, Object instance) {
49 ((ConverterBase) instance).setValueExpression(this.name, this.attr
50 .getValueExpression(ctx, this.type));
51 }
52
53 }
54
55 final static class LiteralPropertyMetadata extends Metadata
56 {
57
58 private final Method method;
59
60 private final TagAttribute attribute;
61
62 private Object[] value;
63
64 public LiteralPropertyMetadata(Method method, TagAttribute attribute)
65 {
66 this.method = method;
67 this.attribute = attribute;
68 }
69
70 public void applyMetadata(FaceletContext ctx, Object instance)
71 {
72 if (value == null)
73 {
74 String str = this.attribute.getValue();
75 value = new Object[] { java.util.TimeZone.getTimeZone( str ) };
76 }
77 try
78 {
79 method.invoke(instance, this.value);
80 }
81 catch (InvocationTargetException e)
82 {
83 throw new TagAttributeException(this.attribute, e.getCause());
84 }
85 catch (Exception e)
86 {
87 throw new TagAttributeException(this.attribute, e);
88 }
89 }
90
91 }
92
93 public final static _TimeZoneRule Instance = new _TimeZoneRule();
94
95 public _TimeZoneRule() {
96 super();
97 }
98
99 public Metadata applyRule(String name, TagAttribute attribute,
100 MetadataTarget meta) {
101 if (meta.isTargetInstanceOf(ConverterBase.class)) {
102
103 if ("timeZone".equals(name))
104 {
105
106 if (!attribute.isLiteral()) {
107 return new ValueExpressionMetadata(name, Object.class, attribute);
108 }
109 else
110 {
111 Method m = meta.getWriteMethod(name);
112
113 return new LiteralPropertyMetadata(m, attribute);
114 }
115 }
116 }
117 return null;
118 }
119 }