KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > mdb > containermanaged > resourceref > MDBResourceRef


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: MDBResourceRef.java 1122 2006-09-27 09:24:54Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.resourceref;
26
27 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.ON_MESSAGE;
28 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.ANNOTATION_INJECTION_FIELD;
29 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.ANNOTATION_INJECTION_METHOD;
30 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.ANNOTATION_RESOURCES_DECLARATION;
31 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.ANNOTATION_RESOURCE_DECLARATION;
32 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.OVERRIDE_INJECTION_FIELD;
33 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.OVERRIDE_INJECTION_METHOD;
34 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.XML_INJECTION_FIELD;
35 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.XML_INJECTION_METHOD;
36 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.XML_RESOURCE_DECLARATION;
37 import static org.objectweb.easybeans.tests.common.helper.ContextHelper.checkResource;
38
39 import javax.annotation.Resource;
40 import javax.annotation.Resources;
41 import javax.ejb.ActivationConfigProperty JavaDoc;
42 import javax.ejb.MessageDriven JavaDoc;
43 import javax.ejb.MessageDrivenContext JavaDoc;
44 import javax.jms.Message JavaDoc;
45 import javax.jms.MessageListener JavaDoc;
46 import javax.sql.DataSource JavaDoc;
47
48 import org.objectweb.easybeans.log.JLog;
49 import org.objectweb.easybeans.log.JLogFactory;
50 import org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.simpleentry.MDBSimpleEntryEnv;
51 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertOperation;
52 import org.objectweb.easybeans.tests.common.jms.JMSManager;
53
54 /**
55  * This bean is used to test the "resource" annotation on the bean class.
56  * Resources will be declared in the environment, but they will not be injected.
57  * @author Eduardo Studzinski Estima de Castro
58  * @author Gisele Pinheiro Souza
59  */

60 @MessageDriven JavaDoc(name = "MDBResourceRef", messageListenerInterface = MessageListener JavaDoc.class, activationConfig = {
61         @ActivationConfigProperty JavaDoc(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
62         @ActivationConfigProperty JavaDoc(propertyName = "destination", propertyValue = JMSManager.DEFAULT_QUEUE),
63         @ActivationConfigProperty JavaDoc(propertyName = "messageSelector", propertyValue = "TYPE = 'org.objectweb.easybeans.tests."
64                 + "common.ejbs.mdb.containermanaged.resourceref.MDBResourceRef'")})
65 @Resources({@Resource(name = "jdbc/ds00", type = javax.sql.DataSource JavaDoc.class)})
66 @Resource(name = "jdbc/ds01", type = javax.sql.DataSource JavaDoc.class)
67 public class MDBResourceRef extends BaseInsertOperation {
68
69     /**
70      * Logger.
71      */

72     private static JLog logger = JLogFactory.getLog(MDBResourceRef.class);
73
74     /**
75      * Message type.
76      */

77     public static final String JavaDoc MESSAGE_TYPE = "org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.resourceref."
78             + "MDBResourceRef";
79
80     /**
81      * Context.
82      */

83     @Resource
84     private MessageDrivenContext JavaDoc ctx;
85
86     /**
87      * Field.
88      */

89     private DataSource JavaDoc dsMethodInjection;
90
91     /**
92      * The value must be injected by the container.
93      */

94     @Resource(name = "jdbc/dsFieldInjection")
95     private DataSource JavaDoc dsFieldInjection;
96
97     /**
98      * The value must be injected by the container using the XML value.
99      */

100     private DataSource JavaDoc dsXMLFieldInjection;
101
102     /**
103      * The value must be injected by the container using the XML value.
104      */

105     private DataSource JavaDoc dsXMLMethodInjection;
106
107     /**
108      * The value must be injected by the container using the XML value (Override
109      * test).
110      */

111     @Resource(name = "jdbc/dsOverrideField")
112     private DataSource JavaDoc dsOverrideFieldInjection;
113
114     /**
115      * The value must be injected by the container using the XML value (Override
116      * test).
117      */

118     private DataSource JavaDoc dsOverrideMethodInjection;
119
120     /**
121      * The value must be injected by the container.
122      * @param value information value
123      */

124     @SuppressWarnings JavaDoc("unused")
125     @Resource(name = "jdbc/dsMethodInjection")
126     private void setMethodInjection(final DataSource JavaDoc value) {
127         dsMethodInjection = value;
128     }
129
130     /**
131      * The value must be injected by the container.
132      * @param value information value
133      */

134     @SuppressWarnings JavaDoc("unused")
135     private void setXMLMethodInjection(final DataSource JavaDoc value) {
136         dsXMLMethodInjection = value;
137     }
138
139     /**
140      * The value must be injected by the container.
141      * @param value information value
142      */

143     @SuppressWarnings JavaDoc("unused")
144     @Resource(name = "jdbc/dsOverrideMethod")
145     private void setOverrideMethodInjection(final DataSource JavaDoc value) {
146         dsOverrideMethodInjection = value;
147     }
148
149     /**
150      * Tests declaration and injection.
151      * @param message msg
152      */

153     public void onMessage(final Message JavaDoc message) {
154
155         // Declaration using annotation.
156
try {
157             checkResource(ctx, "jdbc/dsDeclaration00");
158             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, ANNOTATION_RESOURCES_DECLARATION);
159             logger.debug("{0} is working properly.", ANNOTATION_RESOURCES_DECLARATION.toString());
160         } catch (Exception JavaDoc e) {
161             logger.error("Error checking {0}: {1}", ANNOTATION_RESOURCES_DECLARATION.toString(), e.getMessage());
162         }
163         try {
164             checkResource(ctx, "jdbc/dsDeclaration01");
165             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, ANNOTATION_RESOURCE_DECLARATION);
166             logger.debug("{0} is working properly.", ANNOTATION_RESOURCE_DECLARATION.toString());
167         } catch (Exception JavaDoc e) {
168             logger.error("Error checking {0}: {1}", ANNOTATION_RESOURCE_DECLARATION.toString(), e.getMessage());
169         }
170
171         // Declaration using XML.
172
try {
173             checkResource(ctx, "jdbc/dsXMLDeclaration");
174             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, XML_RESOURCE_DECLARATION);
175             logger.debug("{0} is working properly.", XML_RESOURCE_DECLARATION.toString());
176         } catch (Exception JavaDoc e) {
177             logger.error("Error checking {0}: {1}", XML_RESOURCE_DECLARATION.toString(), e.getMessage());
178         }
179
180         // Injection in a field using annotation.
181
try {
182
183             checkResource(ctx, dsFieldInjection, "jdbc/dsFieldInjection");
184             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, ANNOTATION_INJECTION_FIELD);
185             logger.debug("{0} is working properly.", ANNOTATION_INJECTION_FIELD.toString());
186         } catch (Exception JavaDoc e) {
187             logger.error("Error checking {0}: {1}", ANNOTATION_INJECTION_FIELD.toString(), e.getMessage());
188         }
189
190         // Injection in a method using annotation.
191
try {
192             checkResource(ctx, dsMethodInjection, "jdbc/dsMethodInjection");
193             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, ANNOTATION_INJECTION_METHOD);
194             logger.debug("{0} is working properly.", ANNOTATION_INJECTION_METHOD.toString());
195         } catch (Exception JavaDoc e) {
196             logger.error("Error checking {0}: {1}", ANNOTATION_INJECTION_METHOD.toString(), e.getMessage());
197         }
198
199         // Injection in a field using XML.
200
try {
201             checkResource(ctx, dsXMLFieldInjection, "jdbc/dsXMLFieldInjection");
202             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, XML_INJECTION_FIELD);
203             logger.debug("{0} is working properly.", XML_INJECTION_FIELD.toString());
204         } catch (Exception JavaDoc e) {
205             logger.error("Error checking {0}: {1}", XML_INJECTION_FIELD.toString(), e.getMessage());
206         }
207
208         // Injection in a method using XML.
209
try {
210             checkResource(ctx, dsXMLMethodInjection, "jdbc/dsXMLMethodInjection");
211             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, XML_INJECTION_METHOD);
212             logger.debug("{0} is working properly.", XML_INJECTION_METHOD.toString());
213         } catch (Exception JavaDoc e) {
214             logger.error("Error checking {0}: {1}", XML_INJECTION_METHOD.toString(), e.getMessage());
215         }
216
217         // Override an injection in a field with a XML.
218
try {
219             // Attention: the "jdbc/dsOverrideFieldInjection" is the injection
220
// declared using the XML.
221
checkResource(ctx, dsOverrideFieldInjection, "jdbc/dsOverrideFieldInjection");
222             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, OVERRIDE_INJECTION_FIELD);
223             logger.debug("{0} is working properly.", OVERRIDE_INJECTION_FIELD.toString());
224         } catch (Exception JavaDoc e) {
225             logger.error("Error checking {0}: {1}", OVERRIDE_INJECTION_FIELD.toString(), e.getMessage());
226         }
227
228         // Override an injection in a method with a XML.
229
try {
230             // Attention: the "jdbc/dsOverrideMethodInjection" is the injection
231
// declared using the XML.
232
checkResource(ctx, dsOverrideMethodInjection, "jdbc/dsOverrideMethodInjection");
233             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, OVERRIDE_INJECTION_METHOD);
234             logger.debug("{0} is working properly.", OVERRIDE_INJECTION_METHOD.toString());
235         } catch (Exception JavaDoc e) {
236             logger.error("Error checking {0}: {1}", OVERRIDE_INJECTION_METHOD.toString(), e.getMessage());
237         }
238     }
239
240 }
241
Popular Tags