KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > reflection > DefaultNanoPicoContainer


1 /*****************************************************************************
2  * Copyright (C) NanoContainer 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 Paul Hammant *
9  *****************************************************************************/

10
11 package org.nanocontainer.reflection;
12
13 import java.io.Serializable JavaDoc;
14 import org.nanocontainer.NanoPicoContainer;
15 import org.picocontainer.ComponentMonitor;
16 import org.picocontainer.MutablePicoContainer;
17 import org.picocontainer.PicoContainer;
18 import org.picocontainer.defaults.ComponentAdapterFactory;
19 import org.picocontainer.defaults.ComponentMonitorStrategy;
20 import org.picocontainer.defaults.DefaultComponentAdapterFactory;
21 import org.picocontainer.defaults.DefaultPicoContainer;
22 import org.picocontainer.defaults.LifecycleStrategy;
23
24 /**
25  * This is a MutablePicoContainer that also supports soft composition. i.e. assembly by class name rather that class
26  * reference.
27  * <p>
28  * In terms of implementation it adopts the behaviour of DefaultPicoContainer and DefaultNanoContainer.</p>
29  *
30  * @author Paul Hammant
31  * @author Mauro Talevi
32  * @author Michael Rimov
33  * @version $Revision: 2964 $
34  */

35 public class DefaultNanoPicoContainer extends AbstractNanoPicoContainer implements NanoPicoContainer, Serializable JavaDoc,
36     ComponentMonitorStrategy {
37
38     public DefaultNanoPicoContainer(ClassLoader JavaDoc classLoader, ComponentAdapterFactory caf, PicoContainer parent) {
39         super(new DefaultPicoContainer(caf, parent), classLoader);
40     }
41
42     public DefaultNanoPicoContainer(ClassLoader JavaDoc classLoader, PicoContainer parent) {
43         super(new DefaultPicoContainer(new DefaultComponentAdapterFactory(), parent), classLoader);
44     }
45
46     public DefaultNanoPicoContainer(ClassLoader JavaDoc classLoader, PicoContainer parent, ComponentMonitor componentMonitor) {
47         super(new DefaultPicoContainer(new DefaultComponentAdapterFactory(componentMonitor), parent), classLoader);
48     }
49
50     public DefaultNanoPicoContainer(ComponentAdapterFactory caf) {
51         super(new DefaultPicoContainer(caf, null), DefaultNanoPicoContainer.class.getClassLoader());
52     }
53
54     public DefaultNanoPicoContainer(PicoContainer pc) {
55         super(new DefaultPicoContainer(pc), DefaultNanoPicoContainer.class.getClassLoader());
56     }
57
58     public DefaultNanoPicoContainer(ClassLoader JavaDoc classLoader) {
59         super(new DefaultPicoContainer(), classLoader);
60     }
61
62     public DefaultNanoPicoContainer() {
63         super(new DefaultPicoContainer(), DefaultNanoPicoContainer.class.getClassLoader());
64     }
65
66
67     /**
68      * Constructor that provides the same control over the nanocontainer lifecycle strategies
69      * as {@link DefaultPicoContainer(ComponentAdapterFactory, LifecycleStrategy, PicoContainer)}.
70      * @param componentAdapterFactory ComponentAdapterFactory
71      * @param lifecycleStrategyForInstanceRegistrations LifecycleStrategy
72      * @param parent PicoContainer may be null if there is no parent.
73      * @param cl the Classloader to use. May be null, in which case DefaultNanoPicoContainer.class.getClassLoader()
74      * will be called instead.
75      */

76     public DefaultNanoPicoContainer(ComponentAdapterFactory componentAdapterFactory,
77         LifecycleStrategy lifecycleStrategyForInstanceRegistrations, PicoContainer parent, ClassLoader JavaDoc cl) {
78
79         super(new DefaultPicoContainer(componentAdapterFactory,
80             lifecycleStrategyForInstanceRegistrations, parent),
81             //Use a default classloader if none is specified.
82
(cl != null) ? cl : DefaultNanoPicoContainer.class.getClassLoader());
83     }
84
85     /**
86      * Copy Constructor. Makes a new DefaultNanoPicoContainer with the same
87      * attributes - ClassLoader, child PicoContainer type, ComponentAdapterFactory -
88      * as the parent.
89      * <p><tt>Note:</tt> This constructor is protected because are existing scripts
90      * that call <tt>new DefaultNanoPicoContainer(PicoContainer)</tt>, and they get this
91      * constructor instead (which has different behavior).</p>
92      * @param parent The object to copy.
93      */

94     protected DefaultNanoPicoContainer(final DefaultNanoPicoContainer parent) {
95         super(parent.getDelegate().makeChildContainer(), parent.getComponentClassLoader());
96         MutablePicoContainer parentDelegate = parent.getDelegate();
97         parentDelegate.removeChildContainer(getDelegate());
98         parentDelegate.addChildContainer(this);
99     }
100
101
102     protected AbstractNanoPicoContainer createChildContainer() {
103         return new DefaultNanoPicoContainer(this);
104      }
105
106     public void changeMonitor(ComponentMonitor monitor) {
107         ((ComponentMonitorStrategy)getDelegate()).changeMonitor(monitor);
108     }
109
110     public ComponentMonitor currentMonitor() {
111         return ((ComponentMonitorStrategy)getDelegate()).currentMonitor();
112     }
113
114 }
115
Popular Tags