All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.picocontainer.containers.AbstractDelegatingPicoContainer Maven / Gradle / Ivy

There is a newer version: 2.15
Show newest version
package org.picocontainer.containers;

import org.picocontainer.ComponentAdapter;
import org.picocontainer.Converters;
import org.picocontainer.Converting;
import org.picocontainer.NameBinding;
import org.picocontainer.PicoContainer;
import org.picocontainer.PicoException;
import org.picocontainer.PicoVisitor;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;

/**
 * Abstract base class for immutable delegation to a PicoContainer
 * 
 * @author Konstantin Pribluda
 * 
 */
@SuppressWarnings("serial")
public abstract class AbstractDelegatingPicoContainer implements PicoContainer, Converting, Serializable{

    private PicoContainer delegate;

    public AbstractDelegatingPicoContainer(PicoContainer delegate) {
		if (delegate == null) {
			throw new NullPointerException(
					"PicoContainer delegate must not be null");
		}
		this.delegate = delegate;
	}

	public final void accept(PicoVisitor visitor) {
        visitor.visitContainer(this);
        delegate.accept(visitor);
	}


	@Override
    public boolean equals(Object obj) {
		// required to make it pass on both jdk 1.3 and jdk 1.4. Btw, what about
		// overriding hashCode()? (AH)
		return delegate.equals(obj) || this == obj;
	}

	public  T getComponent(Class componentType) {
		return componentType.cast(getComponent((Object) componentType));
	}

    public  T getComponent(Class componentType, Class binding) {
        return delegate.getComponent(componentType, binding);
    }

    public Object getComponent(Object componentKeyOrType) {
		return delegate.getComponent(componentKeyOrType);
	}

    public Object getComponent(Object componentKeyOrType, Type into) {
        return delegate.getComponent(componentKeyOrType, into);
    }

    public  ComponentAdapter getComponentAdapter(Class componentType,
			NameBinding componentNameBinding) {
		return delegate.getComponentAdapter(componentType,
                                            componentNameBinding);
	}

    public  ComponentAdapter getComponentAdapter(Class componentType, Class binding) {
        return delegate.getComponentAdapter(componentType, binding);
    }

    public ComponentAdapter getComponentAdapter(Object componentKey) {
		return delegate.getComponentAdapter(componentKey);
	}

	public Collection> getComponentAdapters() {
		return delegate.getComponentAdapters();
	}

	public  List> getComponentAdapters(
			Class componentType) {
		return delegate.getComponentAdapters(componentType);
	}

    public  List> getComponentAdapters(Class componentType, Class binding) {
        return delegate.getComponentAdapters(componentType, binding);
    }    

    public List getComponents() {
		return delegate.getComponents();
	}

	public  List getComponents(Class type) throws PicoException {
		return delegate.getComponents(type);
	}

	public PicoContainer getDelegate() {
		return delegate;
	}

	public PicoContainer getParent() {
		return delegate.getParent();
	}
    
    @Override
    public String toString() {
        return "[Delegate]:" + delegate.toString();
    }

    public Converters getConverters() {
        if (delegate instanceof Converting) {
            return ((Converting) delegate).getConverters();
        } else {
            return null;
        }
    }
}