1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.cubby.dxo.impl; |
17 | |
|
18 | |
import java.lang.reflect.Method; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.seasar.cubby.dxo.FormDxo; |
22 | |
import org.seasar.cubby.tags.FormTag; |
23 | |
import org.seasar.extension.dxo.annotation.AnnotationReader; |
24 | |
import org.seasar.extension.dxo.command.DxoCommand; |
25 | |
import org.seasar.extension.dxo.converter.Converter; |
26 | |
import org.seasar.extension.dxo.converter.ConverterFactory; |
27 | |
import org.seasar.framework.container.annotation.tiger.InitMethod; |
28 | |
import org.seasar.framework.util.ClassUtil; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 36 | public class FormDxoImpl implements FormDxo { |
37 | |
|
38 | |
|
39 | |
private ConverterFactory converterFactory; |
40 | |
|
41 | |
|
42 | |
private AnnotationReader annotationReader; |
43 | |
|
44 | |
|
45 | |
private DxoCommand objectArrayMapToBeanDxoCommand; |
46 | |
|
47 | |
|
48 | |
private DxoCommand beanToStringArrayMapDxoCommand; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public void setConverterFactory(final ConverterFactory converterFactory) { |
57 | 36 | this.converterFactory = converterFactory; |
58 | 36 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public void setAnnotationReader(final AnnotationReader annotationReader) { |
67 | 36 | this.annotationReader = annotationReader; |
68 | 36 | } |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
@InitMethod |
74 | |
public void initialize() { |
75 | 36 | final Class<?> targetClass = this.getClass(); |
76 | |
|
77 | 36 | final Method objectArrayMapToBeanConvertMethod = ClassUtil.getMethod( |
78 | |
targetClass, "convert", new Class<?>[] { Map.class, |
79 | |
Object.class }); |
80 | 36 | this.objectArrayMapToBeanDxoCommand = createObjectArrayMapToBeanDxoCommand( |
81 | |
targetClass, objectArrayMapToBeanConvertMethod); |
82 | |
|
83 | 36 | final Method beanToStringArrayMapConvertMethod = ClassUtil.getMethod( |
84 | |
targetClass, "convert", new Class<?>[] { Object.class, |
85 | |
Map.class }); |
86 | 36 | this.beanToStringArrayMapDxoCommand = createBeanToStringArrayMapDxoCommand( |
87 | |
targetClass, beanToStringArrayMapConvertMethod); |
88 | 36 | } |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public void convert(final Map<String, Object[]> src, final Object dest) { |
99 | 6 | if (src != null) { |
100 | 5 | objectArrayMapToBeanDxoCommand.execute(new Object[] { src, dest }); |
101 | |
} |
102 | 6 | } |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public void convert(final Object src, final Map<String, String[]> dest) { |
113 | 5 | if (src != null) { |
114 | 4 | beanToStringArrayMapDxoCommand.execute(new Object[] { src, dest }); |
115 | |
} |
116 | 5 | } |
117 | |
|
118 | |
@SuppressWarnings("unchecked") |
119 | |
private DxoCommand createObjectArrayMapToBeanDxoCommand( |
120 | |
final Class dxoClass, final Method method) { |
121 | 36 | return new ObjectArrayMapToBeanDxoCommand(dxoClass, method, |
122 | |
converterFactory, annotationReader, Object.class); |
123 | |
} |
124 | |
|
125 | |
@SuppressWarnings("unchecked") |
126 | |
private DxoCommand createBeanToStringArrayMapDxoCommand( |
127 | |
final Class dxoClass, final Method method) { |
128 | 36 | final String expression = annotationReader.getConversionRule(dxoClass, |
129 | |
method); |
130 | 36 | return new BeanToStringArrayMapDxoCommand(dxoClass, method, |
131 | |
converterFactory, annotationReader, expression); |
132 | |
} |
133 | |
|
134 | |
} |