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                                                          *
009     *****************************************************************************/
010    package org.picocontainer.containers;
011    
012    import org.picocontainer.PicoContainer;
013    import org.picocontainer.ComponentAdapter;
014    import org.picocontainer.PicoVisitor;
015    import org.picocontainer.ParameterName;
016    
017    import java.util.List;
018    import java.util.Collection;
019    import java.io.Serializable;
020    
021    /**
022     * Empty pico container serving as recoil damper in situations where you
023     * do not like to check whether container reference suplpied to you
024     * is null or not
025     *
026     * Typically its used to merk a parent container.
027     *
028     * @author Konstantin Pribluda
029     */
030    public class ImmutablePicoContainer implements PicoContainer, Serializable {
031    
032        private final PicoContainer delegate;
033    
034        public ImmutablePicoContainer(PicoContainer delegate) {
035            if (delegate == null) {
036                throw new NullPointerException();
037            }
038            this.delegate = delegate;
039        }
040    
041        public Object getComponent(Object componentKeyOrType) {
042            return delegate.getComponent(componentKeyOrType);
043        }
044    
045        public <T> T getComponent(Class<T> componentType) {
046            return delegate.getComponent(componentType);
047        }
048    
049        public List getComponents() {
050            return delegate.getComponents();
051        }
052    
053        public PicoContainer getParent() {
054            return delegate.getParent();
055        }
056    
057        public ComponentAdapter<?> getComponentAdapter(Object componentKey) {
058            return delegate.getComponentAdapter(componentKey);
059        }
060    
061        public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType, ParameterName componentParameterName) {
062            return delegate.getComponentAdapter(componentType, componentParameterName);  
063        }
064    
065        public Collection<ComponentAdapter<?>> getComponentAdapters() {
066            return delegate.getComponentAdapters();
067        }
068    
069        public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType) {
070            return delegate.getComponentAdapters(componentType);
071        }
072    
073        public <T> List<T> getComponents(Class<T> componentType) {
074            return delegate.getComponents(componentType);
075        }
076    
077        public void accept(PicoVisitor visitor) {
078            delegate.accept(visitor);
079        }
080    
081        public boolean equals(Object obj) {
082            return obj == this
083                   || (obj != null && obj == delegate)
084                   || (obj instanceof ImmutablePicoContainer && ((ImmutablePicoContainer) obj).delegate == delegate)
085                ;
086        }
087    
088    
089        public int hashCode() {
090            return delegate.hashCode();
091        }
092    }