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: * *
08: * Idea by Rachel Davies, Original code by Jon Tirsen *
09: *****************************************************************************/package org.picocontainer;
10:
11: import org.picocontainer.parameters.ComponentParameter;
12:
13: import java.lang.annotation.Annotation;
14:
15: /**
16: * This class provides control over the arguments that will be passed to a constructor. It can be used for finer control over
17: * what arguments are passed to a particular constructor.
18: *
19: * @author Jon Tirsén
20: * @author Aslak Hellesøy
21: * @author Thomas Heller
22: * @see MutablePicoContainer#addComponent(Object,Object,Parameter[]) a method on the
23: * {@link MutablePicoContainer} interface which allows passing in of an array of {@linkplain Parameter Parameters}.
24: * @see org.picocontainer.parameters.ComponentParameter an implementation of this interface that allows you to specify the key
25: * used for resolving the parameter.
26: * @see org.picocontainer.parameters.ConstantParameter an implementation of this interface that allows you to specify a constant
27: * that will be used for resolving the parameter.
28: */
29: public interface Parameter {
30:
31: Parameter[] ZERO = new Parameter[0];
32: Parameter[] DEFAULT = new Parameter[] { ComponentParameter.DEFAULT };
33:
34: /**
35: * Retrieve the object from the Parameter that satisfies the expected type.
36: *
37: * @param container the container from which dependencies are resolved.
38: * @param adapter the {@link ComponentAdapter} that is asking for the instance
39: * @param expectedType the type that the returned instance needs to match.
40: * @param expectedNameBinding Expected parameter name
41: *
42: * @param useNames
43: * @param binding
44: * @return the instance or <code>null</code> if no suitable instance can be found.
45: *
46: * @throws PicoCompositionException if a referenced component could not be instantiated.
47: */
48: <T> T resolveInstance(PicoContainer container,
49: ComponentAdapter adapter, Class<T> expectedType,
50: NameBinding expectedNameBinding, boolean useNames,
51: Annotation binding);
52:
53: /**
54: * Check if the Parameter can satisfy the expected type using the container.
55: *
56: * @param container the container from which dependencies are resolved.
57: * @param adapter the {@link ComponentAdapter} that is asking for the instance
58: * @param expectedType the required type
59: * @param expectedNameBinding Expected parameter name
60: *
61: * @param useNames
62: * @param binding
63: * @return <code>true</code> if the component parameter can be resolved.
64: *
65: */
66: boolean isResolvable(PicoContainer container,
67: ComponentAdapter adapter, Class expectedType,
68: NameBinding expectedNameBinding, boolean useNames,
69: Annotation binding);
70:
71: /**
72: * Verify that the Parameter can satisfy the expected type using the container
73: *
74: * @param container the container from which dependencies are resolved.
75: * @param adapter the {@link ComponentAdapter} that is asking for the verification
76: * @param expectedType the required type
77: * @param expectedNameBinding Expected parameter name
78: *
79: * @param useNames
80: * @param binding
81: * @throws PicoCompositionException if parameter and its dependencies cannot be resolved
82: */
83: void verify(PicoContainer container, ComponentAdapter adapter,
84: Class expectedType, NameBinding expectedNameBinding,
85: boolean useNames, Annotation binding);
86:
87: /**
88: * Accepts a visitor for this Parameter. The method is normally called by visiting a {@link ComponentAdapter}, that
89: * cascades the {@linkplain PicoVisitor visitor} also down to all its {@linkplain Parameter Parameters}.
90: *
91: * @param visitor the visitor.
92: *
93: */
94: void accept(PicoVisitor visitor);
95: }
|