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: * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant *
09: *****************************************************************************/package org.picocontainer.behaviors;
10:
11: import org.picocontainer.Characteristics;
12: import org.picocontainer.ComponentAdapter;
13: import org.picocontainer.ComponentMonitor;
14: import org.picocontainer.LifecycleStrategy;
15: import org.picocontainer.Parameter;
16: import org.picocontainer.PicoCompositionException;
17:
18: import java.util.Properties;
19:
20: /** @author Paul Hammant */
21: public class ThreadCaching extends AbstractBehaviorFactory {
22:
23: public <T> ComponentAdapter<T> createComponentAdapter(
24: ComponentMonitor componentMonitor,
25: LifecycleStrategy lifecycleStrategy,
26: Properties componentProperties, Object componentKey,
27: Class<T> componentImplementation, Parameter... parameters)
28: throws PicoCompositionException {
29: if (removePropertiesIfPresent(componentProperties,
30: Characteristics.NO_CACHE)) {
31: return super .createComponentAdapter(componentMonitor,
32: lifecycleStrategy, componentProperties,
33: componentKey, componentImplementation, parameters);
34: }
35: removePropertiesIfPresent(componentProperties,
36: Characteristics.CACHE);
37: return new ThreadCached<T>(super .createComponentAdapter(
38: componentMonitor, lifecycleStrategy,
39: componentProperties, componentKey,
40: componentImplementation, parameters));
41:
42: }
43:
44: public <T> ComponentAdapter<T> addComponentAdapter(
45: ComponentMonitor componentMonitor,
46: LifecycleStrategy lifecycleStrategy,
47: Properties componentProperties, ComponentAdapter<T> adapter) {
48: if (removePropertiesIfPresent(componentProperties,
49: Characteristics.NO_CACHE)) {
50: return super .addComponentAdapter(componentMonitor,
51: lifecycleStrategy, componentProperties, adapter);
52: }
53: removePropertiesIfPresent(componentProperties,
54: Characteristics.CACHE);
55: return new ThreadCached<T>(super.addComponentAdapter(
56: componentMonitor, lifecycleStrategy,
57: componentProperties, adapter));
58: }
59: }
|