KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > mdb > containermanaged > ejbref > MDBEjbRef


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: MDBEjbRef.java 796 2006-06-28 12:07:13Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.ejbref;
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.checkBeanRef;
38
39 import javax.annotation.Resource;
40 import javax.ejb.ActivationConfigProperty JavaDoc;
41 import javax.ejb.EJB JavaDoc;
42 import javax.ejb.EJBs JavaDoc;
43 import javax.ejb.MessageDriven JavaDoc;
44 import javax.ejb.MessageDrivenContext JavaDoc;
45 import javax.jms.Message JavaDoc;
46 import javax.jms.MessageListener JavaDoc;
47
48 import org.objectweb.easybeans.log.JLog;
49 import org.objectweb.easybeans.log.JLogFactory;
50 import org.objectweb.easybeans.tests.common.ejbs.base.ItfOneMethod01;
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 ejb references in the environement.
56  * Operations:<li>Declaration using annotation.</li> <li>Declaration using XML.</li>
57  * <li>Injection in a field using annotation.</li> <li>Injection in a method
58  * using annotation.</li> <li>Injection in a field using XML.</li> <li>Injection
59  * in a method using XML.</li> <li>Override an injection in a field with a
60  * XML.</li><li>Override an injection in a method with a
61  * XML.</li>
62  * @author Eduardo Studzinski Estima de Castro
63  * @author Gisele Pinheiro Souza
64  */

65 @MessageDriven JavaDoc(messageListenerInterface = MessageListener JavaDoc.class, activationConfig = {
66         @ActivationConfigProperty JavaDoc(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
67         @ActivationConfigProperty JavaDoc(propertyName = "destination", propertyValue = JMSManager.DEFAULT_QUEUE),
68         @ActivationConfigProperty JavaDoc(propertyName = "messageSelector", propertyValue = "TYPE = 'org.objectweb.easybeans.tests."
69                 + "common.ejbs.mdb.containermanaged.ejbref.MDBEjbRef'")})
70
71 @EJBs JavaDoc({
72     @EJB JavaDoc(name = "ejb/beanDeclaration00", beanInterface=ItfOneMethod01.class, beanName="EJBInjectionBean"),
73     @EJB JavaDoc(name = "ejb/beanDeclaration01", beanInterface=ItfOneMethod01.class, beanName="EJBInjectionBean")
74     })
75 @EJB JavaDoc(name = "ejb/beanDeclaration02", beanInterface=ItfOneMethod01.class, beanName="EJBInjectionBean")
76 public class MDBEjbRef extends BaseInsertOperation{
77
78     /**
79      * Message type.
80      */

81     public static final String JavaDoc MESSAGE_TYPE = "org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.ejbref."
82             + "MDBEjbRef";
83
84     /**
85      * Logger.
86      */

87     private static JLog logger = JLogFactory.getLog(MDBEjbRef.class);
88
89     /**
90      * Bean.
91      */

92     @SuppressWarnings JavaDoc("unused")
93     @EJB JavaDoc(name="ejb/beanFieldInjection", beanName = "EJBInjectionBean")
94     private ItfOneMethod01 beanFieldInjection;
95
96     /**
97      * Bean.
98      */

99     @SuppressWarnings JavaDoc("unused")
100     @EJB JavaDoc(name="ejb/beanOverrideField", beanName = "EJBInjectionBean")
101     private ItfOneMethod01 beanOverrideFieldInjection;
102
103     /**
104      * Bean.
105      */

106     private ItfOneMethod01 beanMethodInjection;
107
108     /**
109      * Bean.
110      */

111     private ItfOneMethod01 beanXMLMethodInjection;
112
113     /**
114      * Bean.
115      */

116     private ItfOneMethod01 beanXMLFieldInjection;
117
118     /**
119      * Bean.
120      */

121     private ItfOneMethod01 beanOverrideMethodInjection;
122
123     /**
124      * Setter method.
125      * @param b bean
126      */

127     @EJB JavaDoc(name = "ejb/beanMethodInjection", beanName = "EJBInjectionBean")
128     public void setMethodInjection(final ItfOneMethod01 b){
129         beanMethodInjection = b;
130     }
131
132     /**
133      * Setter method.
134      * @param b bean
135      */

136     public void setXMLMethodInjection(final ItfOneMethod01 b){
137         beanXMLMethodInjection = b;
138     }
139
140     /**
141      * Setter method.
142      * @param b bean
143      */

144     @EJB JavaDoc(name = "ejb/beanOverrideMethod", beanName = "EJBInjectionBean")
145     public void setOverrideMethodInjection(final ItfOneMethod01 b){
146         beanOverrideMethodInjection = b;
147     }
148
149     /**
150      * Context.
151      */

152     @Resource
153     private MessageDrivenContext JavaDoc ctx;
154
155     /**
156      * Tests declaration and injection.
157      * @param message msg
158      */

159     public void onMessage(final Message JavaDoc message) {
160
161         //Declaration using annotation.
162
try {
163             checkBeanRef(ctx, "ejb/beanDeclaration00", ItfOneMethod01.class);
164             checkBeanRef(ctx, "ejb/beanDeclaration01", ItfOneMethod01.class);
165             super.log(MDBEjbRef.class, ON_MESSAGE, MDBEjbRef.class, ANNOTATION_RESOURCES_DECLARATION);
166             logger.debug("{0} is working properly.", ANNOTATION_RESOURCES_DECLARATION.toString());
167         } catch (Exception JavaDoc e) {
168             logger.debug("Error checking {0}: {1}", ANNOTATION_RESOURCES_DECLARATION.toString(), e.getMessage());
169         }
170         try {
171             checkBeanRef(ctx, "ejb/beanDeclaration02", ItfOneMethod01.class);
172             super.log(MDBEjbRef.class, ON_MESSAGE, MDBEjbRef.class, ANNOTATION_RESOURCE_DECLARATION);
173             logger.debug("{0} is working properly.", ANNOTATION_RESOURCE_DECLARATION.toString());
174         } catch (Exception JavaDoc e) {
175             logger.debug("Error checking {0}: {1}", ANNOTATION_RESOURCE_DECLARATION.toString(), e.getMessage());
176         }
177
178         //Declaration using XML.
179
try {
180             checkBeanRef(ctx, "ejb/beanXMLDeclaration", ItfOneMethod01.class);
181             super.log(MDBEjbRef.class, ON_MESSAGE, MDBEjbRef.class, XML_RESOURCE_DECLARATION);
182             logger.debug("{0} is working properly.", XML_RESOURCE_DECLARATION.toString());
183         } catch (Exception JavaDoc e) {
184             logger.debug("Error checking {0}: {1}", XML_RESOURCE_DECLARATION.toString(), e.getMessage());
185         }
186
187         //Injection in a field using annotation.
188
try {
189             assert beanFieldInjection.getBool();
190             checkBeanRef(ctx, "ejb/beanFieldInjection", ItfOneMethod01.class);
191             super.log(MDBEjbRef.class, ON_MESSAGE, MDBEjbRef.class, ANNOTATION_INJECTION_FIELD);
192             logger.debug("{0} is working properly.", ANNOTATION_INJECTION_FIELD.toString());
193         } catch (Exception JavaDoc e) {
194             logger.debug("Error checking {0}: {1}", ANNOTATION_INJECTION_FIELD.toString(), e.getMessage());
195         }
196
197         //Injection in a method using annotation.
198
try {
199             assert beanMethodInjection.getBool();
200             checkBeanRef(ctx, "ejb/beanMethodInjection", ItfOneMethod01.class);
201             super.log(MDBEjbRef.class, ON_MESSAGE, MDBEjbRef.class, ANNOTATION_INJECTION_METHOD);
202             logger.debug("{0} is working properly.", ANNOTATION_INJECTION_METHOD.toString());
203         } catch (Exception JavaDoc e) {
204             logger.debug("Error checking {0}: {1}", ANNOTATION_INJECTION_METHOD.toString(), e.getMessage());
205         }
206
207         //Injection in a field using XML.
208
try {
209             assert beanXMLFieldInjection.getBool();
210             checkBeanRef(ctx, "ejb/beanXMLFieldInjection", ItfOneMethod01.class);
211             super.log(MDBEjbRef.class, ON_MESSAGE, MDBEjbRef.class, XML_INJECTION_FIELD);
212             logger.debug("{0} is working properly.", XML_INJECTION_FIELD.toString());
213         } catch (Exception JavaDoc e) {
214             logger.debug("Error checking {0}: {1}", XML_INJECTION_FIELD.toString(), e.getMessage());
215         }
216
217         //Injection in a method using XML.
218
try {
219             assert beanXMLMethodInjection.getBool();
220             checkBeanRef(ctx, "ejb/beanXMLMethodInjection", ItfOneMethod01.class);
221             super.log(MDBEjbRef.class, ON_MESSAGE, MDBEjbRef.class, XML_INJECTION_METHOD);
222             logger.debug("{0} is working properly.", XML_INJECTION_METHOD.toString());
223         } catch (Exception JavaDoc e) {
224             logger.debug("Error checking {0}: {1}", XML_INJECTION_METHOD.toString(), e.getMessage());
225         }
226
227         //Override an injection in a field with a XML.
228
try {
229             //Attention: the "ejb/beanOverrideFieldInjection" is the injection declared using the XML.
230
assert beanOverrideFieldInjection.getBool();
231             checkBeanRef(ctx, "ejb/beanOverrideFieldInjection", ItfOneMethod01.class);
232             super.log(MDBEjbRef.class, ON_MESSAGE, MDBEjbRef.class, OVERRIDE_INJECTION_FIELD);
233             logger.debug("{0} is working properly.", OVERRIDE_INJECTION_FIELD.toString());
234         } catch (Exception JavaDoc e) {
235             logger.debug("Error checking {0}: {1}", OVERRIDE_INJECTION_FIELD.toString(), e.getMessage());
236         }
237
238         //Override an injection in a method with a XML.
239
try {
240             //Attention: the "ejb/beanOverrideMethodInjection" is the injection declared using the XML.
241
assert beanOverrideMethodInjection.getBool();
242             checkBeanRef(ctx, "ejb/beanOverrideMethodInjection", ItfOneMethod01.class);
243             super.log(MDBEjbRef.class, ON_MESSAGE, MDBEjbRef.class, OVERRIDE_INJECTION_METHOD);
244             logger.debug("{0} is working properly.", OVERRIDE_INJECTION_METHOD.toString());
245         } catch (Exception JavaDoc e) {
246             logger.debug("Error checking {0}: {1}", OVERRIDE_INJECTION_METHOD.toString(), e.getMessage());
247         }
248     }
249 }
250
Popular Tags