KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > alternatives > CachingPicoContainer


1 /*****************************************************************************
2  * Copyright (C) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Original code by the committers *
9  *****************************************************************************/

10 package org.picocontainer.alternatives;
11
12 import org.picocontainer.MutablePicoContainer;
13 import org.picocontainer.PicoContainer;
14 import org.picocontainer.LifecycleManager;
15 import org.picocontainer.defaults.CachingComponentAdapterFactory;
16 import org.picocontainer.defaults.ComponentAdapterFactory;
17 import org.picocontainer.defaults.DefaultComponentAdapterFactory;
18 import org.picocontainer.defaults.DefaultPicoContainer;
19 import org.picocontainer.defaults.DefaultLifecycleManager;
20
21 import java.io.Serializable JavaDoc;
22
23 /**
24  * <p/>
25  * The Cacing version of {@link org.picocontainer.defaults.DefaultPicoContainer}
26  * </p>
27  *
28  * @author Paul Hammant
29  * @version $Revision: 1845 $
30  */

31 public class CachingPicoContainer extends AbstractDelegatingMutablePicoContainer implements Serializable JavaDoc {
32     private LifecycleManager lifecycleManager;
33     private CachingComponentAdapterFactory caf;
34
35     /**
36      * Creates a new container with a parent container.
37      */

38     public CachingPicoContainer(CachingComponentAdapterFactory caf, PicoContainer parent, LifecycleManager lifecycleManager) {
39         super(new DefaultPicoContainer(caf, parent, lifecycleManager));
40         this.lifecycleManager = lifecycleManager;
41         this.caf = caf;
42     }
43
44     /**
45      * Creates a new container with a parent container.
46      */

47     public CachingPicoContainer(CachingComponentAdapterFactory caf, PicoContainer parent) {
48         this(caf, parent, new DefaultLifecycleManager());
49     }
50
51     public CachingPicoContainer(ComponentAdapterFactory caf, PicoContainer parent) {
52         this(new CachingComponentAdapterFactory(caf), parent);
53     }
54
55     /**
56      * Creates a new container with a parent container.
57      */

58     public CachingPicoContainer(PicoContainer parent) {
59         this(new DefaultComponentAdapterFactory(), parent);
60     }
61
62     /**
63      * Creates a new container with a parent container.
64      */

65     public CachingPicoContainer(PicoContainer parent, LifecycleManager lifecycleManager) {
66         this(new CachingComponentAdapterFactory(new DefaultComponentAdapterFactory()), parent, lifecycleManager);
67     }
68     
69     /**
70      * Creates a new container with a parent container.
71      */

72     public CachingPicoContainer(ComponentAdapterFactory caf) {
73         this(caf, null);
74     }
75
76
77     /**
78      * Creates a new container with no parent container.
79      */

80     public CachingPicoContainer() {
81         this((PicoContainer) null);
82     }
83
84
85     public MutablePicoContainer makeChildContainer() {
86         ImplementationHidingCachingPicoContainer pc = new ImplementationHidingCachingPicoContainer(caf, this, lifecycleManager);
87         getDelegate().addChildContainer(pc);
88         return pc;
89     }
90
91 }
92
Popular Tags