KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > earsample > resourceadapters > ResourceAdapterImpl


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: ResourceAdapterImpl.java,v 1.1 2005/06/14 14:38:40 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.earsample.resourceadapters;
27
28
29 import java.net.MalformedURLException JavaDoc;
30 import java.util.HashMap JavaDoc;
31
32 import javax.naming.InitialContext JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34 import javax.resource.NotSupportedException JavaDoc;
35 import javax.resource.ResourceException JavaDoc;
36 import javax.resource.spi.ActivationSpec JavaDoc;
37 import javax.resource.spi.BootstrapContext JavaDoc;
38 import javax.resource.spi.ResourceAdapterInternalException JavaDoc;
39 import javax.resource.spi.endpoint.MessageEndpointFactory JavaDoc;
40 import javax.transaction.xa.XAResource JavaDoc;
41
42 /**
43  * A Resource adapter
44  * @author kemlerp
45  *
46  */

47 public class ResourceAdapterImpl implements javax.resource.spi.ResourceAdapter JavaDoc, java.io.Serializable JavaDoc {
48
49
50     /**
51      * serialVersionUID
52      */

53     private static final long serialVersionUID = 3834312812943456568L;
54
55     /**
56      * String should be the RA name when set, ie, EIS
57      */

58     private String JavaDoc eisurl;
59
60     /**
61      * The JNDI name
62      */

63     private String JavaDoc jndiName;
64
65     /**
66      * Initial context
67      */

68     private InitialContext JavaDoc ictx;
69
70     /**
71      * BootstrapContext
72      */

73     private BootstrapContext JavaDoc bootstrapCtx = null; // set in start()
74

75     /**
76      * EndpointFactories
77      */

78     private transient HashMap JavaDoc endpointFactories = new HashMap JavaDoc();
79
80
81     /**
82      * Start
83      * @param bootstrapCtx bootstrapCtx
84      * @throws ResourceAdapterInternalException if an error occurs
85      */

86     public void start(BootstrapContext JavaDoc bootstrapCtx) throws ResourceAdapterInternalException JavaDoc {
87         this.bootstrapCtx = bootstrapCtx;
88
89         try {
90             ictx = new InitialContext JavaDoc();
91             ictx.bind(jndiName, eisurl);
92         } catch (NamingException JavaDoc e) {
93             e.printStackTrace();
94         }
95
96     }
97
98     /**
99      * Stop
100      */

101     public void stop() {
102         try {
103             ictx.unbind(jndiName);
104         } catch (NamingException JavaDoc e) {
105             e.printStackTrace();
106         }
107     }
108
109
110     /**
111      * Called by the application server when a message-driven bean
112      * (MessageEndpoint) is deployed.
113      * @param factory MessageEndpointFactory
114      * @param spec activation spec
115      * @throws NotSupportedException if an error occurs
116      * @throws ResourceAdapterInternalException if an error occurs
117      */

118     public void endpointActivation(MessageEndpointFactory JavaDoc factory, ActivationSpec JavaDoc spec) throws NotSupportedException JavaDoc,
119             ResourceAdapterInternalException JavaDoc {
120             endpointFactories.put(spec, factory);
121     }
122
123     /**
124      * Endpoint Deactivation
125      * @param factory MessageEndpointFactory
126      * @param spec activation spec
127      */

128     public void endpointDeactivation(MessageEndpointFactory JavaDoc factory, ActivationSpec JavaDoc spec) {
129         endpointFactories.remove(spec);
130     }
131
132     /**
133      * Get XAResources
134      * @param specs A tab of specs
135      * @throws ResourceException if an error occurs
136      * @return Tab of XAResources
137      */

138     public XAResource JavaDoc[] getXAResources(ActivationSpec JavaDoc[] specs) throws ResourceException JavaDoc {
139         return null;
140     }
141
142     /**
143      * Get Eis URL
144      * @return Eis URL
145      */

146     public String JavaDoc getEisURL() {
147         return eisurl.toString();
148     }
149
150     /**
151      * Set Eis URL
152      * @param eisURL Eis URL
153      * @throws MalformedURLException if 'eisURL' is not a URL
154      */

155     public void setEisURL(String JavaDoc eisURL) throws MalformedURLException JavaDoc {
156         // ra.xml deployment supplies value
157
this.eisurl = eisURL;
158     }
159
160     /**
161      * Get BootstrapContext
162      * @return bootstrapCtx
163      */

164     public BootstrapContext JavaDoc getBootstrapCtx() {
165         return bootstrapCtx;
166     }
167
168     /**
169      * Set BootstrapContext
170      * @param bootstrapCtx bootstrapContext
171      */

172     public void setBootstrapCtx(BootstrapContext JavaDoc bootstrapCtx) {
173         this.bootstrapCtx = bootstrapCtx;
174     }
175
176     /**
177      * Get used JNDI name
178      * @return A string
179      */

180     public String JavaDoc getJndiName() {
181         return jndiName;
182     }
183
184     /**
185      * Set JNDI name
186      * @param jndiName a string
187      */

188     public void setJndiName(String JavaDoc jndiName) {
189         this.jndiName = jndiName;
190     }
191 }
192
Popular Tags