    001    package org.picocontainer.containers;
    002
    003    import java.io.Serializable;
    004    import java.util.Collection;
    005    import java.util.List;
    006    import java.lang.annotation.Annotation;
    007    import java.lang.reflect.Type;
    008
    009    import org.picocontainer.ComponentAdapter;
    010    import org.picocontainer.NameBinding;
    011    import org.picocontainer.PicoContainer;
    012    import org.picocontainer.PicoException;
    013    import org.picocontainer.PicoVisitor;
    014
    015    /**
    016     * abstract base class for immutable delegation to pico
    017     *
    018     * @author k.pribluda
    019     *
    020     */
    021    public abstract class AbstractDelegatingPicoContainer implements PicoContainer, Serializable{
    022
    023        private PicoContainer delegate;
    024
    025        public AbstractDelegatingPicoContainer(PicoContainer delegate) {
    026                    if (delegate == null) {
    027                            throw new NullPointerException(
    028                                            "PicoContainer delegate must not be null");
    029                    }
    030                    this.delegate = delegate;
    031            }
    032
    033            public final void accept(PicoVisitor visitor) {
    034            visitor.visitContainer(this);
    035            delegate.accept(visitor);
    036            }
    037
    038
    039            public boolean equals(Object obj) {
    040                    // required to make it pass on both jdk 1.3 and jdk 1.4. Btw, what about
    041                    // overriding hashCode()? (AH)
    042                    return delegate.equals(obj) || this == obj;
    043            }
    044
    045            public <T> T getComponent(Class<T> componentType) {
    046                    return componentType.cast(getComponent((Object) componentType));
    047            }
    048
    049        public <T> T getComponent(Class<T> componentType, Class<? extends Annotation> binding) {
    050            return delegate.getComponent(componentType, binding);
    051        }
    052
    053        public Object getComponent(Object componentKeyOrType) {
    054                    return delegate.getComponent(componentKeyOrType);
    055            }
    056
    057        public Object getComponent(Object componentKeyOrType, Type into) {
    058            return delegate.getComponent(componentKeyOrType, into);
    059        }
    060
    061        public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType,
    062                            NameBinding componentNameBinding) {
    063                    return delegate.getComponentAdapter(componentType,
    064                                                componentNameBinding);
    065            }
    066
    067        public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType, Class<? extends Annotation> binding) {
    068            return delegate.getComponentAdapter(componentType, binding);
    069        }
    070
    071        public ComponentAdapter<?> getComponentAdapter(Object componentKey) {
    072                    return delegate.getComponentAdapter(componentKey);
    073            }
    074
    075            public Collection<ComponentAdapter<?>> getComponentAdapters() {
    076                    return delegate.getComponentAdapters();
    077            }
    078
    079            public <T> List<ComponentAdapter<T>> getComponentAdapters(
    080                            Class<T> componentType) {
    081                    return delegate.getComponentAdapters(componentType);
    082            }
    083
    084        public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType, Class<? extends Annotation> binding) {
    085            return delegate.getComponentAdapters(componentType, binding);
    086        }
    087
    088        public List<Object> getComponents() {
    089                    return delegate.getComponents();
    090            }
    091
    092            public <T> List<T> getComponents(Class<T> type) throws PicoException {
    093                    return delegate.getComponents(type);
    094            }
    095
    096            public PicoContainer getDelegate() {
    097                    return delegate;
    098            }
    099
    100            public PicoContainer getParent() {
    101                    return delegate.getParent();
    102            }
    103
    104        public String toString() {
    105            return "D<" + delegate.toString();
    106        }
    107    }