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 * Original code by * 009 *****************************************************************************/ 010 package org.picocontainer.gems.behaviors; 011 012 import org.picocontainer.LifecycleStrategy; 013 import org.picocontainer.ComponentAdapter; 014 import org.picocontainer.Parameter; 015 import org.picocontainer.PicoCompositionException; 016 import org.picocontainer.ComponentMonitor; 017 import org.picocontainer.Characteristics; 018 import org.picocontainer.behaviors.AbstractBehaviorFactory; 019 020 import java.util.Properties; 021 022 /** 023 * Because AsmImplementationHiding is the same type of behavior as HiddenImplementation, we use the same 024 * characteristic properties for turning on and off AsmImplementation Hiding. 025 * @see org.picocontainer.Characteristics.HIDE_IMPL 026 * @see org.picocontainer.Characteristics.NO_HIDE_IMPL 027 */ 028 @SuppressWarnings("serial") 029 public class AsmImplementationHiding extends AbstractBehaviorFactory { 030 031 032 @Override 033 public <T> ComponentAdapter<T> createComponentAdapter(final ComponentMonitor componentMonitor, 034 final LifecycleStrategy lifecycleStrategy, 035 final Properties componentProperties, 036 final Object componentKey, 037 final Class<T> componentImplementation, 038 final Parameter... parameters) throws PicoCompositionException { 039 if (AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, Characteristics.NO_HIDE_IMPL)) { 040 return super.createComponentAdapter(componentMonitor, lifecycleStrategy, 041 componentProperties, componentKey, componentImplementation, parameters); 042 } 043 AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, Characteristics.HIDE_IMPL); 044 ComponentAdapter<T> componentAdapter = super.createComponentAdapter(componentMonitor, 045 lifecycleStrategy, 046 componentProperties, 047 componentKey, 048 componentImplementation, 049 parameters); 050 return componentMonitor.newBehavior(new AsmHiddenImplementation<T>(componentAdapter)); 051 } 052 053 @Override 054 public <T> ComponentAdapter<T> addComponentAdapter(final ComponentMonitor componentMonitor, 055 final LifecycleStrategy lifecycleStrategy, 056 final Properties componentProperties, 057 final ComponentAdapter<T> adapter) { 058 if (AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, Characteristics.NO_HIDE_IMPL)) { 059 return super.addComponentAdapter(componentMonitor, 060 lifecycleStrategy, 061 componentProperties, 062 adapter); 063 } 064 AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, Characteristics.HIDE_IMPL); 065 return componentMonitor.newBehavior(new AsmHiddenImplementation<T>(super.addComponentAdapter(componentMonitor, 066 lifecycleStrategy, 067 componentProperties, 068 adapter))); 069 } 070 }