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: MDBInvocationOrder00.java 547 2006-05-30 13:50:43Z studzine $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.common.ejbs.mdb.containermanaged.interceptororder;
025:
026: import static org.ow2.easybeans.tests.common.ejbs.base.ItfSimpleBean.EMBEDDED_INTERCEPTOR;
027: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.AROUND_INVOKE;
028: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.UNDEFINED;
029: import static org.ow2.easybeans.tests.common.helper.InterceptorHelper.addValue;
030:
031: import java.util.ArrayList;
032: import java.util.List;
033:
034: import javax.ejb.ActivationConfigProperty;
035: import javax.ejb.MessageDriven;
036: import javax.interceptor.AroundInvoke;
037: import javax.interceptor.Interceptors;
038: import javax.interceptor.InvocationContext;
039: import javax.jms.Message;
040: import javax.jms.MessageListener;
041:
042: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertCallbackEvent;
043: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.CallbackChecker;
044: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder01Interceptor;
045: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder02Interceptor;
046: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder06Interceptor;
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 embedded interceptors.
053: * @author Eduardo Studzinski Estima de Castro
054: * @author Gisele Pinheiro Souza
055: */
056: @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.interceptororder.MDBInvocationOrder00'")})
057: @Interceptors({PrintOrder01Interceptor.class})
058: public class MDBInvocationOrder00 extends BaseInsertCallbackEvent {
059:
060: /**
061: * Logger.
062: */
063: private static Log logger = LogFactory
064: .getLog(MDBInvocationOrder00.class);
065:
066: /**
067: * Message type.
068: */
069: public static final String MESSAGE_TYPE = "org.ow2.easybeans.tests.common."
070: + "ejbs.mdb.containermanaged.interceptororder.MDBInvocationOrder00";
071:
072: /**
073: * Intercepts the method and add the ORDER value in the list that was get
074: * from InvocationContext. This method has private level access.
075: * @param invocationContext contains attributes of invocation, the first
076: * parameter of the intercepted method must be a list.
077: * @return method's invocation result
078: * @throws Exception if invocation fails
079: */
080: @SuppressWarnings("unused")
081: @AroundInvoke
082: private Object addOrder(final InvocationContext invocationContext)
083: throws Exception {
084: logger.debug("Interceptor invoked.");
085: return addValue(invocationContext, EMBEDDED_INTERCEPTOR,
086: MDBInvocationOrder00.class.toString());
087: }
088:
089: /**
090: * Verifies the MessageDrivenContext methods.
091: * @param message msg
092: * @throws JMSException
093: */
094: @SuppressWarnings("unchecked")
095: @Interceptors({PrintOrder02Interceptor.class,PrintOrder06Interceptor.class})
096: public void onMessage(final Message message) {
097: CallbackChecker checker = new CallbackChecker();
098:
099: List<String> lstResult = new ArrayList<String>();
100: lstResult.add(PrintOrder01Interceptor.class.toString());
101: lstResult.add(PrintOrder02Interceptor.class.toString());
102: lstResult.add(PrintOrder06Interceptor.class.toString());
103: lstResult.add(MDBInvocationOrder00.class.toString());
104:
105: // Verifies the invoked interceptors.
106: try {
107: checker.check(MDBInvocationOrder00.class.toString(),
108: UNDEFINED, lstResult);
109: super .log(MDBInvocationOrder00.class.toString(),
110: AROUND_INVOKE, MDBInvocationOrder00.class
111: .toString());
112: } catch (Exception e) {
113: logger.error(
114: "Error verifying interceptors order. Exception: ",
115: e);
116: }
117:
118: }
119: }
|