KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > mdb > containermanaged > interceptororder > MDBInvocationOrder00


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: MDBInvocationOrder00.java 547 2006-05-30 13:50:43Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.interceptororder;
26
27 import static org.objectweb.easybeans.tests.common.ejbs.base.ItfSimpleBean.EMBEDDED_INTERCEPTOR;
28 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.AROUND_INVOKE;
29 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.UNDEFINED;
30 import static org.objectweb.easybeans.tests.common.helper.InterceptorHelper.addValue;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.List JavaDoc;
34
35 import javax.ejb.ActivationConfigProperty JavaDoc;
36 import javax.ejb.MessageDriven JavaDoc;
37 import javax.interceptor.AroundInvoke;
38 import javax.interceptor.Interceptors;
39 import javax.interceptor.InvocationContext;
40 import javax.jms.Message JavaDoc;
41 import javax.jms.MessageListener JavaDoc;
42
43 import org.objectweb.easybeans.log.JLog;
44 import org.objectweb.easybeans.log.JLogFactory;
45 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertCallbackEvent;
46 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.CallbackChecker;
47 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder01Interceptor;
48 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder02Interceptor;
49 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder06Interceptor;
50 import org.objectweb.easybeans.tests.common.jms.JMSManager;
51
52 /**
53  * This bean is used to test embedded interceptors.
54  * @author Eduardo Studzinski Estima de Castro
55  * @author Gisele Pinheiro Souza
56  */

57 @MessageDriven JavaDoc(messageListenerInterface = MessageListener JavaDoc.class, activationConfig = {
58         @ActivationConfigProperty JavaDoc(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
59         @ActivationConfigProperty JavaDoc(propertyName = "destination", propertyValue = JMSManager.DEFAULT_QUEUE),
60         @ActivationConfigProperty JavaDoc(propertyName = "messageSelector", propertyValue =
61             "TYPE = 'org.objectweb.easybeans.tests.common.ejbs."
62                 + "mdb.containermanaged.interceptororder.MDBInvocationOrder00'")})
63 @Interceptors({PrintOrder01Interceptor.class})
64 public class MDBInvocationOrder00 extends BaseInsertCallbackEvent {
65
66     /**
67      * Logger.
68      */

69     private static JLog logger = JLogFactory.getLog(MDBInvocationOrder00.class);
70
71     /**
72      * Message type.
73      */

74     public static final String JavaDoc MESSAGE_TYPE = "org.objectweb.easybeans.tests.common."
75             + "ejbs.mdb.containermanaged.interceptororder.MDBInvocationOrder00";
76
77     /**
78      * Intercepts the method and add the ORDER value in the list that was get
79      * from InvocationContext. This method has private level access.
80      * @param invocationContext contains attributes of invocation, the first
81      * parameter of the intercepted method must be a list.
82      * @return method's invocation result
83      * @throws Exception if invocation fails
84      */

85     @SuppressWarnings JavaDoc("unused")
86     @AroundInvoke
87     private Object JavaDoc addOrder(final InvocationContext invocationContext) throws Exception JavaDoc {
88         logger.debug("Interceptor invoked.");
89         return addValue(invocationContext, EMBEDDED_INTERCEPTOR, MDBInvocationOrder00.class.toString());
90     }
91
92     /**
93      * Verifies the MessageDrivenContext methods.
94      * @param message msg
95      * @throws JMSException
96      */

97     @SuppressWarnings JavaDoc("unchecked")
98     @Interceptors({PrintOrder02Interceptor.class, PrintOrder06Interceptor.class})
99     public void onMessage(final Message JavaDoc message) {
100         CallbackChecker checker = new CallbackChecker();
101
102         List JavaDoc<String JavaDoc> lstResult = new ArrayList JavaDoc<String JavaDoc>();
103         lstResult.add(PrintOrder01Interceptor.class.toString());
104         lstResult.add(PrintOrder02Interceptor.class.toString());
105         lstResult.add(PrintOrder06Interceptor.class.toString());
106         lstResult.add(MDBInvocationOrder00.class.toString());
107
108         // Verifies the invoked interceptors.
109
try {
110             checker.check(MDBInvocationOrder00.class.toString(), UNDEFINED, lstResult);
111             super.log(MDBInvocationOrder00.class.toString(), AROUND_INVOKE, MDBInvocationOrder00.class.toString());
112         } catch (Exception JavaDoc e) {
113             logger.error("Error verifying interceptors order. Exception: ", e);
114         }
115
116     }
117 }
118
Popular Tags