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.List; |
18 |
| import java.util.Locale; |
19 |
| import java.util.Map; |
20 |
| |
21 |
| import org.apache.hivemind.ApplicationRuntimeException; |
22 |
| import org.apache.hivemind.ClassResolver; |
23 |
| import org.apache.hivemind.ErrorHandler; |
24 |
| import org.apache.hivemind.HiveMind; |
25 |
| import org.apache.hivemind.Location; |
26 |
| import org.apache.hivemind.Messages; |
27 |
| import org.apache.hivemind.internal.MessageFinder; |
28 |
| import org.apache.hivemind.internal.Module; |
29 |
| import org.apache.hivemind.internal.RegistryInfrastructure; |
30 |
| import org.apache.hivemind.internal.ServiceModelFactory; |
31 |
| import org.apache.hivemind.internal.ServicePoint; |
32 |
| import org.apache.hivemind.schema.Translator; |
33 |
| import org.apache.hivemind.service.ThreadLocale; |
34 |
| import org.apache.hivemind.util.IdUtils; |
35 |
| import org.apache.hivemind.util.ToStringBuilder; |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| public final class ModuleImpl extends BaseLocatable implements Module |
43 |
| { |
44 |
| private String _moduleId; |
45 |
| |
46 |
| |
47 |
| private String _packageName; |
48 |
| |
49 |
| private RegistryInfrastructure _registry; |
50 |
| |
51 |
| private ClassResolver _resolver; |
52 |
| |
53 |
| private Messages _messages; |
54 |
| |
55 |
252
| public List getConfiguration(String extensionPointId)
|
56 |
| { |
57 |
252
| String qualifiedId = IdUtils.qualify(_moduleId, extensionPointId);
|
58 |
| |
59 |
252
| return _registry.getConfiguration(qualifiedId, this);
|
60 |
| } |
61 |
| |
62 |
123
| public boolean canConfigurationBeMapped(String configurationId)
|
63 |
| { |
64 |
123
| String qualifiedId = IdUtils.qualify(_moduleId, configurationId);
|
65 |
| |
66 |
123
| return _registry.getConfigurationPoint(qualifiedId, this).canElementsBeMapped();
|
67 |
| } |
68 |
| |
69 |
123
| public Map getMappedConfiguration(String configurationId)
|
70 |
| { |
71 |
123
| String qualifiedId = IdUtils.qualify(_moduleId, configurationId);
|
72 |
| |
73 |
123
| return _registry.getConfigurationPoint(qualifiedId, this).getMappedElements();
|
74 |
| } |
75 |
| |
76 |
493
| public String getModuleId()
|
77 |
| { |
78 |
493
| return _moduleId;
|
79 |
| } |
80 |
| |
81 |
| |
82 |
| |
83 |
261
| public void setPackageName(String packageName)
|
84 |
| { |
85 |
261
| _packageName = packageName;
|
86 |
| } |
87 |
| |
88 |
272
| public boolean containsService(Class serviceInterface)
|
89 |
| { |
90 |
272
| return _registry.containsService(serviceInterface, this);
|
91 |
| } |
92 |
| |
93 |
2984
| public Object getService(String serviceId, Class serviceInterface)
|
94 |
| { |
95 |
2984
| String qualifiedId = IdUtils.qualify(_moduleId, serviceId);
|
96 |
| |
97 |
2984
| return _registry.getService(qualifiedId, serviceInterface, this);
|
98 |
| } |
99 |
| |
100 |
138
| public Object getService(Class serviceInterface)
|
101 |
| { |
102 |
138
| return _registry.getService(serviceInterface, this);
|
103 |
| } |
104 |
| |
105 |
260
| public void setModuleId(String string)
|
106 |
| { |
107 |
260
| _moduleId = string;
|
108 |
| } |
109 |
| |
110 |
260
| public void setRegistry(RegistryInfrastructure registry)
|
111 |
| { |
112 |
260
| _registry = registry;
|
113 |
| } |
114 |
| |
115 |
273
| public void setClassResolver(ClassResolver resolver)
|
116 |
| { |
117 |
273
| _resolver = resolver;
|
118 |
| } |
119 |
| |
120 |
10
| public ClassResolver getClassResolver()
|
121 |
| { |
122 |
10
| return _resolver;
|
123 |
| } |
124 |
| |
125 |
45
| public synchronized Messages getMessages()
|
126 |
| { |
127 |
45
| if (_messages == null)
|
128 |
| { |
129 |
9
| ThreadLocale threadLocale = (ThreadLocale) _registry.getService(
|
130 |
| HiveMind.THREAD_LOCALE_SERVICE, |
131 |
| ThreadLocale.class, |
132 |
| this); |
133 |
| |
134 |
9
| MessageFinder finder = new MessageFinderImpl(getLocation().getResource());
|
135 |
| |
136 |
9
| _messages = new ModuleMessages(finder, threadLocale);
|
137 |
| } |
138 |
| |
139 |
45
| return _messages;
|
140 |
| } |
141 |
| |
142 |
7107
| public String expandSymbols(String input, Location location)
|
143 |
| { |
144 |
7107
| return _registry.expandSymbols(input, location);
|
145 |
| } |
146 |
| |
147 |
4
| public String toString()
|
148 |
| { |
149 |
4
| ToStringBuilder builder = new ToStringBuilder(this);
|
150 |
| |
151 |
4
| builder.append("moduleId", _moduleId);
|
152 |
4
| builder.append("classResolver", _resolver);
|
153 |
| |
154 |
4
| return builder.toString();
|
155 |
| } |
156 |
| |
157 |
511
| public ServicePoint getServicePoint(String serviceId)
|
158 |
| { |
159 |
511
| String qualifiedId = IdUtils.qualify(_moduleId, serviceId);
|
160 |
| |
161 |
511
| return _registry.getServicePoint(qualifiedId, this);
|
162 |
| } |
163 |
| |
164 |
1403
| public ServiceModelFactory getServiceModelFactory(String name)
|
165 |
| { |
166 |
1403
| return _registry.getServiceModelFactory(name);
|
167 |
| } |
168 |
| |
169 |
8835
| public Translator getTranslator(String translator)
|
170 |
| { |
171 |
8835
| return _registry.getTranslator(translator);
|
172 |
| } |
173 |
| |
174 |
11
| public Locale getLocale()
|
175 |
| { |
176 |
11
| return _registry.getLocale();
|
177 |
| } |
178 |
| |
179 |
1043
| public ErrorHandler getErrorHandler()
|
180 |
| { |
181 |
1043
| return _registry.getErrorHander();
|
182 |
| } |
183 |
| |
184 |
0
| public String valueForSymbol(String symbol)
|
185 |
| { |
186 |
0
| return _registry.valueForSymbol(symbol);
|
187 |
| } |
188 |
| |
189 |
10030
| public Class resolveType(String type)
|
190 |
| { |
191 |
10030
| Class result = _resolver.checkForClass(type);
|
192 |
| |
193 |
10030
| if (result == null)
|
194 |
8440
| result = _resolver.checkForClass(_packageName + "." + type);
|
195 |
| |
196 |
10030
| if (result == null)
|
197 |
3
| throw new ApplicationRuntimeException(ImplMessages.unableToConvertType(
|
198 |
| type, |
199 |
| _packageName)); |
200 |
| |
201 |
10027
| return result;
|
202 |
| } |
203 |
| } |