KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > lifecycle > LifecycleFactoryImpl


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.lifecycle;
17
18 import javax.faces.FacesException;
19 import javax.faces.lifecycle.Lifecycle;
20 import javax.faces.lifecycle.LifecycleFactory;
21 import java.util.HashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Map JavaDoc;
24
25 /**
26  * @author Manfred Geiler (latest modification by $Author: matze $)
27  * @author Anton Koinov
28  * @version $Revision: 1.10 $ $Date: 2004/10/13 11:51:00 $
29  */

30 public class LifecycleFactoryImpl
31         extends LifecycleFactory
32 {
33     private final Map JavaDoc _lifecycles = new HashMap JavaDoc();
34
35     public LifecycleFactoryImpl()
36     {
37         addLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE, new LifecycleImpl());
38     }
39
40     public void addLifecycle(String JavaDoc id, Lifecycle lifecycle)
41     {
42         synchronized (_lifecycles)
43         {
44             if (_lifecycles.get(id) != null)
45             {
46                 throw new IllegalArgumentException JavaDoc("Lifecycle with id '" + id + "' already exists.");
47             }
48             _lifecycles.put(id, lifecycle);
49         }
50     }
51
52     public Lifecycle getLifecycle(String JavaDoc id)
53             throws FacesException
54     {
55         synchronized (_lifecycles)
56         {
57             Lifecycle lifecycle = (Lifecycle)_lifecycles.get(id);
58             if (lifecycle == null)
59             {
60                 throw new IllegalArgumentException JavaDoc("Unknown lifecycle '" + id + "'.");
61             }
62             return lifecycle;
63         }
64     }
65
66     public Iterator JavaDoc getLifecycleIds()
67     {
68         return _lifecycles.keySet().iterator();
69     }
70 }
71
Popular Tags