001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: SLSBResourceRefMethodInjection00.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.resourceref;
025:
026: import static org.ow2.easybeans.tests.common.helper.ContextHelper.checkResource;
027:
028: import java.net.URL;
029:
030: import javax.annotation.Resource;
031: import javax.ejb.EJBContext;
032: import javax.ejb.Remote;
033: import javax.ejb.SessionContext;
034: import javax.ejb.Stateless;
035: import javax.jms.ConnectionFactory;
036: import javax.jms.Queue;
037: import javax.jms.QueueConnectionFactory;
038: import javax.jms.Topic;
039: import javax.jms.TopicConnectionFactory;
040: import javax.mail.Session;
041: import javax.sql.DataSource;
042:
043: import org.ow2.easybeans.tests.common.ejbs.base.ItfResourceEnvRef00;
044:
045: /**
046: * This bean is used to test injection of resource references in setter methods.
047: * @author Eduardo Studzinski Estima de Castro
048: * @author Gisele Pinheiro Souza
049: */
050: @Stateless(name="SLSBResourceRefMethodInjection00")
051: @Remote(ItfResourceEnvRef00.class)
052: public class SLSBResourceRefMethodInjection00 implements
053: ItfResourceEnvRef00 {
054:
055: /**
056: * SessionContext.
057: */
058: @Resource
059: private SessionContext sessionContext;
060:
061: /**
062: * The reference must be injected by the container.
063: */
064: private DataSource dsInjection00;
065:
066: /**
067: * Setter method. It is an injection target.
068: * @param ds Data Source
069: */
070: @Resource(name="jdbc/ds00")
071: public void setJDBC00(final DataSource ds) {
072: dsInjection00 = ds;
073: }
074:
075: /**
076: * The reference must be injected by the container.
077: */
078: private DataSource dsInjection01;
079:
080: /**
081: * Setter method. It is an injection target.
082: * @param ds Data Source
083: */
084: @Resource(name="jdbc/ds01",mappedName="jdbc_1")
085: public void setJDBC01(final DataSource ds) {
086: dsInjection01 = ds;
087: }
088:
089: /**
090: * The reference must be injected by the container.
091: */
092: private DataSource dsInjection02;
093:
094: /**
095: * Setter method. It is an injection target.
096: * @param ds Data Source
097: */
098: @Resource(name="jdbc/ds02",shareable=true)
099: public void setJDBC02(final DataSource ds) {
100: dsInjection02 = ds;
101: }
102:
103: /**
104: * The reference must be injected by the container.
105: */
106: private DataSource ds03;
107:
108: /**
109: * Setter method. It is an injection target.
110: * @param ds Data Source
111: */
112: @Resource
113: public void setDs03(final DataSource ds) {
114: ds03 = ds;
115: }
116:
117: /**
118: * The reference must be injected by the container.
119: */
120: private ConnectionFactory cfInjection00;
121:
122: /**
123: * Setter method. It is an injection target.
124: * @param con Connection Factory
125: */
126: @Resource(name="jms/cf00")
127: public void setConFactory00(final ConnectionFactory con) {
128: cfInjection00 = con;
129: }
130:
131: /**
132: * The reference must be injected by the container.
133: */
134: private ConnectionFactory conFactory01;
135:
136: /**
137: * Setter method. It is an injection target.
138: * @param con Connection Factory
139: */
140: @Resource(type=ConnectionFactory.class)
141: public void setConFactory01(final ConnectionFactory con) {
142: conFactory01 = con;
143: }
144:
145: /**
146: * The reference must be injected by the container.
147: */
148:
149: private QueueConnectionFactory queueConFactory00;
150:
151: /**
152: * Setter method. It is an injection target.
153: * @param con Queue Connection Factory
154: */
155: @Resource(name="jms/qcf00")
156: public void setQueueConFactory00(final QueueConnectionFactory con) {
157: queueConFactory00 = con;
158: }
159:
160: /**
161: * The reference must be injected by the container.
162: */
163:
164: private TopicConnectionFactory topicConFactory00;
165:
166: /**
167: * Setter method. It is an injection target.
168: * @param con Topic Connection Factory
169: */
170: @Resource(name="jms/tcf00")
171: public void setTopicConFactory00(final TopicConnectionFactory con) {
172: topicConFactory00 = con;
173: }
174:
175: /**
176: * The reference must be injected by the container.
177: */
178:
179: private Queue queue00;
180:
181: /**
182: * Setter method. It is an injection target.
183: * @param q queueu
184: */
185: @Resource(name="jms/queue00")
186: public void setQueue00(final Queue q) {
187: queue00 = q;
188: }
189:
190: /**
191: * The reference must be injected by the container.
192: */
193:
194: private Topic topic00;
195:
196: /**
197: * Setter method. It is an injection target.
198: * @param t topic
199: */
200: @Resource(name="jms/topic00")
201: public void setQueue00(final Topic t) {
202: topic00 = t;
203: }
204:
205: /**
206: * The reference must be injected by the container.
207: */
208: private Session mail00;
209:
210: /**
211: * Setter method. It is an injection target.
212: * @param session Mail Session
213: */
214: @Resource(name="mail/mail00")
215: public void setTopicConFactory00(final Session session) {
216: mail00 = session;
217: }
218:
219: /**
220: * The reference must be injected by the container.
221: */
222: private URL url00;
223:
224: /**
225: * Setter method. It is an injection target.
226: * @param url url
227: */
228: @Resource(name="url/url00")
229: public void setUrl00(final URL url) {
230: url00 = url;
231: }
232:
233: /**
234: * The reference must be injected by the container.
235: */
236: private EJBContext ctx00;
237:
238: /**
239: * Setter method. It is an injection target.
240: * @param ctx reference
241: */
242: @Resource(name="ejbctx/ctx00")
243: public void setCtx00(final EJBContext ctx) {
244: ctx00 = ctx;
245: }
246:
247: /**
248: * Checks if the annotation @Resource on a method is working properly to ejb context resource.
249: */
250: public void checkJDBC() {
251: checkResource(sessionContext, dsInjection00, "jdbc/ds00");
252: checkResource(sessionContext, dsInjection01, "jdbc/ds01");
253: checkResource(sessionContext, dsInjection02, "jdbc/ds02");
254: checkResource(
255: sessionContext,
256: ds03,
257: "org.ow2.easybeans.tests.common."
258: + "ejbs.stateless.containermanaged.resourceref.SLSBResourceRefMethodInjection00/ds03");
259: }
260:
261: /**
262: * Checks if the annotation @Resource on a method is working properly to ejb context resource.
263: */
264: public void checkJMSConFactory() {
265: checkResource(sessionContext, cfInjection00, "jms/cf00");
266: checkResource(
267: sessionContext,
268: conFactory01,
269: "org.ow2.easybeans.tests."
270: + "common.ejbs.stateless.containermanaged.resourceref.SLSBResourceRefMethodInjection00/conFactory01");
271: }
272:
273: /**
274: * Checks if the annotation @Resource on a method is working properly to ejb context resource.
275: */
276: public void checkJMSQueueConFactory() {
277: checkResource(sessionContext, queueConFactory00, "jms/qcf00");
278: }
279:
280: /**
281: * Checks if the annotation @Resource on a method is working properly to ejb context resource.
282: */
283: public void checkJMSTopicConFactory() {
284: checkResource(sessionContext, topicConFactory00, "jms/tcf00");
285: }
286:
287: /**
288: * Checks if the annotation @Resource on a method is working properly to ejb context resource.
289: */
290: public void checkMailSession() {
291: checkResource(sessionContext, mail00, "mail/mail00");
292: }
293:
294: /**
295: * Checks if the annotation @Resource on a method is working properly to ejb context resource.
296: */
297: public void checkUrl() {
298: checkResource(sessionContext, url00, "url/url00");
299: }
300:
301: /**
302: * Checks if the annotation @Resource on a method is working properly to ejb context resource.
303: */
304: public void checkEJBContext() {
305: checkResource(sessionContext, ctx00, "ejbctx/ctx00");
306: }
307:
308: /**
309: * Checks if the annotation @Resource on a method is working properly to ejb context resource.
310: */
311: public void checkJMSQueue() {
312: checkResource(sessionContext, queue00, "jms/queue00");
313: }
314:
315: /**
316: * Checks if the annotation @Resource on a method is working properly to ejb context resource.
317: */
318: public void checkJMSTopic() {
319: checkResource(sessionContext, topic00, "jms/topic00");
320: }
321: }
|