1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.config.faces.assembler; |
17 | |
|
18 | |
import java.util.Collections; |
19 | |
import java.util.Iterator; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import javax.faces.application.Application; |
24 | |
|
25 | |
import org.seasar.framework.util.StringUtil; |
26 | |
import org.seasar.teeda.core.application.ConfigurationSupport; |
27 | |
import org.seasar.teeda.core.application.ConverterConfiguration; |
28 | |
import org.seasar.teeda.core.config.faces.element.ConverterElement; |
29 | |
import org.seasar.teeda.core.config.faces.element.PropertyElement; |
30 | |
import org.seasar.teeda.core.util.ApplicationUtil; |
31 | |
import org.seasar.teeda.core.util.IteratorUtil; |
32 | |
|
33 | |
public abstract class ConverterChildAssembler implements JsfAssembler { |
34 | |
|
35 | |
private Application application_; |
36 | |
|
37 | 12 | private Map targetCovnerters_ = Collections.EMPTY_MAP; |
38 | |
|
39 | 12 | public ConverterChildAssembler(Map targetConverters) { |
40 | 12 | application_ = ApplicationUtil.getApplicationFromFactory(); |
41 | 12 | targetCovnerters_ = targetConverters; |
42 | 12 | } |
43 | |
|
44 | |
public void assemble() { |
45 | 12 | String converterKey = null; |
46 | 12 | ConverterElement converterElement = null; |
47 | 12 | for (Iterator itr = IteratorUtil.getEntryIterator(targetCovnerters_); itr |
48 | 20 | .hasNext();) { |
49 | 8 | Map.Entry entry = (Map.Entry) itr.next(); |
50 | 8 | converterKey = (String) entry.getKey(); |
51 | 8 | converterElement = (ConverterElement) entry.getValue(); |
52 | 8 | if (!StringUtil.isEmpty(converterKey) && converterElement != null) { |
53 | 7 | setConverterConfiguration(converterKey, converterElement); |
54 | 7 | doAssemble(converterKey, converterElement); |
55 | |
} |
56 | |
} |
57 | 12 | } |
58 | |
|
59 | |
protected void setConverterConfiguration(String converterKey, |
60 | |
ConverterElement converterElement) { |
61 | 7 | if (converterElement == null) { |
62 | 0 | return; |
63 | |
} |
64 | 7 | Application app = getApplication(); |
65 | 7 | if (app instanceof ConfigurationSupport) { |
66 | 1 | List properties = converterElement.getPropertyElements(); |
67 | 1 | ConfigurationSupport support = (ConfigurationSupport) app; |
68 | 1 | for (Iterator itr = IteratorUtil.getIterator(properties); itr |
69 | 2 | .hasNext();) { |
70 | 1 | PropertyElement property = (PropertyElement) itr.next(); |
71 | 1 | String propertyName = property.getPropertyName(); |
72 | 1 | String propertyClass = property.getPropertyClass(); |
73 | 1 | String defaultValue = property.getDefaultValue(); |
74 | 1 | if (!StringUtil.isEmpty(propertyName) |
75 | |
&& !StringUtil.isEmpty(propertyClass)) { |
76 | 1 | doAddConverterConfiguration(support, converterKey, |
77 | |
new ConverterConfiguration(propertyName, |
78 | |
propertyClass, defaultValue)); |
79 | |
} |
80 | |
} |
81 | |
} |
82 | 7 | } |
83 | |
|
84 | |
protected final Application getApplication() { |
85 | 14 | return application_; |
86 | |
} |
87 | |
|
88 | |
protected abstract void doAssemble(String converterKey, |
89 | |
ConverterElement converterElement); |
90 | |
|
91 | |
protected abstract void doAddConverterConfiguration( |
92 | |
ConfigurationSupport support, String converterKey, |
93 | |
ConverterConfiguration configuration); |
94 | |
|
95 | |
} |