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