01: /*****************************************************************************
02: * Copyright (C) PicoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: * Original code by *
09: *****************************************************************************/package org.picocontainer.behaviors;
10:
11: import org.picocontainer.ComponentAdapter;
12: import org.picocontainer.Parameter;
13: import org.picocontainer.PicoCompositionException;
14: import org.picocontainer.ComponentMonitor;
15: import org.picocontainer.LifecycleStrategy;
16: import org.picocontainer.Characteristics;
17: import org.picocontainer.behaviors.AbstractBehaviorFactory;
18:
19: import java.util.Properties;
20:
21: /**
22: * @author Aslak Hellesøy
23: * @see org.picocontainer.gems.adapters.HotSwappingComponentFactory for a more feature-rich version of the class
24: */
25: public class ImplementationHiding extends AbstractBehaviorFactory {
26:
27: public ComponentAdapter createComponentAdapter(
28: ComponentMonitor componentMonitor,
29: LifecycleStrategy lifecycleStrategy,
30: Properties componentProperties, Object componentKey,
31: Class componentImplementation, Parameter... parameters)
32: throws PicoCompositionException {
33: ComponentAdapter componentAdapter = super
34: .createComponentAdapter(componentMonitor,
35: lifecycleStrategy, componentProperties,
36: componentKey, componentImplementation,
37: parameters);
38: if (removePropertiesIfPresent(componentProperties,
39: Characteristics.NO_HIDE_IMPL)) {
40: return componentAdapter;
41: }
42: removePropertiesIfPresent(componentProperties,
43: Characteristics.HIDE_IMPL);
44: return new HiddenImplementation(componentAdapter);
45:
46: }
47:
48: public ComponentAdapter addComponentAdapter(
49: ComponentMonitor componentMonitor,
50: LifecycleStrategy lifecycleStrategy,
51: Properties componentProperties, ComponentAdapter adapter) {
52: if (removePropertiesIfPresent(componentProperties,
53: Characteristics.NO_HIDE_IMPL)) {
54: return adapter;
55: }
56: removePropertiesIfPresent(componentProperties,
57: Characteristics.HIDE_IMPL);
58: return new HiddenImplementation(super.addComponentAdapter(
59: componentMonitor, lifecycleStrategy,
60: componentProperties, adapter));
61:
62: }
63: }
|