org.picocontainer.containers.ImmutablePicoContainer Maven / Gradle / Ivy
The newest version!
/*****************************************************************************
* Copyright (C) PicoContainer Organization. All rights reserved. *
* ------------------------------------------------------------------------- *
* The software in this package is published under the terms of the BSD *
* style license a copy of which has been included with this distribution in *
* the LICENSE.txt file. *
* *
* Original code by *
*****************************************************************************/
package org.picocontainer.containers;
import org.picocontainer.*;
import org.picocontainer.converters.ConvertsNothing;
import java.util.List;
import java.util.Collection;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
/**
* wrap pico container to achieve immutability
* Typically its used to mock a parent container.
*
* @author Konstantin Pribluda
*/
@SuppressWarnings("serial")
public final class ImmutablePicoContainer implements PicoContainer, Converting, Serializable {
private final PicoContainer delegate;
public ImmutablePicoContainer(PicoContainer delegate) {
if (delegate == null) {
throw new NullPointerException();
}
this.delegate = delegate;
}
public Object getComponent(Object componentKeyOrType) {
return delegate.getComponent(componentKeyOrType);
}
public Object getComponent(Object componentKeyOrType, Type into) {
return delegate.getComponent(componentKeyOrType, into);
}
public T getComponent(Class componentType) {
return delegate.getComponent(componentType);
}
public T getComponent(Class componentType, Class extends Annotation> binding) {
return delegate.getComponent(componentType, binding);
}
public List getComponents() {
return delegate.getComponents();
}
public PicoContainer getParent() {
return delegate.getParent();
}
public ComponentAdapter> getComponentAdapter(Object componentKey) {
return delegate.getComponentAdapter(componentKey);
}
public ComponentAdapter getComponentAdapter(Class componentType, NameBinding componentNameBinding) {
return delegate.getComponentAdapter(componentType, componentNameBinding);
}
public ComponentAdapter getComponentAdapter(Class componentType, Class extends Annotation> binding) {
return delegate.getComponentAdapter(componentType, binding);
}
public Collection> getComponentAdapters() {
return delegate.getComponentAdapters();
}
public List> getComponentAdapters(Class componentType) {
return delegate.getComponentAdapters(componentType);
}
public List> getComponentAdapters(Class componentType, Class extends Annotation> binding) {
return delegate.getComponentAdapters(componentType, binding);
}
public List getComponents(Class componentType) {
return delegate.getComponents(componentType);
}
public final void accept(PicoVisitor visitor) {
// don't visit "this" its pointless.
delegate.accept(visitor);
}
public boolean equals(Object obj) {
return obj == this
|| (obj != null && obj == delegate)
|| (obj instanceof ImmutablePicoContainer && ((ImmutablePicoContainer) obj).delegate == delegate)
;
}
public int hashCode() {
return delegate.hashCode();
}
public String toString() {
return "[Immutable]:" + delegate.toString();
}
public Converters getConverters() {
if (delegate instanceof Converting) {
return ((Converting) delegate).getConverters();
}
return new ConvertsNothing();
}
}