1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.shale.tiger.managed.rules; |
19 | |
|
20 | |
import java.util.Map; |
21 | |
import java.util.Set; |
22 | |
import org.apache.commons.digester.Rule; |
23 | |
import org.apache.shale.tiger.config.FacesConfigConfig; |
24 | |
import org.apache.shale.tiger.managed.config.ManagedBeanConfig; |
25 | |
import org.apache.shale.tiger.managed.config.ManagedPropertyConfig; |
26 | |
import org.xml.sax.Attributes; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public class ManagedBeanRule extends Rule { |
33 | |
|
34 | |
|
35 | 21 | public ManagedBeanRule() { |
36 | 21 | } |
37 | |
|
38 | |
|
39 | |
private static final String CLASS_NAME = |
40 | |
"org.apache.shale.tiger.managed.config.ManagedBeanConfig"; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public void begin(String namespace, String name, |
53 | |
Attributes attributes) throws Exception { |
54 | |
|
55 | 186 | Class clazz = digester.getClassLoader().loadClass(CLASS_NAME); |
56 | 186 | digester.push(clazz.newInstance()); |
57 | |
|
58 | 186 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public void body(String namespace, String name) throws Exception { |
70 | |
} |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public void end(String namespace, String name) throws Exception { |
86 | |
|
87 | 186 | ManagedBeanConfig config = (ManagedBeanConfig) digester.pop(); |
88 | 186 | FacesConfigConfig parent = (FacesConfigConfig) digester.peek(); |
89 | 186 | ManagedBeanConfig previous = parent.getManagedBean(config.getName()); |
90 | 186 | if (previous == null) { |
91 | 126 | parent.addManagedBean(config); |
92 | 126 | } else { |
93 | 60 | merge(config, previous); |
94 | |
} |
95 | |
|
96 | 186 | } |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
static void merge(ManagedBeanConfig config, ManagedBeanConfig previous) { |
107 | |
|
108 | 60 | if (config.getType() != null) { |
109 | 60 | previous.setType(config.getType()); |
110 | |
} |
111 | 60 | if (config.getScope() != null) { |
112 | 60 | previous.setScope(config.getScope()); |
113 | |
} |
114 | 60 | Set<Map.Entry<String,ManagedPropertyConfig>> properties = |
115 | |
config.getProperties().entrySet(); |
116 | 60 | for (Map.Entry<String,ManagedPropertyConfig> property : properties) { |
117 | 123 | ManagedPropertyConfig prevProperty = |
118 | |
previous.getProperty(property.getValue().getName()); |
119 | 123 | if (prevProperty == null) { |
120 | 26 | previous.addProperty(property.getValue()); |
121 | 26 | } else { |
122 | 97 | ManagedPropertyRule.merge(property.getValue(), prevProperty); |
123 | |
} |
124 | 123 | } |
125 | 60 | if (config.getListEntries() != null) { |
126 | |
if (previous.getListEntries() != null) { |
127 | |
ListEntriesRule.merge(config.getListEntries(), previous.getListEntries()); |
128 | |
} else { |
129 | |
previous.setListEntries(config.getListEntries()); |
130 | |
} |
131 | |
} |
132 | 60 | if (config.getMapEntries() != null) { |
133 | |
if (previous.getMapEntries() != null) { |
134 | |
MapEntriesRule.merge(config.getMapEntries(), previous.getMapEntries()); |
135 | |
} else { |
136 | |
previous.setMapEntries(config.getMapEntries()); |
137 | |
} |
138 | |
} |
139 | |
|
140 | 60 | } |
141 | |
|
142 | |
|
143 | |
} |