1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
package org.apache.tapestry.services.impl;
|
16
|
|
|
17
|
|
import java.util.HashMap;
|
18
|
|
import java.util.Iterator;
|
19
|
|
import java.util.List;
|
20
|
|
import java.util.Locale;
|
21
|
|
import java.util.Map;
|
22
|
|
|
23
|
|
import org.apache.hivemind.ApplicationRuntimeException;
|
24
|
|
import org.apache.hivemind.ClassResolver;
|
25
|
|
import org.apache.hivemind.ErrorLog;
|
26
|
|
import org.apache.hivemind.Resource;
|
27
|
|
import org.apache.hivemind.service.ThreadLocale;
|
28
|
|
import org.apache.hivemind.util.Defense;
|
29
|
|
import org.apache.tapestry.coerce.ValueConverter;
|
30
|
|
import org.apache.tapestry.describe.HTMLDescriber;
|
31
|
|
import org.apache.tapestry.engine.IPageSource;
|
32
|
|
import org.apache.tapestry.engine.IPropertySource;
|
33
|
|
import org.apache.tapestry.engine.IScriptSource;
|
34
|
|
import org.apache.tapestry.engine.ISpecificationSource;
|
35
|
|
import org.apache.tapestry.engine.state.ApplicationStateManager;
|
36
|
|
import org.apache.tapestry.error.ExceptionPresenter;
|
37
|
|
import org.apache.tapestry.error.RequestExceptionReporter;
|
38
|
|
import org.apache.tapestry.error.StaleLinkExceptionPresenter;
|
39
|
|
import org.apache.tapestry.error.StaleSessionExceptionPresenter;
|
40
|
|
import org.apache.tapestry.listener.ListenerInvoker;
|
41
|
|
import org.apache.tapestry.listener.ListenerMapSource;
|
42
|
|
import org.apache.tapestry.markup.MarkupWriterSource;
|
43
|
|
import org.apache.tapestry.services.ComponentMessagesSource;
|
44
|
|
import org.apache.tapestry.services.ComponentPropertySource;
|
45
|
|
import org.apache.tapestry.services.DataSqueezer;
|
46
|
|
import org.apache.tapestry.services.Infrastructure;
|
47
|
|
import org.apache.tapestry.services.LinkFactory;
|
48
|
|
import org.apache.tapestry.services.ObjectPool;
|
49
|
|
import org.apache.tapestry.services.RequestCycleFactory;
|
50
|
|
import org.apache.tapestry.services.ResetEventCoordinator;
|
51
|
|
import org.apache.tapestry.services.ResponseRenderer;
|
52
|
|
import org.apache.tapestry.services.ServiceMap;
|
53
|
|
import org.apache.tapestry.services.TemplateSource;
|
54
|
|
import org.apache.tapestry.spec.IApplicationSpecification;
|
55
|
|
import org.apache.tapestry.web.WebContext;
|
56
|
|
import org.apache.tapestry.web.WebContextResource;
|
57
|
|
import org.apache.tapestry.web.WebRequest;
|
58
|
|
import org.apache.tapestry.web.WebResponse;
|
59
|
|
|
60
|
|
|
61
|
|
|
62
|
|
|
63
|
|
|
64
|
|
|
65
|
|
|
66
|
|
public class InfrastructureImpl implements Infrastructure
|
67
|
|
{
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
|
private List _normalContributions;
|
72
|
|
|
73
|
|
|
74
|
|
|
75
|
|
|
76
|
|
private List _overrideContributions;
|
77
|
|
|
78
|
|
private Map _properties = new HashMap();
|
79
|
|
|
80
|
|
private boolean _initialized;
|
81
|
|
|
82
|
|
private String _mode;
|
83
|
|
|
84
|
|
private ErrorLog _errorLog;
|
85
|
|
|
86
|
|
private ClassResolver _classResolver;
|
87
|
|
|
88
|
|
private ThreadLocale _threadLocale;
|
89
|
|
|
90
|
12
|
public void setLocale(Locale locale)
|
91
|
|
{
|
92
|
12
|
_threadLocale.setLocale(locale);
|
93
|
|
}
|
94
|
|
|
95
|
45
|
public String getApplicationId()
|
96
|
|
{
|
97
|
45
|
return (String) getProperty("applicationId");
|
98
|
|
}
|
99
|
|
|
100
|
403
|
public IPropertySource getApplicationPropertySource()
|
101
|
|
{
|
102
|
403
|
return (IPropertySource) getProperty("applicationPropertySource");
|
103
|
|
}
|
104
|
|
|
105
|
51
|
public IApplicationSpecification getApplicationSpecification()
|
106
|
|
{
|
107
|
51
|
return (IApplicationSpecification) getProperty("applicationSpecification");
|
108
|
|
}
|
109
|
|
|
110
|
152
|
public ApplicationStateManager getApplicationStateManager()
|
111
|
|
{
|
112
|
152
|
return (ApplicationStateManager) getProperty("applicationStateManager");
|
113
|
|
}
|
114
|
|
|
115
|
64
|
public ClassResolver getClassResolver()
|
116
|
|
{
|
117
|
64
|
return _classResolver;
|
118
|
|
}
|
119
|
|
|
120
|
45
|
public ComponentMessagesSource getComponentMessagesSource()
|
121
|
|
{
|
122
|
45
|
return (ComponentMessagesSource) getProperty("componentMessagesSource");
|
123
|
|
}
|
124
|
|
|
125
|
45
|
public ComponentPropertySource getComponentPropertySource()
|
126
|
|
{
|
127
|
45
|
return (ComponentPropertySource) getProperty("componentPropertySource");
|
128
|
|
}
|
129
|
|
|
130
|
45
|
public String getContextPath()
|
131
|
|
{
|
132
|
45
|
return getRequest().getContextPath();
|
133
|
|
}
|
134
|
|
|
135
|
45
|
public Resource getContextRoot()
|
136
|
|
{
|
137
|
45
|
WebContext context = (WebContext) getProperty("context");
|
138
|
|
|
139
|
45
|
return new WebContextResource(context, "/");
|
140
|
|
}
|
141
|
|
|
142
|
45
|
public DataSqueezer getDataSqueezer()
|
143
|
|
{
|
144
|
45
|
return (DataSqueezer) getProperty("dataSqueezer");
|
145
|
|
}
|
146
|
|
|
147
|
0
|
public IPropertySource getGlobalPropertySource()
|
148
|
|
{
|
149
|
0
|
return (IPropertySource) getProperty("globalPropertySource");
|
150
|
|
}
|
151
|
|
|
152
|
45
|
public LinkFactory getLinkFactory()
|
153
|
|
{
|
154
|
45
|
return (LinkFactory) getProperty("linkFactory");
|
155
|
|
}
|
156
|
|
|
157
|
0
|
public ObjectPool getObjectPool()
|
158
|
|
{
|
159
|
0
|
return (ObjectPool) getProperty("objectPool");
|
160
|
|
}
|
161
|
|
|
162
|
148
|
public IPageSource getPageSource()
|
163
|
|
{
|
164
|
148
|
return (IPageSource) getProperty("pageSource");
|
165
|
|
}
|
166
|
|
|
167
|
521
|
public WebRequest getRequest()
|
168
|
|
{
|
169
|
521
|
return (WebRequest) getProperty("request");
|
170
|
|
}
|
171
|
|
|
172
|
148
|
public RequestCycleFactory getRequestCycleFactory()
|
173
|
|
{
|
174
|
148
|
return (RequestCycleFactory) getProperty("requestCycleFactory");
|
175
|
|
}
|
176
|
|
|
177
|
31
|
public RequestExceptionReporter getRequestExceptionReporter()
|
178
|
|
{
|
179
|
31
|
return (RequestExceptionReporter) getProperty("requestExceptionReporter");
|
180
|
|
}
|
181
|
|
|
182
|
0
|
public ResetEventCoordinator getResetEventCoordinator()
|
183
|
|
{
|
184
|
0
|
return (ResetEventCoordinator) getProperty("resetEventCoordinator");
|
185
|
|
}
|
186
|
|
|
187
|
200
|
public WebResponse getResponse()
|
188
|
|
{
|
189
|
200
|
return (WebResponse) getProperty("response");
|
190
|
|
}
|
191
|
|
|
192
|
47
|
public ResponseRenderer getResponseRenderer()
|
193
|
|
{
|
194
|
47
|
return (ResponseRenderer) getProperty("responseRenderer");
|
195
|
|
}
|
196
|
|
|
197
|
5
|
public IScriptSource getScriptSource()
|
198
|
|
{
|
199
|
5
|
return (IScriptSource) getProperty("scriptSource");
|
200
|
|
}
|
201
|
|
|
202
|
237
|
public ServiceMap getServiceMap()
|
203
|
|
{
|
204
|
237
|
return (ServiceMap) getProperty("serviceMap");
|
205
|
|
}
|
206
|
|
|
207
|
45
|
public ISpecificationSource getSpecificationSource()
|
208
|
|
{
|
209
|
45
|
return (ISpecificationSource) getProperty("specificationSource");
|
210
|
|
}
|
211
|
|
|
212
|
45
|
public TemplateSource getTemplateSource()
|
213
|
|
{
|
214
|
45
|
return (TemplateSource) getProperty("templateSource");
|
215
|
|
}
|
216
|
|
|
217
|
376
|
public String getOutputEncoding()
|
218
|
|
{
|
219
|
376
|
return getApplicationPropertySource().getPropertyValue(
|
220
|
|
"org.apache.tapestry.output-encoding");
|
221
|
|
}
|
222
|
|
|
223
|
45
|
public MarkupWriterSource getMarkupWriterSource()
|
224
|
|
{
|
225
|
45
|
return (MarkupWriterSource) getProperty("markupWriterSource");
|
226
|
|
}
|
227
|
|
|
228
|
15
|
public HTMLDescriber getHTMLDescriber()
|
229
|
|
{
|
230
|
15
|
return (HTMLDescriber) getProperty("HTMLDescriber");
|
231
|
|
}
|
232
|
|
|
233
|
25
|
public ExceptionPresenter getExceptionPresenter()
|
234
|
|
{
|
235
|
25
|
return (ExceptionPresenter) getProperty("exceptionPresenter");
|
236
|
|
}
|
237
|
|
|
238
|
28
|
public ListenerMapSource getListenerMapSource()
|
239
|
|
{
|
240
|
28
|
return (ListenerMapSource) getProperty("listenerMapSource");
|
241
|
|
}
|
242
|
|
|
243
|
3
|
public StaleSessionExceptionPresenter getStaleSessionExceptionPresenter()
|
244
|
|
{
|
245
|
3
|
return (StaleSessionExceptionPresenter) getProperty("staleSessionExceptionPresenter");
|
246
|
|
}
|
247
|
|
|
248
|
1
|
public StaleLinkExceptionPresenter getStaleLinkExceptionPresenter()
|
249
|
|
{
|
250
|
1
|
return (StaleLinkExceptionPresenter) getProperty("staleLinkExceptionPresenter");
|
251
|
|
}
|
252
|
|
|
253
|
45
|
public ValueConverter getValueConverter()
|
254
|
|
{
|
255
|
45
|
return (ValueConverter) getProperty("valueConverter");
|
256
|
|
}
|
257
|
|
|
258
|
25
|
public ListenerInvoker getListenerInvoker()
|
259
|
|
{
|
260
|
25
|
return (ListenerInvoker) getProperty("listenerInvoker");
|
261
|
|
}
|
262
|
|
|
263
|
2516
|
public Object getProperty(String propertyName)
|
264
|
|
{
|
265
|
2516
|
Defense.notNull(propertyName, "propertyName");
|
266
|
|
|
267
|
2516
|
if (!_initialized)
|
268
|
1
|
throw new IllegalStateException(ImplMessages.infrastructureNotInitialized());
|
269
|
|
|
270
|
2515
|
Object result = _properties.get(propertyName);
|
271
|
|
|
272
|
2515
|
if (result == null)
|
273
|
1
|
throw new ApplicationRuntimeException(ImplMessages
|
274
|
|
.missingInfrastructureProperty(propertyName));
|
275
|
|
|
276
|
2514
|
return result;
|
277
|
|
}
|
278
|
|
|
279
|
52
|
public synchronized void initialize(String mode)
|
280
|
|
{
|
281
|
52
|
Defense.notNull(mode, "mode");
|
282
|
|
|
283
|
52
|
if (_initialized)
|
284
|
1
|
throw new IllegalStateException(ImplMessages.infrastructureAlreadyInitialized(
|
285
|
|
mode,
|
286
|
|
_mode));
|
287
|
|
|
288
|
51
|
Map normalByMode = buildMapFromContributions(_normalContributions, mode);
|
289
|
51
|
Map normal = buildMapFromContributions(_normalContributions, null);
|
290
|
51
|
Map overrideByMode = buildMapFromContributions(_overrideContributions, mode);
|
291
|
51
|
Map override = buildMapFromContributions(_overrideContributions, null);
|
292
|
|
|
293
|
51
|
addToProperties(overrideByMode);
|
294
|
51
|
addToProperties(override);
|
295
|
51
|
addToProperties(normalByMode);
|
296
|
51
|
addToProperties(normal);
|
297
|
|
|
298
|
51
|
_mode = mode;
|
299
|
51
|
_initialized = true;
|
300
|
|
}
|
301
|
|
|
302
|
204
|
private Map buildMapFromContributions(List contributions, String mode)
|
303
|
|
{
|
304
|
204
|
Map result = new HashMap();
|
305
|
|
|
306
|
204
|
Iterator i = contributions.iterator();
|
307
|
204
|
while (i.hasNext())
|
308
|
|
{
|
309
|
3346
|
InfrastructureContribution ic = (InfrastructureContribution) i.next();
|
310
|
|
|
311
|
3346
|
if (!ic.matchesMode(mode))
|
312
|
1826
|
continue;
|
313
|
|
|
314
|
1520
|
String propertyName = ic.getProperty();
|
315
|
|
|
316
|
1520
|
InfrastructureContribution existing = (InfrastructureContribution) result
|
317
|
|
.get(propertyName);
|
318
|
|
|
319
|
1520
|
if (existing != null)
|
320
|
|
{
|
321
|
1
|
_errorLog.error(ImplMessages.duplicateInfrastructureContribution(ic, existing
|
322
|
|
.getLocation()), ic.getLocation(), null);
|
323
|
1
|
continue;
|
324
|
|
}
|
325
|
|
|
326
|
1519
|
result.put(propertyName, ic);
|
327
|
|
}
|
328
|
|
|
329
|
204
|
return result;
|
330
|
|
}
|
331
|
|
|
332
|
|
|
333
|
|
|
334
|
|
|
335
|
|
|
336
|
|
|
337
|
|
|
338
|
|
|
339
|
|
|
340
|
|
|
341
|
204
|
private void addToProperties(Map map)
|
342
|
|
{
|
343
|
204
|
Iterator i = map.values().iterator();
|
344
|
204
|
while (i.hasNext())
|
345
|
|
{
|
346
|
1519
|
InfrastructureContribution ic = (InfrastructureContribution) i.next();
|
347
|
1519
|
String propertyName = ic.getProperty();
|
348
|
|
|
349
|
1519
|
if (_properties.containsKey(propertyName))
|
350
|
30
|
continue;
|
351
|
|
|
352
|
1489
|
_properties.put(propertyName, ic.getObject());
|
353
|
|
}
|
354
|
|
}
|
355
|
|
|
356
|
45
|
public void setClassResolver(ClassResolver classResolver)
|
357
|
|
{
|
358
|
45
|
_classResolver = classResolver;
|
359
|
|
}
|
360
|
|
|
361
|
45
|
public void setThreadLocale(ThreadLocale threadLocale)
|
362
|
|
{
|
363
|
45
|
_threadLocale = threadLocale;
|
364
|
|
}
|
365
|
|
|
366
|
51
|
public void setNormalContributions(List normalContributions)
|
367
|
|
{
|
368
|
51
|
_normalContributions = normalContributions;
|
369
|
|
}
|
370
|
|
|
371
|
51
|
public void setOverrideContributions(List overrideContributions)
|
372
|
|
{
|
373
|
51
|
_overrideContributions = overrideContributions;
|
374
|
|
}
|
375
|
|
|
376
|
46
|
public void setErrorLog(ErrorLog errorLog)
|
377
|
|
{
|
378
|
46
|
_errorLog = errorLog;
|
379
|
|
}
|
380
|
|
}
|