1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package org.objectledge.pico.customization;
30
31 import org.picocontainer.ComponentAdapter;
32 import org.picocontainer.PicoContainer;
33 import org.picocontainer.PicoInitializationException;
34 import org.picocontainer.PicoIntrospectionException;
35 import org.picocontainer.PicoVerificationException;
36 import org.picocontainer.PicoVisitor;
37
38 /***
39 * An adapter for a component that is customized on behalf of a component that is asking for it.
40 * <p>
41 * When another component is being initialized and it depends on the component that is managed by
42 * this adapter (identified by the componentKey), the customizedContainerProvider is asked to
43 * produce an instance of the customized component. Thus, different components may recieve different
44 * instnaces of the managed component, depending on the customizedComponentProvider's semantics.
45 * </p>
46 *
47 * @author <a href="Rafal.Krzewski">rafal@caltha.pl </a>
48 * @version $Id: CustomizedComponentAdapter.java,v 1.15 2005/02/04 02:28:00 rafal Exp $
49 */
50 public class CustomizedComponentAdapter
51 implements ComponentAdapter
52 {
53 private Object componentKey;
54
55 private CustomizedComponentProvider customizedComponentProvider;
56
57 /***
58 * Crates a new instance of the adapter.
59 *
60 * @param componentKey the component key this adapter manages.
61 * @param customizedComponentProvider a provider of customized components.
62 */
63 public CustomizedComponentAdapter(Object componentKey,
64 CustomizedComponentProvider customizedComponentProvider)
65 {
66 this.componentKey = componentKey;
67 this.customizedComponentProvider = customizedComponentProvider;
68 }
69
70 /***
71 * {@inheritDoc}
72 */
73 public Object getComponentInstance(PicoContainer container)
74 throws PicoInitializationException, PicoIntrospectionException
75 {
76
77 return customizedComponentProvider.getCustomizedComponentInstance(container, null, null);
78 }
79
80 /***
81 * Returns a customized components instance.
82 * <p>
83 * This method is called by the {@link CustomizingConstructorComponentAdapter}.
84 * </p>
85 *
86 * @param container the container for resolving references.
87 * @param componentKey the key of the requesting component.
88 * @param componentImplementation the implemenation class of the requesting component.
89 * @return a customized component instance.
90 * @throws PicoInitializationException if the customized component cannot be instantiated.
91 * @throws PicoIntrospectionException if there is a problem introspecting classes.
92 * @throws UnsupportedKeyTypeException if the requesting component key if an unsupported type.
93 */
94 public Object getComponentInstance(PicoContainer container, Object componentKey,
95 Class componentImplementation)
96 throws PicoInitializationException, PicoIntrospectionException, UnsupportedKeyTypeException
97 {
98 return customizedComponentProvider.getCustomizedComponentInstance(container, componentKey,
99 componentImplementation);
100 }
101
102 /***
103 * {@inheritDoc}
104 */
105 public void verify(PicoContainer container)
106 throws PicoVerificationException
107 {
108 customizedComponentProvider.verify(container);
109 }
110
111 /***
112 * {@inheritDoc}
113 */
114 public Class getComponentImplementation()
115 {
116 return customizedComponentProvider.getCustomizedComponentImplementation();
117 }
118
119 /***
120 * {@inheritDoc}
121 */
122 public Object getComponentKey()
123 {
124 return componentKey;
125 }
126
127 /***
128 * {@inheritDoc}
129 */
130 public void accept(PicoVisitor visitor)
131 {
132 visitor.visitComponentAdapter(this);
133 }
134 }