View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.config.impl.digester.elements;
20  
21  import java.io.Serializable;
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.HashMap;
25  import java.util.List;
26  import java.util.Map;
27  import org.apache.myfaces.config.element.AbsoluteOrdering;
28  import org.apache.myfaces.config.element.Application;
29  import org.apache.myfaces.config.element.Behavior;
30  import org.apache.myfaces.config.element.ComponentTagDeclaration;
31  import org.apache.myfaces.config.element.Converter;
32  import org.apache.myfaces.config.element.FacesConfigExtension;
33  import org.apache.myfaces.config.element.FacesFlowDefinition;
34  import org.apache.myfaces.config.element.Factory;
35  import org.apache.myfaces.config.element.ManagedBean;
36  import org.apache.myfaces.config.element.NamedEvent;
37  import org.apache.myfaces.config.element.NavigationRule;
38  import org.apache.myfaces.config.element.Ordering;
39  import org.apache.myfaces.config.element.RenderKit;
40  import org.apache.myfaces.config.element.facelets.FaceletTagLibrary;
41  
42  /**
43   * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
44   */
45  public class FacesConfigImpl extends org.apache.myfaces.config.element.FacesConfig implements Serializable
46  {
47  
48      private List<Application> applications;
49      private List<Factory> factories;
50      private Map<String, String> components;
51      private Map<String, ComponentTagDeclaration> componentTagDeclarations;
52      private List<Converter> converters;
53      private List<ManagedBean> managedBeans;
54      private List<NavigationRule> navigationRules;
55      private List<RenderKit> renderKits;
56      private List<String> lifecyclePhaseListener;
57      private Map<String, String> validators;
58      private List<Behavior> behaviors;
59      private List<NamedEvent> namedEvents;
60      private List<FacesConfigExtension> facesConfigExtensions;
61      private List <FacesFlowDefinition> facesFlowDefinitions;
62      private List <String> protectedViewsUrlPatternList;
63      private List <String> resourceResolvers;
64      private List<FaceletTagLibrary> faceletTagLibraryList;
65      
66      private transient List<Application> unmodifiableApplications;
67      private transient List<Factory> unmodifiableFactories;
68      private transient Map<String, String> unmodifiableComponents;
69      private transient Map<String, ComponentTagDeclaration> unmodifiableComponentTagDeclarations;
70      private transient List<Converter> unmodifiableConverters;
71      private transient List<ManagedBean> unmodifiableManagedBeans;
72      private transient List<NavigationRule> unmodifiableNavigationRules;
73      private transient List<RenderKit> unmodifiableRenderKits;
74      private transient List<String> unmodifiableLifecyclePhaseListener;
75      private transient Map<String, String> unmodifiableValidators;
76      private transient List<Behavior> unmodifiableBehaviors;
77      private transient List<NamedEvent> unmodifiableNamedEvents;
78      private transient List<FacesConfigExtension> unmodifiableFacesConfigExtensions;
79      private transient List <FacesFlowDefinition> unmodifiableFacesFlowDefinitions;
80      private transient List <String> unmodifiableProtectedViewsUrlPatternList;
81      private transient List <String> unmodifiableResourceResolvers;
82      private transient List<FaceletTagLibrary> unmodifiableFaceletTagLibraryList;
83      
84      private String metadataComplete;
85      private String version;
86      //Ordering variables
87      //This information are not merged, and helps
88      //with preprocessing of faces-config files
89      private String name;
90      private AbsoluteOrdering absoluteOrdering;
91      private Ordering ordering;
92  
93      public void addApplication(Application application)
94      {
95          if (applications == null)
96          {
97              applications = new ArrayList<Application>();
98          }
99          applications.add(application); 
100     }
101 
102     public void addFactory(Factory factory)
103     {
104         if (factories == null)
105         {
106             factories = new ArrayList<Factory>();
107         }
108         factories.add(factory);
109     }
110 
111     public void addComponent(String componentType, String componentClass)
112     {
113         if (components == null)
114         {
115             components = new HashMap<String, String>();
116         }
117         components.put(componentType, componentClass);
118     }
119     
120     public void addComponentTagDeclaration(String componentType, 
121             ComponentTagDeclaration tagDeclaration)
122     {
123         if (componentTagDeclarations == null)
124         {
125             componentTagDeclarations = new HashMap<String, ComponentTagDeclaration>();
126         }
127         componentTagDeclarations.put(componentType, tagDeclaration);
128     }
129 
130     public void addConverter(Converter converter)
131     {
132         if (converters == null)
133         {
134             converters = new ArrayList<Converter>();
135         }
136         converters.add(converter);
137     }
138 
139     public void addManagedBean(ManagedBean bean)
140     {
141         if (managedBeans == null)
142         {
143             managedBeans = new ArrayList<ManagedBean>();
144         }
145         managedBeans.add(bean);
146     }
147 
148     public void addNavigationRule(NavigationRule rule)
149     {
150         if (navigationRules == null)
151         {
152             navigationRules = new ArrayList<NavigationRule>();
153         }
154         navigationRules.add(rule);
155     }
156 
157     public void addRenderKit(RenderKit renderKit)
158     {
159         if (renderKits == null)
160         {
161             renderKits = new ArrayList<RenderKit>();
162         }
163         renderKits.add(renderKit);
164     }
165 
166     public void addLifecyclePhaseListener(String value)
167     {
168         if (lifecyclePhaseListener == null)
169         {
170             lifecyclePhaseListener = new ArrayList<String>();
171         }
172         lifecyclePhaseListener.add(value);
173     }
174 
175     public void addValidator(String id, String validatorClass)
176     {
177         if (validators == null)
178         {
179             validators = new HashMap<String, String>();
180         }
181         validators.put(id, validatorClass);
182     }
183     
184     public void addBehavior (Behavior behavior)
185     {
186         if (behaviors == null)
187         {
188             behaviors = new ArrayList<Behavior>();
189         }
190         behaviors.add (behavior);
191     }
192     
193     public void addNamedEvent (NamedEvent namedEvent)
194     {
195         if (namedEvents == null)
196         {
197             namedEvents = new ArrayList<NamedEvent>();
198         }
199         namedEvents.add(namedEvent);
200     }
201     
202     public void addFacesConfigExtension(FacesConfigExtension elem)
203     {
204         if (facesConfigExtensions == null)
205         {
206             facesConfigExtensions = new ArrayList<FacesConfigExtension>();
207         }
208         facesConfigExtensions.add(elem);
209     }
210     
211     public void addFacesFlowDefinition(FacesFlowDefinition elem)
212     {
213         if (facesFlowDefinitions == null)
214         {
215             facesFlowDefinitions = new ArrayList<FacesFlowDefinition>();
216         }
217         facesFlowDefinitions.add(elem);
218     }
219     
220     public void addProtectedViewUrlPattern(String urlPattern)
221     {
222         if (protectedViewsUrlPatternList == null)
223         {
224             protectedViewsUrlPatternList = new ArrayList<String>();
225         }
226         protectedViewsUrlPatternList.add(urlPattern);
227     }
228     
229     public void addResourceResolver(String resourceResolverClass)
230     {
231         if (resourceResolvers == null)
232         {
233             resourceResolvers = new ArrayList<String>();
234         }
235         resourceResolvers.add(resourceResolverClass);
236     }
237 
238     public void addFaceletTagLibrary(FaceletTagLibrary library)
239     {
240         if (faceletTagLibraryList == null)
241         {
242             faceletTagLibraryList = new ArrayList<FaceletTagLibrary>();
243         }
244         faceletTagLibraryList.add(library);
245     }
246 
247     public List<Application> getApplications()
248     {
249         if (applications == null)
250         {
251             return Collections.emptyList();
252         }
253         if (unmodifiableApplications == null)
254         {
255             unmodifiableApplications = 
256                 Collections.unmodifiableList(applications);
257         }
258         return unmodifiableApplications;
259     }
260 
261     public List<Factory> getFactories()
262     {
263         if (factories == null)
264         {
265             return Collections.emptyList();
266         }
267         if (unmodifiableFactories == null)
268         {
269             unmodifiableFactories = 
270                 Collections.unmodifiableList(factories);
271         }
272         return unmodifiableFactories;
273     }
274 
275     public Map<String, String> getComponents()
276     {
277         if (components == null)
278         {
279             return Collections.emptyMap();
280         }
281         if (unmodifiableComponents == null)
282         {
283             unmodifiableComponents = 
284                 Collections.unmodifiableMap(components);
285         }
286         return unmodifiableComponents;
287     }
288     
289     public Map<String, ComponentTagDeclaration> getComponentTagDeclarations()
290     {
291         if (componentTagDeclarations == null)
292         {
293             return Collections.emptyMap();
294         }
295         if (unmodifiableComponentTagDeclarations == null)
296         {
297             unmodifiableComponentTagDeclarations = 
298                 Collections.unmodifiableMap(componentTagDeclarations);
299         }
300         return unmodifiableComponentTagDeclarations;
301     }
302 
303     public List<Converter> getConverters()
304     {
305         if (converters == null)
306         {
307             return Collections.emptyList();
308         }
309         if (unmodifiableConverters == null)
310         {
311             unmodifiableConverters = 
312                 Collections.unmodifiableList(converters);
313         }
314         return unmodifiableConverters;
315     }
316 
317     public List<ManagedBean> getManagedBeans()
318     {
319         if (managedBeans == null)
320         {
321             return Collections.emptyList();
322         }
323         if (unmodifiableManagedBeans == null)
324         {
325             unmodifiableManagedBeans = 
326                 Collections.unmodifiableList(managedBeans);
327         }
328         return unmodifiableManagedBeans;
329     }
330 
331     public List<NavigationRule> getNavigationRules()
332     {
333         if (navigationRules == null)
334         {
335             return Collections.emptyList();
336         }
337         if (unmodifiableNavigationRules == null)
338         {
339             unmodifiableNavigationRules = 
340                 Collections.unmodifiableList(navigationRules);
341         }
342         return unmodifiableNavigationRules;
343     }
344 
345     public List<RenderKit> getRenderKits()
346     {
347         if (renderKits == null)
348         {
349             return Collections.emptyList();
350         }
351         if (unmodifiableRenderKits == null)
352         {
353             unmodifiableRenderKits = 
354                 Collections.unmodifiableList(renderKits);
355         }
356         return unmodifiableRenderKits;
357     }
358 
359     public List<String> getLifecyclePhaseListener()
360     {
361         if (lifecyclePhaseListener == null)
362         {
363             return Collections.emptyList();
364         }
365         if (unmodifiableLifecyclePhaseListener == null)
366         {
367             unmodifiableLifecyclePhaseListener = 
368                 Collections.unmodifiableList(lifecyclePhaseListener);
369         }
370         return unmodifiableLifecyclePhaseListener;
371     }
372 
373     public Map<String, String> getValidators()
374     {
375         if (validators == null)
376         {
377             return Collections.emptyMap();
378         }
379         if (unmodifiableValidators == null)
380         {
381             unmodifiableValidators = 
382                 Collections.unmodifiableMap(validators);
383         }
384         return unmodifiableValidators;
385     }
386     
387     public List<Behavior> getBehaviors ()
388     {
389         if (behaviors == null)
390         {
391             return Collections.emptyList();
392         }
393         if (unmodifiableBehaviors == null)
394         {
395             unmodifiableBehaviors = 
396                 Collections.unmodifiableList(behaviors);
397         }
398         return unmodifiableBehaviors;
399     }
400     
401     public List<NamedEvent> getNamedEvents ()
402     {
403         if (namedEvents == null)
404         {
405             return Collections.emptyList();
406         }
407         if (unmodifiableNamedEvents == null)
408         {
409             unmodifiableNamedEvents = 
410                 Collections.unmodifiableList(namedEvents);
411         }
412         return unmodifiableNamedEvents;
413     }
414     
415     public RenderKit getRenderKit(String renderKitId)
416     {
417         for (RenderKit rk : getRenderKits())
418         {
419             if (renderKitId != null && renderKitId.equals(rk.getId()))
420             {
421                 return rk;
422             }
423             else if (renderKitId == null && rk.getId() == null)
424             {
425                 return rk;
426             }
427         }
428         return null;
429     }
430     
431     public String getName()
432     {
433         return name;
434     }
435 
436     public void setName(String name)
437     {
438         this.name = name;
439     }
440     
441     public org.apache.myfaces.config.element.AbsoluteOrdering getAbsoluteOrdering()
442     {
443         return absoluteOrdering;
444     }
445 
446     public void setAbsoluteOrdering(org.apache.myfaces.config.element.AbsoluteOrdering absoluteOrdering)
447     {
448         this.absoluteOrdering = absoluteOrdering;
449     }
450 
451     public org.apache.myfaces.config.element.Ordering getOrdering()
452     {
453         return ordering;
454     }
455 
456     public void setOrdering(org.apache.myfaces.config.element.Ordering ordering)
457     {
458         this.ordering = ordering;
459     }
460 
461     public String getMetadataComplete()
462     {
463         return metadataComplete;
464     }
465 
466     public void setMetadataComplete(String metadataComplete)
467     {
468         this.metadataComplete = metadataComplete;
469     }
470     
471     public String getVersion ()
472     {
473         return version;
474     }
475     
476     public void setVersion (String version)
477     {
478         this.version = version;
479     }
480 
481     @Override
482     public List<org.apache.myfaces.config.element.FacesConfigExtension> getFacesConfigExtensions()
483     {
484         if (facesConfigExtensions == null)
485         {
486             return Collections.emptyList();
487         }
488         if (unmodifiableFacesConfigExtensions == null)
489         {
490             unmodifiableFacesConfigExtensions = 
491                 Collections.unmodifiableList(facesConfigExtensions);
492         }
493         return unmodifiableFacesConfigExtensions;
494     }
495     
496     @Override
497     public List<FacesFlowDefinition> getFacesFlowDefinitions()
498     {
499         if (facesFlowDefinitions == null)
500         {
501             return Collections.emptyList();
502         }
503         if (unmodifiableFacesFlowDefinitions == null)
504         {
505             unmodifiableFacesFlowDefinitions = 
506                 Collections.unmodifiableList(facesFlowDefinitions);
507         }
508         return unmodifiableFacesFlowDefinitions;
509     }
510     
511     public List<String> getProtectedViewsUrlPatternList()
512     {
513         if (protectedViewsUrlPatternList == null)
514         {
515             return Collections.emptyList();
516         }
517         if (unmodifiableProtectedViewsUrlPatternList == null)
518         {
519             unmodifiableProtectedViewsUrlPatternList = 
520                 Collections.unmodifiableList(protectedViewsUrlPatternList);
521         }
522         return unmodifiableProtectedViewsUrlPatternList;
523     }
524     
525     public List<String> getResourceResolversList()
526     {
527         if (resourceResolvers == null)
528         {
529             return Collections.emptyList();
530         }
531         if (unmodifiableResourceResolvers == null)
532         {
533             unmodifiableResourceResolvers = 
534                 Collections.unmodifiableList(resourceResolvers);
535         }
536         return unmodifiableResourceResolvers;
537     }
538     
539     @Override
540     public List<FaceletTagLibrary> getFaceletTagLibraryList()
541     {
542         if (faceletTagLibraryList == null)
543         {
544             return Collections.emptyList();
545         }
546         if (unmodifiableFaceletTagLibraryList == null)
547         {
548             unmodifiableFaceletTagLibraryList = 
549                 Collections.unmodifiableList(faceletTagLibraryList);
550         }
551         return unmodifiableFaceletTagLibraryList;
552     }
553 }