01: /*****************************************************************************
02: * Copyright (C) PicoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: *****************************************************************************/package org.picocontainer;
08:
09: /**
10: * A component adapter is responsible for providing a specific component
11: * instance of type <T>. An instance of an implementation of this interface is
12: * used inside a {@link PicoContainer} for every registered component or
13: * instance. Each <code>ComponentAdapter</code> instance has to have a key
14: * which is unique within that container. The key itself is either a class type
15: * (normally an interface) or an identifier.
16: *
17: * @author Jon Tirsén
18: * @author Paul Hammant
19: * @author Aslak Hellesøy
20: */
21: public interface ComponentAdapter<T> {
22:
23: /**
24: * Retrieve the key associated with the component.
25: *
26: * @return the component's key. Should either be a class type (normally an interface) or an identifier that is
27: * unique (within the scope of the current PicoContainer).
28: */
29: Object getComponentKey();
30:
31: /**
32: * Retrieve the class of the component.
33: *
34: * @return the component's implementation class. Should normally be a concrete class (ie, a class that can be
35: * instantiated).
36: */
37: Class<T> getComponentImplementation();
38:
39: /**
40: * Retrieve the component instance. This method will usually create a new instance each time it is called, but that
41: * is not required. For example, {@link org.picocontainer.behaviors.Cached} will always return the
42: * same instance.
43: *
44: * @param container the {@link PicoContainer}, that is used to resolve any possible dependencies of the instance.
45: * @return the component instance.
46: * @throws PicoCompositionException if the component has dependencies which could not be resolved, or
47: * instantiation of the component lead to an ambigous situation within the
48: * container.
49: */
50: T getComponentInstance(PicoContainer container)
51: throws PicoCompositionException;
52:
53: /**
54: * Verify that all dependencies for this adapter can be satisifed. Normally, the adapter should verify this by
55: * checking that the associated PicoContainer contains all the needed dependnecies.
56: *
57: * @param container the {@link PicoContainer}, that is used to resolve any possible dependencies of the instance.
58: * @throws PicoCompositionException if one or more dependencies cannot be resolved.
59: */
60: void verify(PicoContainer container)
61: throws PicoCompositionException;
62:
63: /**
64: * Accepts a visitor for this ComponentAdapter. The method is normally called by visiting a {@link PicoContainer}, that
65: * cascades the visitor also down to all its ComponentAdapter instances.
66: *
67: * @param visitor the visitor.
68: */
69: void accept(PicoVisitor visitor);
70:
71: ComponentAdapter<T> getDelegate();
72:
73: <U extends ComponentAdapter> U findAdapterOfType(
74: Class<U> componentAdapterType);
75:
76: String getDescriptor();
77:
78: }
|