KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > gems > 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;
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
27  * {@link AssimilatingComponentAdapter}instances for all {@link ComponentAdapter}instances
28  * created by the delegate. This will assimilate every component for a specific type.
29  *
30  * @author Jörg Schaible
31  * @since 1.0
32  */

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

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

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

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