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: MDBSimpleEntryEnv.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.common.ejbs.mdb.containermanaged.simpleentry;
025:
026: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.ON_MESSAGE;
027: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.ANNOTATION_INJECTION_FIELD;
028: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.ANNOTATION_INJECTION_METHOD;
029: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.ANNOTATION_RESOURCES_DECLARATION;
030: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.ANNOTATION_RESOURCE_DECLARATION;
031: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.OVERRIDE_INJECTION_FIELD;
032: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.OVERRIDE_INJECTION_METHOD;
033: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.XML_INJECTION_FIELD;
034: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.XML_INJECTION_METHOD;
035: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.XML_RESOURCE_DECLARATION;
036: import static org.ow2.easybeans.tests.common.helper.ContextHelper.checkSimpleEntry;
037:
038: import javax.annotation.Resource;
039: import javax.annotation.Resources;
040: import javax.ejb.ActivationConfigProperty;
041: import javax.ejb.MessageDriven;
042: import javax.ejb.MessageDrivenContext;
043: import javax.jms.Message;
044: import javax.jms.MessageListener;
045:
046: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertOperation;
047: import org.ow2.easybeans.tests.common.jms.JMSManager;
048: import org.ow2.util.log.Log;
049: import org.ow2.util.log.LogFactory;
050:
051: /**
052: * This bean is used to test the simple entries in the environement. Operations:
053: * <li>Declaration using annotation.</li> <li>Declaration using XML.</li>
054: * <li>Injection in a field using annotation.</li> <li>Injection in a method
055: * using annotation.</li> <li>Injection in a field using XML.</li> <li>Injection
056: * in a method using XML.</li> <li>Override an injection in a field with a
057: * XML.</li><li>Override an injection in a method with a
058: * XML.</li>
059: * @author Eduardo Studzinski Estima de Castro
060: * @author Gisele Pinheiro Souza
061: */
062: @MessageDriven(messageListenerInterface=MessageListener.class,activationConfig={@ActivationConfigProperty(propertyName="destinationType",propertyValue="javax.jms.Queue"),@ActivationConfigProperty(propertyName="destination",propertyValue=JMSManager.DEFAULT_QUEUE),@ActivationConfigProperty(propertyName="messageSelector",propertyValue="TYPE = 'org.ow2.easybeans.tests." + "common.ejbs.mdb.containermanaged.simpleentry.MDBSimpleEntryEnv'")})
063: @Resources({@Resource(name="simple/strDeclaration00",type=java.lang.String.class)})
064: @Resource(name="simple/strDeclaration01",type=java.lang.String.class)
065: public class MDBSimpleEntryEnv extends BaseInsertOperation {
066:
067: /**
068: * Message type.
069: */
070: public static final String MESSAGE_TYPE = "org.ow2.easybeans.tests.common.ejbs.mdb."
071: + "containermanaged.simpleentry.MDBSimpleEntryEnv";
072:
073: /**
074: * Logger.
075: */
076: private static Log logger = LogFactory
077: .getLog(MDBSimpleEntryEnv.class);
078:
079: /**
080: * Field.
081: */
082: private String strMethodInjection;
083:
084: /**
085: * The value must be injected by the container.
086: */
087: @Resource(name="simple/strFieldInjection")
088: private String strFieldInjection;
089:
090: /**
091: * The value must be injected by the container using the XML value.
092: */
093: private String strXMLFieldInjection;
094:
095: /**
096: * The value must be injected by the container using the XML value.
097: */
098: private String strXMLMethodInjection;
099:
100: /**
101: * The value must be injected by the container using the XML value (Override
102: * test).
103: */
104: @Resource(name="simple/strOverrideField")
105: private String strOverrideFieldInjection;
106:
107: /**
108: * The value must be injected by the container using the XML value (Override
109: * test).
110: */
111: private String strOverrideMethodInjection;
112:
113: /**
114: * The value must be injected by the container.
115: * @param value information value
116: */
117: @SuppressWarnings("unused")
118: @Resource(name="simple/strMethodInjection")
119: private void setMethodInjection(final String value) {
120: strMethodInjection = value;
121: }
122:
123: /**
124: * The value must be injected by the container.
125: * @param value information value
126: */
127: @SuppressWarnings("unused")
128: private void setXMLMethodInjection(final String value) {
129: strXMLMethodInjection = value;
130: }
131:
132: /**
133: * The value must be injected by the container.
134: * @param value information value
135: */
136: @SuppressWarnings("unused")
137: @Resource(name="simple/strOverrideMethod")
138: private void setOverrideMethodInjection(final String value) {
139: strOverrideMethodInjection = value;
140: }
141:
142: /**
143: * Context.
144: */
145: @Resource
146: private MessageDrivenContext ctx;
147:
148: /**
149: * Tests declaration and injection.
150: * @param message msg
151: */
152: public void onMessage(final Message message) {
153:
154: //Declaration using annotation.
155: try {
156: checkSimpleEntry(ctx, "simple/strDeclaration00",
157: "strDeclaration00");
158: super .log(MDBSimpleEntryEnv.class, ON_MESSAGE,
159: MDBSimpleEntryEnv.class,
160: ANNOTATION_RESOURCES_DECLARATION);
161: logger.debug("{0} is working properly.",
162: ANNOTATION_RESOURCES_DECLARATION.toString());
163: } catch (Exception e) {
164: logger.debug("Error checking {0}: {1}",
165: ANNOTATION_RESOURCES_DECLARATION.toString(), e
166: .getMessage());
167: }
168: try {
169: checkSimpleEntry(ctx, "simple/strDeclaration01",
170: "strDeclaration01");
171: super .log(MDBSimpleEntryEnv.class, ON_MESSAGE,
172: MDBSimpleEntryEnv.class,
173: ANNOTATION_RESOURCE_DECLARATION);
174: logger.debug("{0} is working properly.",
175: ANNOTATION_RESOURCE_DECLARATION.toString());
176: } catch (Exception e) {
177: logger.debug("Error checking {0}: {1}",
178: ANNOTATION_RESOURCE_DECLARATION.toString(), e
179: .getMessage());
180: }
181:
182: //Declaration using XML.
183: try {
184: checkSimpleEntry(ctx, "simple/strXMLDeclaration",
185: "strXMLDeclaration00");
186: super .log(MDBSimpleEntryEnv.class, ON_MESSAGE,
187: MDBSimpleEntryEnv.class, XML_RESOURCE_DECLARATION);
188: logger.debug("{0} is working properly.",
189: XML_RESOURCE_DECLARATION.toString());
190: } catch (Exception e) {
191: logger
192: .debug("Error checking {0}: {1}",
193: XML_RESOURCE_DECLARATION.toString(), e
194: .getMessage());
195: }
196:
197: //Injection in a field using annotation.
198: try {
199:
200: checkSimpleEntry(ctx, "simple/strFieldInjection",
201: strFieldInjection, "strFieldInjection00");
202: super
203: .log(MDBSimpleEntryEnv.class, ON_MESSAGE,
204: MDBSimpleEntryEnv.class,
205: ANNOTATION_INJECTION_FIELD);
206: logger.debug("{0} is working properly.",
207: ANNOTATION_INJECTION_FIELD.toString());
208: } catch (Exception e) {
209: logger.debug("Error checking {0}: {1}",
210: ANNOTATION_INJECTION_FIELD.toString(), e
211: .getMessage());
212: }
213:
214: //Injection in a method using annotation.
215: try {
216: checkSimpleEntry(ctx, "simple/strMethodInjection",
217: strMethodInjection, "strMethodInjection00");
218: super .log(MDBSimpleEntryEnv.class, ON_MESSAGE,
219: MDBSimpleEntryEnv.class,
220: ANNOTATION_INJECTION_METHOD);
221: logger.debug("{0} is working properly.",
222: ANNOTATION_INJECTION_METHOD.toString());
223: } catch (Exception e) {
224: logger.debug("Error checking {0}: {1}",
225: ANNOTATION_INJECTION_METHOD.toString(), e
226: .getMessage());
227: }
228:
229: //Injection in a field using XML.
230: try {
231: checkSimpleEntry(ctx, "simple/strXMLFieldInjection",
232: strXMLFieldInjection, "strXMLFieldInjection00");
233: super .log(MDBSimpleEntryEnv.class, ON_MESSAGE,
234: MDBSimpleEntryEnv.class, XML_INJECTION_FIELD);
235: logger.debug("{0} is working properly.",
236: XML_INJECTION_FIELD.toString());
237: } catch (Exception e) {
238: logger.debug("Error checking {0}: {1}", XML_INJECTION_FIELD
239: .toString(), e.getMessage());
240: }
241:
242: //Injection in a method using XML.
243: try {
244: checkSimpleEntry(ctx, "simple/strXMLMethodInjection",
245: strXMLMethodInjection, "strXMLMethodInjection00");
246: super .log(MDBSimpleEntryEnv.class, ON_MESSAGE,
247: MDBSimpleEntryEnv.class, XML_INJECTION_METHOD);
248: logger.debug("{0} is working properly.",
249: XML_INJECTION_METHOD.toString());
250: } catch (Exception e) {
251: logger.debug("Error checking {0}: {1}",
252: XML_INJECTION_METHOD.toString(), e.getMessage());
253: }
254:
255: //Override an injection in a field with a XML.
256: try {
257: //Attention: the "simple/strOverrideFieldInjection" is the injection declared using the XML.
258: checkSimpleEntry(ctx, "simple/strOverrideFieldInjection",
259: strOverrideFieldInjection,
260: "strOverrideFieldInjection00");
261: super .log(MDBSimpleEntryEnv.class, ON_MESSAGE,
262: MDBSimpleEntryEnv.class, OVERRIDE_INJECTION_FIELD);
263: logger.debug("{0} is working properly.",
264: OVERRIDE_INJECTION_FIELD.toString());
265: } catch (Exception e) {
266: logger
267: .debug("Error checking {0}: {1}",
268: OVERRIDE_INJECTION_FIELD.toString(), e
269: .getMessage());
270: }
271:
272: //Override an injection in a method with a XML.
273: try {
274: //Attention: the "simple/strOverrideMethodInjection" is the injection declared using the XML.
275: checkSimpleEntry(ctx, "simple/strOverrideMethodInjection",
276: strOverrideMethodInjection,
277: "strOverrideMethodInjection00");
278: super .log(MDBSimpleEntryEnv.class, ON_MESSAGE,
279: MDBSimpleEntryEnv.class, OVERRIDE_INJECTION_METHOD);
280: logger.debug("{0} is working properly.",
281: OVERRIDE_INJECTION_METHOD.toString());
282: } catch (Exception e) {
283: logger.debug("Error checking {0}: {1}",
284: OVERRIDE_INJECTION_METHOD.toString(), e
285: .getMessage());
286: }
287:
288: }
289:
290: }
|