KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > stateless > containermanaged > resourceref > SLSBResourceRefFieldInjection00


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@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: SLSBResourceRefFieldInjection00.java 990 2006-07-31 13:09:09Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.resourceref;
26
27 import static org.objectweb.easybeans.tests.common.helper.ContextHelper.checkResource;
28
29 import java.net.URL JavaDoc;
30
31 import javax.annotation.Resource;
32 import javax.annotation.Resource.AuthenticationType;
33 import javax.ejb.EJBContext JavaDoc;
34 import javax.ejb.Remote JavaDoc;
35 import javax.ejb.SessionContext JavaDoc;
36 import javax.ejb.Stateless JavaDoc;
37 import javax.jms.ConnectionFactory JavaDoc;
38 import javax.jms.Queue JavaDoc;
39 import javax.jms.QueueConnectionFactory JavaDoc;
40 import javax.jms.Topic JavaDoc;
41 import javax.jms.TopicConnectionFactory JavaDoc;
42 import javax.mail.Session JavaDoc;
43 import javax.sql.DataSource JavaDoc;
44
45 import org.objectweb.easybeans.tests.common.db.TableManager;
46 import org.objectweb.easybeans.tests.common.ejbs.base.ItfResourceEnvRef00;
47
48 /**
49  * This bean is used to test injection of resource references in fields.
50  * @author Eduardo Studzinski Estima de Castro
51  * @author Gisele Pinheiro Souza
52  */

53 @Stateless JavaDoc(name = "SLSBResourceRefFieldInjection00")
54 @Remote JavaDoc(ItfResourceEnvRef00.class)
55 public class SLSBResourceRefFieldInjection00 implements ItfResourceEnvRef00 {
56
57     /**
58      * SessionContext.
59      */

60     @Resource
61     private SessionContext JavaDoc sessionContext;
62
63     /**
64      * The reference must be injected by the container.
65      */

66     @Resource(name = "jdbc/ds00")
67     private DataSource JavaDoc dsInjection00;
68
69     /**
70      * The reference must be injected by the container.
71      */

72     @Resource(name = "jdbc/ds01", mappedName = "jdbc_1")
73     private DataSource JavaDoc dsInjection01;
74
75     /**
76      * The reference must be injected by the container.
77      */

78     @Resource(name = "jdbc/ds02", shareable = true,
79             description = "Another jdbc.", authenticationType = AuthenticationType.CONTAINER)
80     private DataSource JavaDoc dsInjection02;
81
82     /**
83      * The reference must be injected by the container.
84      */

85     @Resource
86     private DataSource JavaDoc ds03;
87
88     /**
89      * The reference must be injected by the container using
90      * injection-target(XML).
91      */

92     private DataSource JavaDoc ds04;
93
94     /**
95      * The reference must be injected by the container using the xml descriptor,
96      * so the jdbc_2 must be injected.
97      */

98     @Resource(name = "jdbc/ds05", mappedName = "jdbc_1")
99     private DataSource JavaDoc ds05;
100
101     /**
102      * The reference must be injected by the container.
103      */

104     @Resource(name = "jms/cf00")
105     private ConnectionFactory JavaDoc cfInjection00;
106
107     /**
108      * The reference must be injected by the container.
109      */

110     @Resource
111     private ConnectionFactory JavaDoc conFactory01;
112
113     /**
114      * The reference must be injected by the container using
115      * injection-target(XML).
116      */

117     private ConnectionFactory JavaDoc conFactory02;
118
119     /**
120      * The reference must be injected by the container.
121      */

122     @Resource(name = "jms/qcf00")
123     private QueueConnectionFactory JavaDoc queueConFactory00;
124
125     /**
126      * The reference must be injected by the container.
127      */

128     @Resource(name = "jms/tcf00")
129     private TopicConnectionFactory JavaDoc topicConFactory00;
130
131     /**
132      * The reference must be injected by the container.
133      */

134     @Resource(name = "jms/queue00")
135     private Queue JavaDoc queue00;
136
137     /**
138      * The reference must be injected by the container.
139      */

140     @Resource(name = "jms/topic00")
141     private Topic JavaDoc topic00;
142
143     /**
144      * The reference must be injected by the container.
145      */

146     @Resource(name = "mail/mail00")
147     private Session JavaDoc mail00;
148
149     /**
150      * The reference must be injected by the container.
151      */

152     @Resource(name = "url/url00")
153     private URL JavaDoc url00;
154
155     /**
156      * The reference must be injected by the container.
157      */

158     @Resource(name = "ejbctx/ctx00")
159     private EJBContext JavaDoc ctx00;
160
161     /**
162      * Checks if the annotation @Resource on a field is working properly to
163      * url resource.
164      */

165     public void checkJDBC() {
166         checkResource(sessionContext, dsInjection00, "jdbc/ds00");
167         checkResource(sessionContext, dsInjection01, "jdbc/ds01");
168         checkResource(sessionContext, dsInjection02, "jdbc/ds02");
169         checkResource(sessionContext, ds03, "org.objectweb.easybeans.tests.common.ejbs."
170                 + "stateless.containermanaged.resourceref.SLSBResourceRefFieldInjection00/ds03");
171
172         // The reference must be injected by the container using the xml
173
// descriptor, so the jdbc_2 must be injected.
174
checkResource(sessionContext, ds04, "jdbc/ds04");
175
176         TableManager cTest00 = new TableManager(dsInjection02);
177         TableManager cTest01 = new TableManager(ds05);
178         try {
179             // It must create twice the table, because each is in a different
180
// database.
181
cTest00.insertTable("ds04");
182             cTest01.insertTable("ds04");
183
184             cTest00.deleteTable("ds04");
185             cTest01.deleteTable("ds04");
186         } catch (Exception JavaDoc e) {
187             throw new IllegalStateException JavaDoc("Exception: " + e.getMessage());
188         }
189     }
190
191     /**
192      * Checks if the annotation @Resource on a field is working properly to
193      * url resource.
194      */

195     public void checkJMSConFactory() {
196         checkResource(sessionContext, cfInjection00, "jms/cf00");
197         checkResource(sessionContext, conFactory01, "org.objectweb.easybeans."
198                 + "tests.common.ejbs.stateless.containermanaged.resourceref.SLSBResourceRefFieldInjection00/conFactory01");
199         checkResource(sessionContext, conFactory02, "jms/cf02");
200     }
201
202     /**
203      * Checks if the annotation @Resource on a field is working properly to
204      * url resource.
205      */

206     public void checkJMSQueueConFactory() {
207         checkResource(sessionContext, queueConFactory00, "jms/qcf00");
208     }
209
210     /**
211      * Checks if the annotation @Resource on a field is working properly to
212      * url resource.
213      */

214     public void checkJMSTopicConFactory() {
215         checkResource(sessionContext, topicConFactory00, "jms/tcf00");
216     }
217
218     /**
219      * Checks if the annotation @Resource on a field is working properly to
220      * mail session resource.
221      */

222     public void checkMailSession() {
223         checkResource(sessionContext, mail00, "mail/mail00");
224     }
225
226     /**
227      * Checks if the annotation @Resource on a field is working properly to
228      * url resource.
229      */

230     public void checkUrl() {
231         checkResource(sessionContext, url00, "url/url00");
232     }
233
234     /**
235      * Checks if the annotation @Resource on a field is working properly to
236      * ejb context resource.
237      */

238     public void checkEJBContext() {
239         checkResource(sessionContext, ctx00, "ejbctx/ejb00");
240     }
241
242     /**
243      * Checks if the annotation @Resource on a field is working properly to
244      * url resource.
245      */

246     public void checkJMSQueue() {
247         checkResource(sessionContext, queue00, "jms/queue00");
248     }
249
250     /**
251      * Checks if the annotation @Resource on a field is working properly to
252      * url resource.
253      */

254     public void checkJMSTopic() {
255         checkResource(sessionContext, topic00, "jms/topic00");
256     }
257 }
258
Popular Tags