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.containers;
011    
012    import org.picocontainer.*;
013    import org.picocontainer.converters.ConvertsNothing;
014    
015    import java.io.Serializable;
016    import java.util.Collection;
017    import java.util.Collections;
018    import java.util.List;
019    import java.lang.annotation.Annotation;
020    import java.lang.reflect.Type;
021    
022    /**
023     * Empty pico container serving as recoil damper in situations where you
024     * do not like to check whether container reference supplied to you
025     * is null or not
026     *
027     * @author Konstantin Pribluda
028     */
029    @SuppressWarnings("serial")
030    public class EmptyPicoContainer implements PicoContainer, Converting, Serializable {
031    
032        @SuppressWarnings("unused") 
033        public Object getComponent(Object componentKeyOrType) {
034            return null;
035        }
036    
037        @SuppressWarnings("unused") 
038        public Object getComponent(Object componentKeyOrType, Type into) {
039            return null;
040        }
041    
042        @SuppressWarnings("unused") 
043        public <T> T getComponent(Class<T> componentType) {
044            return null;
045        }
046    
047        @SuppressWarnings("unused") 
048        public <T> T getComponent(Class<T> componentType, Class<? extends Annotation> binding) {
049            return null;
050        }
051    
052        public List getComponents() {
053            return Collections.EMPTY_LIST;
054        }
055    
056        public PicoContainer getParent() {
057            return null;
058        }
059    
060        @SuppressWarnings("unused") 
061        public ComponentAdapter<?> getComponentAdapter(Object componentKey) {
062            return null;
063        }
064    
065        @SuppressWarnings("unused") 
066        public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType, NameBinding componentNameBinding) {
067            return null;
068        }
069    
070        @SuppressWarnings("unused") 
071        public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType, Class<? extends Annotation> binding) {
072            return null;
073        }
074    
075        public Collection<ComponentAdapter<?>> getComponentAdapters() {
076            return Collections.emptyList();
077        }
078    
079        @SuppressWarnings("unused") 
080        public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType) {
081            return Collections.emptyList();
082        }
083    
084        @SuppressWarnings("unused") 
085        public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType, Class<? extends Annotation> binding) {
086            return Collections.emptyList();
087        }
088    
089        /**
090         * we do not have anything to do here. 
091         */
092        @SuppressWarnings("unused") 
093        public void accept(PicoVisitor visitor) {
094            //Does nothing.
095        }
096    
097        /** {@inheritDoc} **/
098        @SuppressWarnings("unused") 
099        public <T> List<T> getComponents(Class<T> componentType) {
100            return Collections.emptyList();
101        }
102    
103        @Override
104        public String toString() {
105            return "(empty)";
106        }
107    
108        public Converters getConverters() {
109            return new ConvertsNothing();
110        }
111    
112    }