KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > TestResource


1 package test;
2
3 import java.util.logging.Logger JavaDoc;
4
5 import javax.resource.spi.ResourceAdapter JavaDoc;
6 import javax.resource.spi.ResourceAdapterInternalException JavaDoc;
7 import javax.resource.spi.BootstrapContext JavaDoc;
8
9 import com.caucho.jca.AbstractResourceAdapter;
10
11 /**
12  * Implements a resource which is a plain-old bean.
13  *
14  * The resource is configured in the resin.conf (or web.xml) using
15  * bean-style configuration and saved in JNDI.
16  *
17  * <pre>
18  * &lt;resource name="test/basic"
19  * type="test.TestResource">
20  * &lt;init>
21  * &lt;value>sample configuration&lt;/value>
22  * &lt;/init>
23  * &lt;/resource>
24  * </pre>
25  *
26  * <p>Applications will use JNDI to retrieve the resource:</p>
27  *
28  * <code><pre>
29  * Context ic = new InitialContext();
30  * TestResource resource = (TestResource) ic.lookup("java:comp/env/test/basic");
31  * </pre></code>
32  */

33 public class TestResource {
34   private static final Logger JavaDoc log =
35     Logger.getLogger(TestResource.class.getName());
36
37   /**
38    * Sample initialization param set by the <resource>
39    */

40   private String JavaDoc _value = "default";
41
42   /**
43    * Sets the value.
44    */

45   public void setValue(String JavaDoc value)
46   {
47     _value = value;
48   }
49
50   /**
51    * init() is called at the end of the configuration.
52    */

53   public void init()
54   {
55     log.config("TestResource[" + _value + "] init");
56   }
57
58   /**
59    * Returns a printable version of the resource.
60    */

61   public String JavaDoc toString()
62   {
63     return "TestResource[" + _value + "]";
64   }
65 }
66
Popular Tags