01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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.lifecycle;
20:
21: import javax.faces.FacesException;
22: import javax.faces.lifecycle.Lifecycle;
23: import javax.faces.lifecycle.LifecycleFactory;
24: import java.util.HashMap;
25: import java.util.Iterator;
26: import java.util.Map;
27:
28: /**
29: * @author Manfred Geiler (latest modification by $Author: mbr $)
30: * @author Anton Koinov
31: * @version $Revision: 510942 $ $Date: 2007-02-23 14:27:29 +0100 (Fr, 23 Feb 2007) $
32: */
33: public class LifecycleFactoryImpl extends LifecycleFactory {
34: private final Map<String, Lifecycle> _lifecycles = new HashMap<String, Lifecycle>();
35:
36: public LifecycleFactoryImpl() {
37: addLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE,
38: new LifecycleImpl());
39: }
40:
41: public void addLifecycle(String id, Lifecycle lifecycle) {
42: synchronized (_lifecycles) {
43: if (_lifecycles.get(id) != null) {
44: throw new IllegalArgumentException(
45: "Lifecycle with id '" + id
46: + "' already exists.");
47: }
48: _lifecycles.put(id, lifecycle);
49: }
50: }
51:
52: public Lifecycle getLifecycle(String id) throws FacesException {
53: synchronized (_lifecycles) {
54: Lifecycle lifecycle = _lifecycles.get(id);
55: if (lifecycle == null) {
56: throw new IllegalArgumentException(
57: "Unknown lifecycle '" + id + "'.");
58: }
59: return lifecycle;
60: }
61: }
62:
63: public Iterator<String> getLifecycleIds() {
64: return _lifecycles.keySet().iterator();
65: }
66: }
|