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.behaviors;
012
013 import org.picocontainer.ComponentAdapter;
014 import org.picocontainer.Parameter;
015 import org.picocontainer.PicoCompositionException;
016 import org.picocontainer.ComponentMonitor;
017 import org.picocontainer.LifecycleStrategy;
018 import org.picocontainer.behaviors.AbstractBehaviorFactory;
019 import org.picocontainer.gems.GemsCharacteristics;
020
021 import java.util.Properties;
022
023
024 /**
025 * Hides implementation.
026 *
027 * @author Paul Hammant
028 * @author Aslak Hellesøy
029 * @see HotSwappable
030 */
031 @SuppressWarnings("serial")
032 public class HotSwapping extends AbstractBehaviorFactory {
033
034
035 @Override
036 public <T> ComponentAdapter<T> createComponentAdapter(final ComponentMonitor componentMonitor, final LifecycleStrategy lifecycleStrategy, final Properties componentProperties, final Object componentKey, final Class<T> componentImplementation, final Parameter... parameters)
037 throws PicoCompositionException {
038 ComponentAdapter<T> delegateAdapter = super.createComponentAdapter(componentMonitor, lifecycleStrategy,
039 componentProperties, componentKey, componentImplementation, parameters);
040
041 if (AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, GemsCharacteristics.NO_HOT_SWAP)) {
042 return delegateAdapter;
043 }
044
045 AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, GemsCharacteristics.HOT_SWAP);
046 return componentMonitor.newBehavior(new HotSwappable<T>(delegateAdapter));
047 }
048
049 @Override
050 public <T> ComponentAdapter<T> addComponentAdapter(final ComponentMonitor componentMonitor,
051 final LifecycleStrategy lifecycleStrategy,
052 final Properties componentProperties,
053 final ComponentAdapter<T> adapter) {
054 if (AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, GemsCharacteristics.NO_HOT_SWAP)) {
055 return super.addComponentAdapter(componentMonitor,
056 lifecycleStrategy,
057 componentProperties,
058 adapter);
059 }
060
061
062 AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, GemsCharacteristics.HOT_SWAP);
063 return componentMonitor.newBehavior(new HotSwappable<T>(super.addComponentAdapter(componentMonitor,
064 lifecycleStrategy,
065 componentProperties,
066 adapter)));
067 }
068 }