01: package test;
02:
03: import java.util.logging.Logger;
04:
05: import javax.resource.spi.ResourceAdapter;
06: import javax.resource.spi.ResourceAdapterInternalException;
07: import javax.resource.spi.BootstrapContext;
08:
09: import com.caucho.jca.AbstractResourceAdapter;
10:
11: /**
12: * Implements a resource which uses the ResourceAdapter lifecycle.
13: */
14: public class TestResource extends AbstractResourceAdapter {
15: private static final Logger log = Logger
16: .getLogger(ResourceAdapter.class.getName());
17:
18: /**
19: * Sample initialization param set by the <resource>
20: */
21: private String _value = "default";
22:
23: private String _status = "new";
24:
25: /**
26: * Sets the value.
27: */
28: public void setValue(String value) {
29: _value = value;
30: }
31:
32: /**
33: * The start method is called when the resource adapter starts, i.e.
34: * when the web-app or host initializes.
35: */
36: public void start(BootstrapContext ctx)
37: throws ResourceAdapterInternalException {
38: log.info("Resource[value=" + _value + "] starting");
39:
40: _status = "started";
41: }
42:
43: /**
44: * Called when the resource adapter is stopped, i.e. when the
45: * web-app or host closes down.
46: */
47: public void stop() throws ResourceAdapterInternalException {
48: log.info("Resource[value=" + _value + "] stopping");
49:
50: _status = "stopped";
51: }
52:
53: /**
54: * Returns a printable version of the resource.
55: */
56: public String toString() {
57: return "TestResource[" + _status + ", " + _value + "]";
58: }
59: }
|