001    /*****************************************************************************
002     * Copyright (C) PicoContainer Organization. All rights reserved.            *
003     * ------------------------------------------------------------------------- *
004     * The software in this package is published under the terms of the BSD      *
005     * style license a copy of which has been included with this distribution in *
006     * the LICENSE.txt file.                                                     *
007     *                                                                           *
008     * Original code by Paul Hammant                                             *
009     *****************************************************************************/
010    package org.picocontainer.alternatives;
011    
012    import org.picocontainer.ComponentAdapter;
013    import org.picocontainer.PicoContainer;
014    import org.picocontainer.PicoException;
015    import org.picocontainer.PicoVerificationException;
016    import org.picocontainer.PicoVisitor;
017    import org.picocontainer.defaults.VerifyingVisitor;
018    
019    import java.io.Serializable;
020    import java.util.Collection;
021    import java.util.List;
022    
023    // TODO: replace this with a proxy? It don't do nothing! (AH)
024    // Am open to elegant solution. This, at least, is instantiable (PH)
025    
026    /**
027     * @author Paul Hammant
028     * @version $Revision: 2286 $
029     * @since 1.1
030     * @deprecated since 1.2, use the {@link org.picocontainer.defaults.ImmutablePicoContainerProxyFactory}
031     */
032    public class ImmutablePicoContainer implements PicoContainer, Serializable {
033    
034        private PicoContainer delegate;
035    
036        public ImmutablePicoContainer(PicoContainer delegate) {
037            if(delegate == null) throw new NullPointerException("You must pass in a picoContainer instance");
038            this.delegate = delegate;
039        }
040    
041        public Object getComponentInstance(Object componentKey) {
042            return delegate.getComponentInstance(componentKey);
043        }
044    
045        public Object getComponentInstanceOfType(Class componentType) {
046            return delegate.getComponentInstanceOfType(componentType);
047        }
048    
049        public List getComponentInstances() {
050            return delegate.getComponentInstances();
051        }
052    
053        public synchronized PicoContainer getParent() {
054            return delegate.getParent();
055        }
056    
057        public ComponentAdapter getComponentAdapter(Object componentKey) {
058            return delegate.getComponentAdapter(componentKey);
059        }
060    
061        public ComponentAdapter getComponentAdapterOfType(Class componentType) {
062            return delegate.getComponentAdapterOfType(componentType);
063        }
064    
065        public Collection getComponentAdapters() {
066            return delegate.getComponentAdapters();
067        }
068    
069        public List getComponentAdaptersOfType(Class componentType) {
070            return delegate.getComponentAdaptersOfType(componentType);
071        }
072    
073        /**
074         * @deprecated since 1.1 - Use "new VerifyingVisitor().traverse(this)"
075         */
076        public void verify() throws PicoVerificationException {
077            new VerifyingVisitor().traverse(this);
078        }
079    
080        public List getComponentInstancesOfType(Class type) throws PicoException {
081            return delegate.getComponentInstancesOfType(type);
082        }
083    
084        public void accept(PicoVisitor visitor) {
085            delegate.accept(visitor);
086        }
087    
088        public void start() {
089            // This is false security. As long as components can be accessed with getComponentInstance(), they can also be started. (AH).
090            throw new UnsupportedOperationException("This container is immutable, start() is not allowed");
091        }
092    
093        public void stop() {
094            // This is false security. As long as components can be accessed with getComponentInstance(), they can also be stopped. (AH).
095            throw new UnsupportedOperationException("This container is immutable, stop() is not allowed");
096        }
097    
098        public void dispose() {
099            // This is false security. As long as components can be accessed with getComponentInstance(), they can also be disposed. (AH).
100            throw new UnsupportedOperationException("This container is immutable, dispose() is not allowed");
101        }
102    }