KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > config > impl > digester > DigesterFacesConfigDispenserImpl


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.config.impl.digester;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collections JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import javax.faces.render.RenderKitFactory;
26
27 import org.apache.myfaces.config.FacesConfigDispenser;
28 import org.apache.myfaces.config.impl.digester.elements.Application;
29 import org.apache.myfaces.config.impl.digester.elements.Converter;
30 import org.apache.myfaces.config.impl.digester.elements.FacesConfig;
31 import org.apache.myfaces.config.impl.digester.elements.Factory;
32 import org.apache.myfaces.config.impl.digester.elements.LocaleConfig;
33 import org.apache.myfaces.config.impl.digester.elements.RenderKit;
34
35
36 /**
37  * @author <a HREF="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
38  *
39  * $Log: DigesterFacesConfigDispenserImpl.java,v $
40  * Revision 1.4 2005/03/04 00:28:45 mmarinschek
41  * Changes in configuration due to missing Attribute/Property classes for the converter; not building in the functionality yet except for part of the converter properties
42  *
43  * Revision 1.3 2004/10/13 11:50:59 matze
44  * renamed packages to org.apache
45  *
46  * Revision 1.2 2004/07/10 13:55:42 mwessendorf
47  * imports
48  *
49  * Revision 1.1 2004/07/07 00:25:05 o_rossmueller
50  * tidy up config/confignew package (moved confignew classes to package config)
51  *
52  */

53 public class DigesterFacesConfigDispenserImpl implements FacesConfigDispenser
54 {
55
56     private List JavaDoc configs = new ArrayList JavaDoc();
57     private List JavaDoc applicationFactories = new ArrayList JavaDoc();
58     private List JavaDoc facesContextFactories = new ArrayList JavaDoc();
59     private List JavaDoc lifecycleFactories = new ArrayList JavaDoc();
60     private List JavaDoc renderKitFactories = new ArrayList JavaDoc();
61     private Map JavaDoc components = new HashMap JavaDoc();
62     private Map JavaDoc validators = new HashMap JavaDoc();
63     private String JavaDoc defaultRenderKitId;
64     private LocaleConfig localeConfig;
65     private List JavaDoc actionListeners = new ArrayList JavaDoc();
66     private List JavaDoc lifecyclePhaseListeners = new ArrayList JavaDoc();
67     private String JavaDoc messageBundle;
68     private List JavaDoc navigationHandlers = new ArrayList JavaDoc();
69     private List JavaDoc viewHandlers = new ArrayList JavaDoc();
70     private List JavaDoc stateManagers = new ArrayList JavaDoc();
71     private List JavaDoc propertyResolver = new ArrayList JavaDoc();
72     private List JavaDoc variableResolver = new ArrayList JavaDoc();
73     private Map JavaDoc converterById = new HashMap JavaDoc();
74     private Map JavaDoc converterByClass = new HashMap JavaDoc();
75     private Map JavaDoc converterConfigurationByClassName = new HashMap JavaDoc();
76     private Map JavaDoc renderKits = new HashMap JavaDoc();
77     private List JavaDoc managedBeans = new ArrayList JavaDoc();
78     private List JavaDoc navigationRules = new ArrayList JavaDoc();
79
80
81     /**
82      * Add another unmarshalled faces config object.
83      *
84      * @param facesConfig unmarshalled faces config object
85      */

86     public void feed(Object JavaDoc facesConfig)
87     {
88         FacesConfig config = (FacesConfig) facesConfig;
89         configs.add(config);
90         for (Iterator JavaDoc iterator = config.getFactories().iterator(); iterator.hasNext();)
91         {
92             Factory factory = (Factory) iterator.next();
93             applicationFactories.addAll(factory.getApplicationFactory());
94             facesContextFactories.addAll(factory.getFacesContextFactory());
95             lifecycleFactories.addAll(factory.getLifecycleFactory());
96             renderKitFactories.addAll(factory.getRenderkitFactory());
97         }
98         components.putAll(config.getComponents());
99         validators.putAll(config.getValidators());
100
101         for (Iterator JavaDoc iterator = config.getApplications().iterator(); iterator.hasNext();)
102         {
103             Application application = (Application) iterator.next();
104             if (!application.getDefaultRenderkitId().isEmpty())
105             {
106                 defaultRenderKitId = (String JavaDoc) application.getDefaultRenderkitId().get(application.getDefaultRenderkitId().size() - 1);
107             }
108             if (!application.getMessageBundle().isEmpty())
109             {
110                 messageBundle = (String JavaDoc) application.getMessageBundle().get(application.getMessageBundle().size() - 1);
111             }
112             if (!application.getLocaleConfig().isEmpty())
113             {
114                 localeConfig = (LocaleConfig) application.getLocaleConfig().get(application.getLocaleConfig().size() - 1);
115             }
116             actionListeners.addAll(application.getActionListener());
117             navigationHandlers.addAll(application.getNavigationHandler());
118             viewHandlers.addAll(application.getViewHandler());
119             stateManagers.addAll(application.getStateManager());
120             propertyResolver.addAll(application.getPropertyResolver());
121             variableResolver.addAll(application.getVariableResolver());
122         }
123         for (Iterator JavaDoc iterator = config.getConverters().iterator(); iterator.hasNext();)
124         {
125             Converter converter = (Converter) iterator.next();
126
127             if (converter.getConverterId() != null)
128             {
129                 converterById.put(converter.getConverterId(), converter.getConverterClass());
130             }
131             else
132             {
133                 converterByClass.put(converter.getForClass(), converter.getConverterClass());
134             }
135
136             converterConfigurationByClassName.put(converter.getConverterClass(),converter);
137         }
138
139         for (Iterator JavaDoc iterator = config.getRenderKits().iterator(); iterator.hasNext();)
140         {
141             RenderKit renderKit = (RenderKit) iterator.next();
142             String JavaDoc renderKitId = renderKit.getId();
143
144             if (renderKitId == null) {
145                 renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
146             }
147
148             RenderKit existing = (RenderKit) renderKits.get(renderKitId);
149
150             if (existing == null) {
151                 renderKits.put(renderKit.getId(), renderKit);
152             } else {
153                 existing.merge(renderKit);
154             }
155         }
156         lifecyclePhaseListeners.addAll(config.getLifecyclePhaseListener());
157         managedBeans.addAll(config.getManagedBeans());
158         navigationRules.addAll(config.getNavigationRules());
159     }
160
161
162     /**
163      * Add another ApplicationFactory class name
164      *
165      * @param factoryClassName a class name
166      */

167     public void feedApplicationFactory(String JavaDoc factoryClassName)
168     {
169         applicationFactories.add(factoryClassName);
170     }
171
172
173     /**
174      * Add another FacesContextFactory class name
175      *
176      * @param factoryClassName a class name
177      */

178     public void feedFacesContextFactory(String JavaDoc factoryClassName)
179     {
180         lifecycleFactories.add(factoryClassName);
181     }
182
183
184     /**
185      * Add another LifecycleFactory class name
186      *
187      * @param factoryClassName a class name
188      */

189     public void feedLifecycleFactory(String JavaDoc factoryClassName)
190     {
191         lifecycleFactories.add(factoryClassName);
192     }
193
194
195     /**
196      * Add another RenderKitFactory class name
197      *
198      * @param factoryClassName a class name
199      */

200     public void feedRenderKitFactory(String JavaDoc factoryClassName)
201     {
202         renderKitFactories.add(factoryClassName);
203     }
204
205
206     /**
207      * @return Iterator over ApplicationFactory class names
208      */

209     public Iterator JavaDoc getApplicationFactoryIterator()
210     {
211         return applicationFactories.iterator();
212     }
213
214
215     /**
216      * @return Iterator over FacesContextFactory class names
217      */

218     public Iterator JavaDoc getFacesContextFactoryIterator()
219     {
220         return facesContextFactories.iterator();
221     }
222
223
224     /**
225      * @return Iterator over LifecycleFactory class names
226      */

227     public Iterator JavaDoc getLifecycleFactoryIterator()
228     {
229         return lifecycleFactories.iterator();
230     }
231
232
233     /**
234      * @return Iterator over RenderKit factory class names
235      */

236     public Iterator JavaDoc getRenderKitFactoryIterator()
237     {
238         return renderKitFactories.iterator();
239     }
240
241
242     /**
243      * @return Iterator over ActionListener class names
244      */

245     public Iterator JavaDoc getActionListenerIterator()
246     {
247         List JavaDoc listeners = new ArrayList JavaDoc(actionListeners);
248         return listeners.iterator();
249     }
250
251
252     /**
253      * @return the default render kit id
254      */

255     public String JavaDoc getDefaultRenderKitId()
256     {
257         return defaultRenderKitId;
258     }
259
260
261     /**
262      * @return Iterator over message bundle names
263      */

264     public String JavaDoc getMessageBundle()
265     {
266         return messageBundle;
267     }
268
269
270     /**
271      * @return Iterator over NavigationHandler class names
272      */

273     public Iterator JavaDoc getNavigationHandlerIterator()
274     {
275         List JavaDoc handlers = new ArrayList JavaDoc(navigationHandlers);
276         return handlers.iterator();
277     }
278
279
280     /**
281      * @return Iterator over ViewHandler class names
282      */

283     public Iterator JavaDoc getViewHandlerIterator()
284     {
285         List JavaDoc handlers = new ArrayList JavaDoc(viewHandlers);
286         return handlers.iterator();
287     }
288
289
290     /**
291      * @return Iterator over StateManager class names
292      */

293     public Iterator JavaDoc getStateManagerIterator()
294     {
295         List JavaDoc managers = new ArrayList JavaDoc(stateManagers);
296         return managers.iterator();
297     }
298
299
300     /**
301      * @return Iterator over PropertyResolver class names
302      */

303     public Iterator JavaDoc getPropertyResolverIterator()
304     {
305         List JavaDoc resolver = new ArrayList JavaDoc(propertyResolver);
306         return resolver.iterator();
307     }
308
309
310     /**
311      * @return Iterator over VariableResolver class names
312      */

313     public Iterator JavaDoc getVariableResolverIterator()
314     {
315         List JavaDoc resolver = new ArrayList JavaDoc(variableResolver);
316
317         return resolver.iterator();
318     }
319
320
321     /**
322      * @return the default locale name
323      */

324     public String JavaDoc getDefaultLocale()
325     {
326         if (localeConfig != null)
327         {
328             return localeConfig.getDefaultLocale();
329         }
330         return null;
331     }
332
333
334     /**
335      * @return Iterator over supported locale names
336      */

337     public Iterator JavaDoc getSupportedLocalesIterator()
338     {
339         if (localeConfig != null)
340         {
341             return localeConfig.getSupportedLocales().iterator();
342         }
343         return Collections.EMPTY_LIST.iterator();
344     }
345
346
347     /**
348      * @return Iterator over all defined component types
349      */

350     public Iterator JavaDoc getComponentTypes()
351     {
352         return components.keySet().iterator();
353     }
354
355
356     /**
357      * @return component class that belongs to the given component type
358      */

359     public String JavaDoc getComponentClass(String JavaDoc componentType)
360     {
361         return (String JavaDoc) components.get(componentType);
362     }
363
364
365     /**
366      * @return Iterator over all defined converter ids
367      */

368     public Iterator JavaDoc getConverterIds()
369     {
370         return converterById.keySet().iterator();
371     }
372
373
374     /**
375      * @return Iterator over all classes with an associated converter
376      */

377     public Iterator JavaDoc getConverterClasses()
378     {
379         return converterByClass.keySet().iterator();
380     }
381
382     public Iterator JavaDoc getConverterConfigurationByClassName()
383     {
384         return converterConfigurationByClassName.keySet().iterator();
385     }
386
387     public Converter getConverterConfiguration(String JavaDoc converterClassName)
388     {
389         return (Converter) converterConfigurationByClassName.get(converterClassName);
390     }
391
392
393     /**
394      * @return converter class that belongs to the given converter id
395      */

396     public String JavaDoc getConverterClassById(String JavaDoc converterId)
397     {
398         return (String JavaDoc) converterById.get(converterId);
399     }
400
401
402     /**
403      * @return converter class that is associated with the given class name
404      */

405     public String JavaDoc getConverterClassByClass(String JavaDoc className)
406     {
407         return (String JavaDoc) converterByClass.get(className);
408     }
409
410
411     /**
412      * @return Iterator over all defined validator ids
413      */

414     public Iterator JavaDoc getValidatorIds()
415     {
416         return validators.keySet().iterator();
417     }
418
419
420     /**
421      * @return validator class name that belongs to the given validator id
422      */

423     public String JavaDoc getValidatorClass(String JavaDoc validatorId)
424     {
425         return (String JavaDoc) validators.get(validatorId);
426     }
427
428
429     /**
430      * @return Iterator over {@link org.apache.myfaces.config.element.ManagedBean ManagedBean}s
431      */

432     public Iterator JavaDoc getManagedBeans()
433     {
434         return managedBeans.iterator();
435     }
436
437
438     /**
439      * @return Iterator over {@link org.apache.myfaces.config.element.NavigationRule NavigationRule}s
440      */

441     public Iterator JavaDoc getNavigationRules()
442     {
443         return navigationRules.iterator();
444     }
445
446
447     /**
448      * @return Iterator over all defined renderkit ids
449      */

450     public Iterator JavaDoc getRenderKitIds()
451     {
452         return renderKits.keySet().iterator();
453     }
454
455
456     /**
457      * @return renderkit class name for given renderkit id
458      */

459     public String JavaDoc getRenderKitClass(String JavaDoc renderKitId)
460     {
461         RenderKit renderKit = (RenderKit) renderKits.get(renderKitId);
462         return renderKit.getRenderKitClass();
463     }
464
465
466     /**
467      * @return Iterator over {@link org.apache.myfaces.config.element.Renderer Renderer}s for the given renderKitId
468      */

469     public Iterator JavaDoc getRenderers(String JavaDoc renderKitId)
470     {
471         RenderKit renderKit = (RenderKit) renderKits.get(renderKitId);
472         return renderKit.getRenderer().iterator();
473     }
474
475
476     /**
477      * @return Iterator over {@link javax.faces.event.PhaseListener} implementation class names
478      */

479     public Iterator JavaDoc getLifecyclePhaseListeners()
480     {
481         return lifecyclePhaseListeners.iterator();
482     }
483
484 }
485
Popular Tags