1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.impl; |
16 |
| |
17 |
| import java.util.HashMap; |
18 |
| import java.util.List; |
19 |
| import java.util.Locale; |
20 |
| import java.util.Map; |
21 |
| |
22 |
| import org.apache.hivemind.ApplicationRuntimeException; |
23 |
| import org.apache.hivemind.ClassResolver; |
24 |
| import org.apache.hivemind.ErrorHandler; |
25 |
| import org.apache.hivemind.HiveMind; |
26 |
| import org.apache.hivemind.Location; |
27 |
| import org.apache.hivemind.Messages; |
28 |
| import org.apache.hivemind.internal.MessageFinder; |
29 |
| import org.apache.hivemind.internal.Module; |
30 |
| import org.apache.hivemind.internal.RegistryInfrastructure; |
31 |
| import org.apache.hivemind.internal.ServiceModelFactory; |
32 |
| import org.apache.hivemind.internal.ServicePoint; |
33 |
| import org.apache.hivemind.schema.Translator; |
34 |
| import org.apache.hivemind.service.ThreadLocale; |
35 |
| import org.apache.hivemind.util.IdUtils; |
36 |
| import org.apache.hivemind.util.ToStringBuilder; |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| public final class ModuleImpl extends BaseLocatable implements Module |
44 |
| { |
45 |
| private String _moduleId; |
46 |
| |
47 |
| |
48 |
| private String _packageName; |
49 |
| |
50 |
| private RegistryInfrastructure _registry; |
51 |
| |
52 |
| private ClassResolver _resolver; |
53 |
| |
54 |
| private Messages _messages; |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| private final Map _typeCache = new HashMap(); |
62 |
| |
63 |
254
| public List getConfiguration(String extensionPointId)
|
64 |
| { |
65 |
254
| String qualifiedId = IdUtils.qualify(_moduleId, extensionPointId);
|
66 |
| |
67 |
254
| return _registry.getConfiguration(qualifiedId, this);
|
68 |
| } |
69 |
| |
70 |
124
| public boolean isConfigurationMappable(String configurationId)
|
71 |
| { |
72 |
124
| String qualifiedId = IdUtils.qualify(_moduleId, configurationId);
|
73 |
| |
74 |
124
| return _registry.getConfigurationPoint(qualifiedId, this).areElementsMappable();
|
75 |
| } |
76 |
| |
77 |
124
| public Map getConfigurationAsMap(String configurationId)
|
78 |
| { |
79 |
124
| String qualifiedId = IdUtils.qualify(_moduleId, configurationId);
|
80 |
| |
81 |
124
| return _registry.getConfigurationPoint(qualifiedId, this).getElementsAsMap();
|
82 |
| } |
83 |
| |
84 |
497
| public String getModuleId()
|
85 |
| { |
86 |
497
| return _moduleId;
|
87 |
| } |
88 |
| |
89 |
| |
90 |
| |
91 |
264
| public void setPackageName(String packageName)
|
92 |
| { |
93 |
264
| _packageName = packageName;
|
94 |
| } |
95 |
| |
96 |
1057
| public boolean containsService(Class serviceInterface)
|
97 |
| { |
98 |
1059
| return _registry.containsService(serviceInterface, this);
|
99 |
| } |
100 |
| |
101 |
3008
| public Object getService(String serviceId, Class serviceInterface)
|
102 |
| { |
103 |
3008
| String qualifiedId = IdUtils.qualify(_moduleId, serviceId);
|
104 |
| |
105 |
3008
| return _registry.getService(qualifiedId, serviceInterface, this);
|
106 |
| } |
107 |
| |
108 |
924
| public Object getService(Class serviceInterface)
|
109 |
| { |
110 |
924
| return _registry.getService(serviceInterface, this);
|
111 |
| } |
112 |
| |
113 |
263
| public void setModuleId(String string)
|
114 |
| { |
115 |
263
| _moduleId = string;
|
116 |
| } |
117 |
| |
118 |
262
| public void setRegistry(RegistryInfrastructure registry)
|
119 |
| { |
120 |
262
| _registry = registry;
|
121 |
| } |
122 |
| |
123 |
277
| public void setClassResolver(ClassResolver resolver)
|
124 |
| { |
125 |
277
| _resolver = resolver;
|
126 |
| } |
127 |
| |
128 |
10
| public ClassResolver getClassResolver()
|
129 |
| { |
130 |
10
| return _resolver;
|
131 |
| } |
132 |
| |
133 |
307
| public synchronized Messages getMessages()
|
134 |
| { |
135 |
307
| if (_messages == null)
|
136 |
| { |
137 |
9
| ThreadLocale threadLocale = (ThreadLocale) _registry.getService(
|
138 |
| HiveMind.THREAD_LOCALE_SERVICE, |
139 |
| ThreadLocale.class, |
140 |
| this); |
141 |
| |
142 |
9
| MessageFinder finder = new MessageFinderImpl(getLocation().getResource());
|
143 |
| |
144 |
9
| _messages = new ModuleMessages(finder, threadLocale);
|
145 |
| } |
146 |
| |
147 |
307
| return _messages;
|
148 |
| } |
149 |
| |
150 |
7146
| public String expandSymbols(String input, Location location)
|
151 |
| { |
152 |
7146
| return _registry.expandSymbols(input, location);
|
153 |
| } |
154 |
| |
155 |
4
| public String toString()
|
156 |
| { |
157 |
4
| ToStringBuilder builder = new ToStringBuilder(this);
|
158 |
| |
159 |
4
| builder.append("moduleId", _moduleId);
|
160 |
4
| builder.append("classResolver", _resolver);
|
161 |
| |
162 |
4
| return builder.toString();
|
163 |
| } |
164 |
| |
165 |
510
| public ServicePoint getServicePoint(String serviceId)
|
166 |
| { |
167 |
510
| String qualifiedId = IdUtils.qualify(_moduleId, serviceId);
|
168 |
| |
169 |
510
| return _registry.getServicePoint(qualifiedId, this);
|
170 |
| } |
171 |
| |
172 |
1414
| public ServiceModelFactory getServiceModelFactory(String name)
|
173 |
| { |
174 |
1414
| return _registry.getServiceModelFactory(name);
|
175 |
| } |
176 |
| |
177 |
8883
| public Translator getTranslator(String translator)
|
178 |
| { |
179 |
8883
| return _registry.getTranslator(translator);
|
180 |
| } |
181 |
| |
182 |
11
| public Locale getLocale()
|
183 |
| { |
184 |
11
| return _registry.getLocale();
|
185 |
| } |
186 |
| |
187 |
1047
| public ErrorHandler getErrorHandler()
|
188 |
| { |
189 |
1047
| return _registry.getErrorHander();
|
190 |
| } |
191 |
| |
192 |
0
| public String valueForSymbol(String symbol)
|
193 |
| { |
194 |
0
| return _registry.valueForSymbol(symbol);
|
195 |
| } |
196 |
| |
197 |
22327
| public synchronized Class resolveType(String type)
|
198 |
| { |
199 |
22327
| Class result = (Class) _typeCache.get(type);
|
200 |
| |
201 |
22327
| if (result == null)
|
202 |
| { |
203 |
4785
| result = findTypeInClassResolver(type);
|
204 |
| |
205 |
4782
| _typeCache.put(type, result);
|
206 |
| } |
207 |
| |
208 |
22324
| return result;
|
209 |
| } |
210 |
| |
211 |
4785
| private Class findTypeInClassResolver(String type)
|
212 |
| { |
213 |
4785
| Class result = _resolver.checkForClass(type);
|
214 |
| |
215 |
4785
| if (result == null)
|
216 |
3904
| result = _resolver.checkForClass(_packageName + "." + type);
|
217 |
| |
218 |
4785
| if (result == null)
|
219 |
3
| throw new ApplicationRuntimeException(ImplMessages.unableToConvertType(
|
220 |
| type, |
221 |
| _packageName)); |
222 |
| |
223 |
4782
| return result;
|
224 |
| } |
225 |
| } |