This project has retired. For details please refer to its
Attic page.
BasicTilesContainerFactory xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.tiles.factory;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Locale;
26
27 import org.apache.tiles.TilesContainer;
28 import org.apache.tiles.definition.DefinitionsFactory;
29 import org.apache.tiles.definition.DefinitionsReader;
30 import org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory;
31 import org.apache.tiles.definition.dao.BaseLocaleUrlDefinitionDAO;
32 import org.apache.tiles.definition.dao.DefinitionDAO;
33 import org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO;
34 import org.apache.tiles.definition.digester.DigesterDefinitionsReader;
35 import org.apache.tiles.definition.pattern.BasicPatternDefinitionResolver;
36 import org.apache.tiles.definition.pattern.PatternDefinitionResolver;
37 import org.apache.tiles.definition.pattern.PatternDefinitionResolverAware;
38 import org.apache.tiles.definition.pattern.wildcard.WildcardDefinitionPatternMatcherFactory;
39 import org.apache.tiles.evaluator.AttributeEvaluatorFactory;
40 import org.apache.tiles.evaluator.BasicAttributeEvaluatorFactory;
41 import org.apache.tiles.evaluator.impl.DirectAttributeEvaluator;
42 import org.apache.tiles.impl.BasicTilesContainer;
43 import org.apache.tiles.locale.LocaleResolver;
44 import org.apache.tiles.locale.impl.DefaultLocaleResolver;
45 import org.apache.tiles.preparer.factory.BasicPreparerFactory;
46 import org.apache.tiles.preparer.factory.PreparerFactory;
47 import org.apache.tiles.renderer.DefinitionRenderer;
48 import org.apache.tiles.request.ApplicationContext;
49 import org.apache.tiles.request.ApplicationResource;
50 import org.apache.tiles.request.render.BasicRendererFactory;
51 import org.apache.tiles.request.render.ChainedDelegateRenderer;
52 import org.apache.tiles.request.render.DispatchRenderer;
53 import org.apache.tiles.request.render.Renderer;
54 import org.apache.tiles.request.render.RendererFactory;
55 import org.apache.tiles.request.render.StringRenderer;
56
57
58
59
60
61
62
63 public class BasicTilesContainerFactory extends AbstractTilesContainerFactory {
64
65
66
67
68 protected static final String STRING_RENDERER_NAME = "string";
69
70
71
72
73 protected static final String TEMPLATE_RENDERER_NAME = "template";
74
75
76
77
78 protected static final String DEFINITION_RENDERER_NAME = "definition";
79
80
81 @Override
82 public TilesContainer createContainer(ApplicationContext applicationContext) {
83 BasicTilesContainer container = instantiateContainer(applicationContext);
84 container.setApplicationContext(applicationContext);
85 LocaleResolver resolver = createLocaleResolver(applicationContext);
86 container.setDefinitionsFactory(createDefinitionsFactory(applicationContext,
87 resolver));
88 AttributeEvaluatorFactory attributeEvaluatorFactory = createAttributeEvaluatorFactory(
89 applicationContext, resolver);
90 container.setAttributeEvaluatorFactory(attributeEvaluatorFactory);
91 container.setPreparerFactory(createPreparerFactory(applicationContext));
92 TilesContainer injectedContainer = createDecoratedContainer(container, applicationContext);
93 container.setRendererFactory(createRendererFactory(applicationContext,
94 injectedContainer, attributeEvaluatorFactory));
95 return injectedContainer;
96 }
97
98
99
100
101
102
103
104
105 protected BasicTilesContainer instantiateContainer(
106 ApplicationContext context) {
107 return new BasicTilesContainer();
108 }
109
110
111
112
113
114
115
116
117
118 protected TilesContainer createDecoratedContainer(TilesContainer originalContainer,
119 ApplicationContext context) {
120 return originalContainer;
121 }
122
123
124
125
126
127
128
129
130
131
132 protected DefinitionsFactory createDefinitionsFactory(ApplicationContext applicationContext,
133 LocaleResolver resolver) {
134 UnresolvingLocaleDefinitionsFactory factory = instantiateDefinitionsFactory(
135 applicationContext, resolver);
136 factory.setLocaleResolver(resolver);
137 factory.setDefinitionDAO(createLocaleDefinitionDao(applicationContext,
138 resolver));
139 return factory;
140 }
141
142
143
144
145
146
147
148
149 protected UnresolvingLocaleDefinitionsFactory instantiateDefinitionsFactory(
150 ApplicationContext applicationContext,
151 LocaleResolver resolver) {
152 return new UnresolvingLocaleDefinitionsFactory();
153 }
154
155
156
157
158
159
160
161
162
163 protected BaseLocaleUrlDefinitionDAO instantiateLocaleDefinitionDao(ApplicationContext applicationContext,
164 LocaleResolver resolver) {
165 ResolvingLocaleUrlDefinitionDAO dao = new ResolvingLocaleUrlDefinitionDAO(applicationContext);
166 return dao;
167 }
168
169
170
171
172
173
174
175
176 @SuppressWarnings("unchecked")
177 protected DefinitionDAO<Locale> createLocaleDefinitionDao(ApplicationContext applicationContext,
178 LocaleResolver resolver) {
179 BaseLocaleUrlDefinitionDAO definitionDao = instantiateLocaleDefinitionDao(
180 applicationContext, resolver);
181 definitionDao.setReader(createDefinitionsReader(applicationContext));
182 definitionDao.setSources(getSources(applicationContext));
183 if (definitionDao instanceof PatternDefinitionResolverAware) {
184 ((PatternDefinitionResolverAware<Locale>) definitionDao)
185 .setPatternDefinitionResolver(createPatternDefinitionResolver(Locale.class));
186 }
187 return definitionDao;
188 }
189
190
191
192
193
194
195
196
197 protected LocaleResolver createLocaleResolver(ApplicationContext applicationContext) {
198 return new DefaultLocaleResolver();
199 }
200
201
202
203
204
205
206
207
208 protected DefinitionsReader createDefinitionsReader(
209 ApplicationContext applicationContext) {
210 return new DigesterDefinitionsReader();
211 }
212
213
214
215
216
217
218
219
220 protected List<ApplicationResource> getSources(ApplicationContext applicationContext) {
221 List<ApplicationResource> retValue = new ArrayList<ApplicationResource>(1);
222 retValue.add(applicationContext.getResource("/WEB-INF/tiles.xml"));
223 return retValue;
224 }
225
226
227
228
229
230
231
232
233
234
235
236 protected AttributeEvaluatorFactory createAttributeEvaluatorFactory(
237 ApplicationContext applicationContext,
238 LocaleResolver resolver) {
239 return new BasicAttributeEvaluatorFactory(new DirectAttributeEvaluator());
240 }
241
242
243
244
245
246
247
248
249 protected PreparerFactory createPreparerFactory(ApplicationContext applicationContext) {
250 return new BasicPreparerFactory();
251 }
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266 protected RendererFactory createRendererFactory(ApplicationContext applicationContext,
267 TilesContainer container,
268 AttributeEvaluatorFactory attributeEvaluatorFactory) {
269 BasicRendererFactory retValue = new BasicRendererFactory();
270 registerAttributeRenderers(retValue, applicationContext, container,
271 attributeEvaluatorFactory);
272 retValue.setDefaultRenderer(createDefaultAttributeRenderer(retValue,
273 applicationContext, container, attributeEvaluatorFactory));
274 return retValue;
275 }
276
277
278
279
280
281
282
283
284
285
286
287
288 protected Renderer createDefaultAttributeRenderer(
289 BasicRendererFactory rendererFactory,
290 ApplicationContext applicationContext,
291 TilesContainer container,
292 AttributeEvaluatorFactory attributeEvaluatorFactory) {
293 ChainedDelegateRenderer retValue = new ChainedDelegateRenderer();
294 retValue.addAttributeRenderer(rendererFactory.getRenderer(DEFINITION_RENDERER_NAME));
295 retValue.addAttributeRenderer(rendererFactory.getRenderer(TEMPLATE_RENDERER_NAME));
296 retValue.addAttributeRenderer(rendererFactory.getRenderer(STRING_RENDERER_NAME));
297 return retValue;
298 }
299
300
301
302
303
304
305
306
307
308
309
310
311 protected <T> PatternDefinitionResolver<T> createPatternDefinitionResolver(
312 Class<T> customizationKeyClass) {
313 WildcardDefinitionPatternMatcherFactory definitionPatternMatcherFactory =
314 new WildcardDefinitionPatternMatcherFactory();
315 return new BasicPatternDefinitionResolver<T>(
316 definitionPatternMatcherFactory,
317 definitionPatternMatcherFactory);
318 }
319
320
321
322
323
324
325
326
327
328
329
330
331 protected void registerAttributeRenderers(
332 BasicRendererFactory rendererFactory,
333 ApplicationContext applicationContext,
334 TilesContainer container,
335 AttributeEvaluatorFactory attributeEvaluatorFactory) {
336 rendererFactory.registerRenderer(STRING_RENDERER_NAME,
337 createStringAttributeRenderer(rendererFactory,
338 applicationContext, container, attributeEvaluatorFactory));
339 rendererFactory.registerRenderer(TEMPLATE_RENDERER_NAME,
340 createTemplateAttributeRenderer(rendererFactory,
341 applicationContext, container, attributeEvaluatorFactory));
342 rendererFactory.registerRenderer(DEFINITION_RENDERER_NAME,
343 createDefinitionAttributeRenderer(rendererFactory,
344 applicationContext, container, attributeEvaluatorFactory));
345 }
346
347
348
349
350
351
352
353
354
355
356
357 protected Renderer createStringAttributeRenderer(
358 BasicRendererFactory rendererFactory,
359 ApplicationContext applicationContext,
360 TilesContainer container,
361 AttributeEvaluatorFactory attributeEvaluatorFactory) {
362 return new StringRenderer();
363 }
364
365
366
367
368
369
370
371
372
373
374
375 protected Renderer createTemplateAttributeRenderer(
376 BasicRendererFactory rendererFactory,
377 ApplicationContext applicationContext,
378 TilesContainer container,
379 AttributeEvaluatorFactory attributeEvaluatorFactory) {
380 return new DispatchRenderer();
381 }
382
383
384
385
386
387
388
389
390
391
392
393 protected Renderer createDefinitionAttributeRenderer(
394 BasicRendererFactory rendererFactory,
395 ApplicationContext applicationContext,
396 TilesContainer container,
397 AttributeEvaluatorFactory attributeEvaluatorFactory) {
398 return new DefinitionRenderer(container);
399 }
400 }