KickJava   Java API By Example, From Geeks To Geeks.

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


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 Paul Hammant *
9  *****************************************************************************/

10 package org.picocontainer.alternatives;
11
12 import org.picocontainer.ComponentAdapter;
13 import org.picocontainer.PicoContainer;
14 import org.picocontainer.PicoException;
15 import org.picocontainer.PicoVerificationException;
16 import org.picocontainer.PicoVisitor;
17
18 import java.io.Serializable JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.List JavaDoc;
21
22 // TODO: replace this with a proxy? It don't do nothing! (AH)
23
// Am open to elegant solution. This, at least, is instantiable (PH)
24

25 /**
26  * @author Paul Hammant
27  * @version $Revision: 1731 $
28  * @since 1.1
29  */

30 public class ImmutablePicoContainer implements PicoContainer, Serializable JavaDoc {
31
32     private PicoContainer delegate;
33
34     public ImmutablePicoContainer(PicoContainer delegate) {
35         if(delegate == null) throw new NullPointerException JavaDoc("You must pass in a picoContainer instance");
36         this.delegate = delegate;
37     }
38
39     public Object JavaDoc getComponentInstance(Object JavaDoc componentKey) {
40         return delegate.getComponentInstance(componentKey);
41     }
42
43     public Object JavaDoc getComponentInstanceOfType(Class JavaDoc componentType) {
44         return delegate.getComponentInstanceOfType(componentType);
45     }
46
47     public List JavaDoc getComponentInstances() {
48         return delegate.getComponentInstances();
49     }
50
51     public synchronized PicoContainer getParent() {
52         return delegate.getParent();
53     }
54
55     public ComponentAdapter getComponentAdapter(Object JavaDoc componentKey) {
56         return delegate.getComponentAdapter(componentKey);
57     }
58
59     public ComponentAdapter getComponentAdapterOfType(Class JavaDoc componentType) {
60         return delegate.getComponentAdapterOfType(componentType);
61     }
62
63     public Collection JavaDoc getComponentAdapters() {
64         return delegate.getComponentAdapters();
65     }
66
67     public List JavaDoc getComponentAdaptersOfType(Class JavaDoc componentType) {
68         return delegate.getComponentAdaptersOfType(componentType);
69     }
70
71     /**
72      * @deprecated since 1.1 - Use new VerifyingVisitor().traverse(this)
73      */

74     public void verify() throws PicoVerificationException {
75         delegate.verify();
76     }
77
78     public List JavaDoc getComponentInstancesOfType(Class JavaDoc type) throws PicoException {
79         return delegate.getComponentInstancesOfType(type);
80     }
81
82     public void accept(PicoVisitor visitor) {
83         delegate.accept(visitor);
84     }
85
86     public void start() {
87         // This is false security. As long as components can be accessed with getComponentInstance(), they can also be started. (AH).
88
throw new UnsupportedOperationException JavaDoc("This container is immutable, start() is not allowed");
89     }
90
91     public void stop() {
92         // This is false security. As long as components can be accessed with getComponentInstance(), they can also be stopped. (AH).
93
throw new UnsupportedOperationException JavaDoc("This container is immutable, stop() is not allowed");
94     }
95
96     public void dispose() {
97         // This is false security. As long as components can be accessed with getComponentInstance(), they can also be disposed. (AH).
98
throw new UnsupportedOperationException JavaDoc("This container is immutable, dispose() is not allowed");
99     }
100 }
101
Popular Tags