KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > mdb > containermanaged > simpleentry > MDBSimpleEntryEnv


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

25 package org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.simpleentry;
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.checkSimpleEntry;
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
47 import org.objectweb.easybeans.log.JLog;
48 import org.objectweb.easybeans.log.JLogFactory;
49 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertOperation;
50 import org.objectweb.easybeans.tests.common.jms.JMSManager;
51
52 /**
53  * This bean is used to test the simple entries in the environement. Operations:
54  * <li>Declaration using annotation.</li> <li>Declaration using XML.</li>
55  * <li>Injection in a field using annotation.</li> <li>Injection in a method
56  * using annotation.</li> <li>Injection in a field using XML.</li> <li>Injection
57  * in a method using XML.</li> <li>Override an injection in a field with a
58  * XML.</li><li>Override an injection in a method with a
59  * XML.</li>
60  * @author Eduardo Studzinski Estima de Castro
61  * @author Gisele Pinheiro Souza
62  */

63 @MessageDriven JavaDoc(messageListenerInterface = MessageListener JavaDoc.class, activationConfig = {
64         @ActivationConfigProperty JavaDoc(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
65         @ActivationConfigProperty JavaDoc(propertyName = "destination", propertyValue = JMSManager.DEFAULT_QUEUE),
66         @ActivationConfigProperty JavaDoc(propertyName = "messageSelector", propertyValue = "TYPE = 'org.objectweb.easybeans.tests."
67             + "common.ejbs.mdb.containermanaged.simpleentry.MDBSimpleEntryEnv'")})
68 @Resources({@Resource(name = "simple/strDeclaration00", type = java.lang.String JavaDoc.class)})
69 @Resource(name = "simple/strDeclaration01", type = java.lang.String JavaDoc.class)
70 public class MDBSimpleEntryEnv extends BaseInsertOperation {
71
72     /**
73      * Message type.
74      */

75     public static final String JavaDoc MESSAGE_TYPE = "org.objectweb.easybeans.tests.common.ejbs.mdb."
76             + "containermanaged.simpleentry.MDBSimpleEntryEnv";
77
78     /**
79      * Logger.
80      */

81     private static JLog logger = JLogFactory.getLog(MDBSimpleEntryEnv.class);
82
83     /**
84      * Field.
85      */

86     private String JavaDoc strMethodInjection;
87
88     /**
89      * The value must be injected by the container.
90      */

91     @Resource(name = "simple/strFieldInjection")
92     private String JavaDoc strFieldInjection;
93
94     /**
95      * The value must be injected by the container using the XML value.
96      */

97     private String JavaDoc strXMLFieldInjection;
98
99     /**
100      * The value must be injected by the container using the XML value.
101      */

102     private String JavaDoc strXMLMethodInjection;
103
104     /**
105      * The value must be injected by the container using the XML value (Override
106      * test).
107      */

108     @Resource(name = "simple/strOverrideField")
109     private String JavaDoc strOverrideFieldInjection;
110
111     /**
112      * The value must be injected by the container using the XML value (Override
113      * test).
114      */

115     private String JavaDoc strOverrideMethodInjection;
116
117     /**
118      * The value must be injected by the container.
119      * @param value information value
120      */

121     @SuppressWarnings JavaDoc("unused")
122     @Resource(name = "simple/strMethodInjection")
123     private void setMethodInjection(final String JavaDoc value) {
124         strMethodInjection = value;
125     }
126
127     /**
128      * The value must be injected by the container.
129      * @param value information value
130      */

131     @SuppressWarnings JavaDoc("unused")
132     private void setXMLMethodInjection(final String JavaDoc value) {
133         strXMLMethodInjection = value;
134     }
135
136     /**
137      * The value must be injected by the container.
138      * @param value information value
139      */

140     @SuppressWarnings JavaDoc("unused")
141     @Resource(name ="simple/strOverrideMethod")
142     private void setOverrideMethodInjection(final String JavaDoc value) {
143         strOverrideMethodInjection = value;
144     }
145
146     /**
147      * Context.
148      */

149     @Resource
150     private MessageDrivenContext JavaDoc ctx;
151
152     /**
153      * Tests declaration and injection.
154      * @param message msg
155      */

156     public void onMessage(final Message JavaDoc message) {
157
158         //Declaration using annotation.
159
try {
160             checkSimpleEntry(ctx, "simple/strDeclaration00", "strDeclaration00");
161             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, ANNOTATION_RESOURCES_DECLARATION);
162             logger.debug("{0} is working properly.", ANNOTATION_RESOURCES_DECLARATION.toString());
163         } catch (Exception JavaDoc e) {
164             logger.debug("Error checking {0}: {1}", ANNOTATION_RESOURCES_DECLARATION.toString(), e.getMessage());
165         }
166         try {
167             checkSimpleEntry(ctx, "simple/strDeclaration01", "strDeclaration01");
168             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, ANNOTATION_RESOURCE_DECLARATION);
169             logger.debug("{0} is working properly.", ANNOTATION_RESOURCE_DECLARATION.toString());
170         } catch (Exception JavaDoc e) {
171             logger.debug("Error checking {0}: {1}", ANNOTATION_RESOURCE_DECLARATION.toString(), e.getMessage());
172         }
173
174
175         //Declaration using XML.
176
try {
177             checkSimpleEntry(ctx, "simple/strXMLDeclaration", "strXMLDeclaration00");
178             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, XML_RESOURCE_DECLARATION);
179             logger.debug("{0} is working properly.", XML_RESOURCE_DECLARATION.toString());
180         } catch (Exception JavaDoc e) {
181             logger.debug("Error checking {0}: {1}", XML_RESOURCE_DECLARATION.toString(), e.getMessage());
182         }
183
184         //Injection in a field using annotation.
185
try {
186
187             checkSimpleEntry(ctx, "simple/strFieldInjection", strFieldInjection, "strFieldInjection00");
188             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, ANNOTATION_INJECTION_FIELD);
189             logger.debug("{0} is working properly.", ANNOTATION_INJECTION_FIELD.toString());
190         } catch (Exception JavaDoc e) {
191             logger.debug("Error checking {0}: {1}", ANNOTATION_INJECTION_FIELD.toString(), e.getMessage());
192         }
193
194
195         //Injection in a method using annotation.
196
try {
197             checkSimpleEntry(ctx, "simple/strMethodInjection", strMethodInjection, "strMethodInjection00");
198             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, ANNOTATION_INJECTION_METHOD);
199             logger.debug("{0} is working properly.", ANNOTATION_INJECTION_METHOD.toString());
200         } catch (Exception JavaDoc e) {
201             logger.debug("Error checking {0}: {1}", ANNOTATION_INJECTION_METHOD.toString(), e.getMessage());
202         }
203
204         //Injection in a field using XML.
205
try {
206             checkSimpleEntry(ctx, "simple/strXMLFieldInjection", strXMLFieldInjection, "strXMLFieldInjection00");
207             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, XML_INJECTION_FIELD);
208             logger.debug("{0} is working properly.", XML_INJECTION_FIELD.toString());
209         } catch (Exception JavaDoc e) {
210             logger.debug("Error checking {0}: {1}", XML_INJECTION_FIELD.toString(), e.getMessage());
211         }
212
213         //Injection in a method using XML.
214
try {
215             checkSimpleEntry(ctx, "simple/strXMLMethodInjection", strXMLMethodInjection, "strXMLMethodInjection00");
216             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, XML_INJECTION_METHOD);
217             logger.debug("{0} is working properly.", XML_INJECTION_METHOD.toString());
218         } catch (Exception JavaDoc e) {
219             logger.debug("Error checking {0}: {1}", XML_INJECTION_METHOD.toString(), e.getMessage());
220         }
221
222         //Override an injection in a field with a XML.
223
try {
224             //Attention: the "simple/strOverrideFieldInjection" is the injection declared using the XML.
225
checkSimpleEntry(ctx, "simple/strOverrideFieldInjection", strOverrideFieldInjection, "strOverrideFieldInjection00");
226             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, OVERRIDE_INJECTION_FIELD);
227             logger.debug("{0} is working properly.", OVERRIDE_INJECTION_FIELD.toString());
228         } catch (Exception JavaDoc e) {
229             logger.debug("Error checking {0}: {1}", OVERRIDE_INJECTION_FIELD.toString(), e.getMessage());
230         }
231
232         //Override an injection in a method with a XML.
233
try {
234             //Attention: the "simple/strOverrideMethodInjection" is the injection declared using the XML.
235
checkSimpleEntry(ctx, "simple/strOverrideMethodInjection",
236                     strOverrideMethodInjection, "strOverrideMethodInjection00");
237             super.log(MDBSimpleEntryEnv.class, ON_MESSAGE, MDBSimpleEntryEnv.class, OVERRIDE_INJECTION_METHOD);
238             logger.debug("{0} is working properly.", OVERRIDE_INJECTION_METHOD.toString());
239         } catch (Exception JavaDoc e) {
240             logger.debug("Error checking {0}: {1}", OVERRIDE_INJECTION_METHOD.toString(), e.getMessage());
241         }
242
243     }
244
245 }
246
Popular Tags