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 java.io.Serializable;
12:
13: import org.picocontainer.Behavior;
14: import org.picocontainer.ComponentAdapter;
15: import org.picocontainer.ObjectReference;
16: import org.picocontainer.references.SimpleReference;
17:
18: /**
19: * <p>
20: * {@link ComponentAdapter} implementation that caches the component instance.
21: * </p>
22: * <p>
23: * This adapter supports components with a lifecycle, as it is a
24: * {@link Behavior lifecycle manager} which will apply the delegate's
25: * {@link org.picocontainer.LifecycleStrategy lifecycle strategy} to the cached
26: * component instance. The lifecycle state is maintained so that the component
27: * instance behaves in the expected way: it can't be started if already started,
28: * it can't be started or stopped if disposed, it can't be stopped if not
29: * started, it can't be disposed if already disposed.
30: * </p>
31: *
32: * @author Mauro Talevi
33: */
34: public class Cached<T> extends Stored<T> {
35:
36: public Cached(ComponentAdapter delegate) {
37: this (delegate, new SimpleReference());
38: }
39:
40: public Cached(ComponentAdapter delegate,
41: ObjectReference instanceReference) {
42: super (delegate, instanceReference);
43: }
44:
45: public String getDescriptor() {
46: return "Cached";
47: }
48: }
|