01: /*
02: * $Id: LifecycleFactoryImpl.java,v 1.1 2005/06/16 09:13:07 dg154973 Exp $
03: */
04:
05: /*
06: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
07: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
08: */
09:
10: package com.sun.faces.portlet;
11:
12: import java.util.HashMap;
13: import java.util.Iterator;
14: import java.util.Map;
15:
16: import javax.faces.lifecycle.Lifecycle;
17: import javax.faces.lifecycle.LifecycleFactory;
18:
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21:
22: /**
23: * <p>Custom implementation of <code>LifecycleFactory</code> that
24: * provides the portlet-specific <code>Lifecycle</code> by default.</p>
25: */
26:
27: public final class LifecycleFactoryImpl extends LifecycleFactory {
28:
29: // The Log instance for this class
30: private static final Log log = LogFactory
31: .getLog(LifecycleFactoryImpl.class);
32:
33: // ------------------------------------------------------------ Constructors
34:
35: public LifecycleFactoryImpl() {
36: if (log.isTraceEnabled()) {
37: log.trace("Created LifecycleFactory " + this );
38: }
39: addLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE,
40: new LifecycleImpl());
41: }
42:
43: // ------------------------------------------------------ Instance Variables
44:
45: // Registered Lifecycle instances, keyed by lifecycle identifier
46: private Map lifecycles = new HashMap();
47:
48: // ---------------------------------------------------------- Public Methods
49:
50: public void addLifecycle(String lifecycleId, Lifecycle lifecycle) {
51:
52: if ((lifecycleId == null) || (lifecycle == null)) {
53: throw new NullPointerException();
54: }
55: synchronized (lifecycles) {
56: if (lifecycles.containsKey(lifecycleId)) {
57: throw new IllegalArgumentException(lifecycleId);
58: }
59: lifecycles.put(lifecycleId, lifecycle);
60: }
61: if (log.isTraceEnabled()) {
62: log.trace("Added LifecycleId " + lifecycleId);
63: }
64:
65: }
66:
67: public Lifecycle getLifecycle(String lifecycleId) {
68:
69: if (lifecycleId == null) {
70: throw new NullPointerException();
71: }
72: synchronized (lifecycles) {
73: Lifecycle lifecycle = (Lifecycle) lifecycles
74: .get(lifecycleId);
75: if (lifecycle != null) {
76: if (log.isTraceEnabled()) {
77: log.trace("Returned " + lifecycle
78: + " for lifecycleId " + lifecycleId);
79: }
80: return (lifecycle);
81: } else {
82: throw new IllegalArgumentException(lifecycleId);
83: }
84: }
85:
86: }
87:
88: public Iterator getLifecycleIds() {
89:
90: synchronized (lifecycles) {
91: return (lifecycles.keySet().iterator());
92: }
93:
94: }
95:
96: }
|