001    /*****************************************************************************
002     * Copyright (c) PicoContainer Organization. All rights reserved.            *
003     * ------------------------------------------------------------------------- *
004     * The software in this package is published under the terms of the BSD      *
005     * style license a copy of which has been included with this distribution in *
006     * the LICENSE.txt file.                                                     *
007     *                                                                           *
008     * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
009     *****************************************************************************/
010    
011    package org.picocontainer.gems.adapters;
012    
013    import com.thoughtworks.proxy.ProxyFactory;
014    import com.thoughtworks.proxy.factory.StandardProxyFactory;
015    
016    import org.picocontainer.ComponentAdapter;
017    import org.picocontainer.Parameter;
018    import org.picocontainer.PicoIntrospectionException;
019    import org.picocontainer.defaults.AssignabilityRegistrationException;
020    import org.picocontainer.defaults.ComponentAdapterFactory;
021    import org.picocontainer.defaults.DecoratingComponentAdapterFactory;
022    import org.picocontainer.defaults.DefaultComponentAdapterFactory;
023    import org.picocontainer.defaults.NotConcreteRegistrationException;
024    
025    
026    /**
027     * Hides implementation.
028     * 
029     * @author Paul Hammant
030     * @author Aslak Hellesøy
031     * @version $Revision: 2252 $
032     * @see HotSwappingComponentAdapter
033     */
034    public class HotSwappingComponentAdapterFactory extends DecoratingComponentAdapterFactory {
035        private final ProxyFactory proxyFactory;
036    
037        public HotSwappingComponentAdapterFactory() {
038            this(new DefaultComponentAdapterFactory());
039        }
040    
041        public HotSwappingComponentAdapterFactory(ComponentAdapterFactory delegate) {
042            this(delegate, new StandardProxyFactory());
043        }
044    
045        public HotSwappingComponentAdapterFactory(ComponentAdapterFactory delegate, ProxyFactory proxyFactory) {
046            super(delegate);
047            this.proxyFactory = proxyFactory;
048        }
049    
050        public ComponentAdapter createComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters)
051                throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
052            ComponentAdapter componentAdapter = super.createComponentAdapter(componentKey, componentImplementation, parameters);
053            return new HotSwappingComponentAdapter(componentAdapter, proxyFactory);
054        }
055    }