KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > gems > adapters > AssimilatingComponentAdapterFactory


1 /*****************************************************************************
2  * Copyright (C) NanoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Original code by Joerg Schaibe *
9  *****************************************************************************/

10
11 package org.picocontainer.gems.adapters;
12
13 import com.thoughtworks.proxy.ProxyFactory;
14 import com.thoughtworks.proxy.factory.StandardProxyFactory;
15
16 import org.picocontainer.ComponentAdapter;
17 import org.picocontainer.Parameter;
18 import org.picocontainer.PicoIntrospectionException;
19 import org.picocontainer.defaults.AssignabilityRegistrationException;
20 import org.picocontainer.defaults.ComponentAdapterFactory;
21 import org.picocontainer.defaults.DecoratingComponentAdapterFactory;
22 import org.picocontainer.defaults.NotConcreteRegistrationException;
23
24
25 /**
26  * Factory for the AssimilatingComponentAdapter. This factory will create {@link AssimilatingComponentAdapter} instances for all
27  * {@link ComponentAdapter} instances created by the delegate. This will assimilate every component for a specific type.
28  *
29  * @author Jörg Schaible
30  * @since 1.2
31  */

32 public class AssimilatingComponentAdapterFactory extends DecoratingComponentAdapterFactory {
33
34     private final ProxyFactory proxyFactory;
35     private final Class JavaDoc assimilationType;
36
37     /**
38      * Construct an AssimilatingComponentAdapterFactory. The instance will use the {@link StandardProxyFactory} using the JDK
39      * implementation.
40      *
41      * @param delegate The delegated {@link ComponentAdapterFactory}.
42      * @param type The assimilated type.
43      */

44     public AssimilatingComponentAdapterFactory(final ComponentAdapterFactory delegate, final Class JavaDoc type) {
45         this(delegate, type, new StandardProxyFactory());
46     }
47
48     /**
49      * Construct an AssimilatingComponentAdapterFactory using a special {@link ProxyFactory}.
50      *
51      * @param delegate The delegated {@link ComponentAdapterFactory}.
52      * @param type The assimilated type.
53      * @param proxyFactory The proxy factory to use.
54      */

55     public AssimilatingComponentAdapterFactory(
56             final ComponentAdapterFactory delegate, final Class JavaDoc type, final ProxyFactory proxyFactory) {
57         super(delegate);
58         this.assimilationType = type;
59         this.proxyFactory = proxyFactory;
60     }
61
62     /**
63      * Create a {@link AssimilatingComponentAdapter}. This adapter will wrap the returned {@link ComponentAdapter} of the
64      * deleated {@link ComponentAdapterFactory}.
65      *
66      * @see org.picocontainer.defaults.DecoratingComponentAdapterFactory#createComponentAdapter(java.lang.Object,
67      * java.lang.Class, org.picocontainer.Parameter[])
68      */

69     public ComponentAdapter createComponentAdapter(
70             final Object JavaDoc componentKey, final Class JavaDoc componentImplementation, final Parameter[] parameters)
71             throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
72         return new AssimilatingComponentAdapter(assimilationType, super.createComponentAdapter(
73                 componentKey, componentImplementation, parameters), proxyFactory);
74     }
75 }
76
Popular Tags