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: *****************************************************************************/package org.picocontainer.containers;
010:
011: import org.picocontainer.PicoContainer;
012: import org.picocontainer.ComponentAdapter;
013: import org.picocontainer.PicoVisitor;
014: import org.picocontainer.NameBinding;
015:
016: import java.util.List;
017: import java.util.Collection;
018: import java.io.Serializable;
019: import java.lang.annotation.Annotation;
020:
021: /**
022: * wrap pico container to achieve immutability
023: * Typically its used to mock a parent container.
024: *
025: * @author Konstantin Pribluda
026: */
027: public class ImmutablePicoContainer implements PicoContainer,
028: Serializable {
029:
030: private final PicoContainer delegate;
031:
032: public ImmutablePicoContainer(PicoContainer delegate) {
033: if (delegate == null) {
034: throw new NullPointerException();
035: }
036: this .delegate = delegate;
037: }
038:
039: public Object getComponent(Object componentKeyOrType) {
040: return delegate.getComponent(componentKeyOrType);
041: }
042:
043: public <T> T getComponent(Class<T> componentType) {
044: return delegate.getComponent(componentType);
045: }
046:
047: public <T> T getComponent(Class<T> componentType,
048: Class<? extends Annotation> binding) {
049: return delegate.getComponent(componentType, binding);
050: }
051:
052: public List getComponents() {
053: return delegate.getComponents();
054: }
055:
056: public PicoContainer getParent() {
057: return delegate.getParent();
058: }
059:
060: public ComponentAdapter<?> getComponentAdapter(Object componentKey) {
061: return delegate.getComponentAdapter(componentKey);
062: }
063:
064: public <T> ComponentAdapter<T> getComponentAdapter(
065: Class<T> componentType, NameBinding componentNameBinding) {
066: return delegate.getComponentAdapter(componentType,
067: componentNameBinding);
068: }
069:
070: public <T> ComponentAdapter<T> getComponentAdapter(
071: Class<T> componentType, Class<? extends Annotation> binding) {
072: return delegate.getComponentAdapter(componentType, binding);
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(
085: Class<T> componentType, Class<? extends Annotation> binding) {
086: return delegate.getComponentAdapters(componentType, binding);
087: }
088:
089: public <T> List<T> getComponents(Class<T> componentType) {
090: return delegate.getComponents(componentType);
091: }
092:
093: public void accept(PicoVisitor visitor) {
094: delegate.accept(visitor);
095: }
096:
097: public boolean equals(Object obj) {
098: return obj == this
099: || (obj != null && obj == delegate)
100: || (obj instanceof ImmutablePicoContainer && ((ImmutablePicoContainer) obj).delegate == delegate);
101: }
102:
103: public int hashCode() {
104: return delegate.hashCode();
105: }
106: }
|