KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > mdb > containermanaged > context > MDBContext


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: MDBContext.java 929 2006-07-25 13:19:59Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.context;
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.GET_CALLER_PRINCIPAL;
29 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.GET_ROLLBACK_ONLY;
30 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.SET_ROLLBACK_ONLY;
31 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.TIMER;
32 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.USER_TRANSACTION;
33 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.isEqual;
34 import static org.objectweb.easybeans.tests.common.resources.TimerServiceTester.checkInstance;
35
36 import javax.annotation.Resource;
37 import javax.ejb.ActivationConfigProperty JavaDoc;
38 import javax.ejb.MessageDriven JavaDoc;
39 import javax.ejb.MessageDrivenContext JavaDoc;
40 import javax.jms.JMSException JavaDoc;
41 import javax.jms.Message JavaDoc;
42 import javax.jms.MessageListener JavaDoc;
43
44 import org.objectweb.easybeans.log.JLog;
45 import org.objectweb.easybeans.log.JLogFactory;
46 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertOperation;
47 import org.objectweb.easybeans.tests.common.jms.JMSManager;
48 import org.objectweb.easybeans.tests.common.jms.MessageProperty;
49
50 /**
51  * This bean tests the MessageDrivenContext.
52  * @author Eduardo Studzinski Estima de Castro
53  * @author Gisele Pinheiro Souza
54  */

55 @MessageDriven JavaDoc(messageListenerInterface = MessageListener JavaDoc.class, activationConfig = {
56         @ActivationConfigProperty JavaDoc(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
57         @ActivationConfigProperty JavaDoc(propertyName = "destination", propertyValue = JMSManager.DEFAULT_QUEUE),
58         @ActivationConfigProperty JavaDoc(propertyName = "messageSelector", propertyValue = "TYPE = 'org.objectweb.easybeans.tests."
59             + "common.ejbs.mdb.containermanaged.context.MDBContext'")})
60 public class MDBContext extends BaseInsertOperation {
61
62     /**
63      * Message type.
64      */

65     public static final String JavaDoc MESSAGE_TYPE = "org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.context.MDBContext";
66
67     /**
68      * Context.
69      */

70     @Resource
71     private MessageDrivenContext JavaDoc ctx;
72
73     /**
74      * Logger.
75      */

76     private JLog logger = JLogFactory.getLog(MDBContext.class);
77
78     /**
79      * Verifies the MessageDrivenContext methods.
80      * @param msg message
81      */

82     public void onMessage(final Message JavaDoc msg) {
83         String JavaDoc op = null;
84
85         try {
86             op = msg.getStringProperty(MessageProperty.OPERATION.toString());
87         } catch (JMSException JavaDoc e) {
88             logger.debug("Error getting operation type: {0}", e);
89         }
90
91         if(ctx == null){
92             logger.debug("The SessionContext reference is null.");
93         }else if (isEqual(GET_CALLER_PRINCIPAL, op)) {
94
95             // TODO: test case
96

97         } else if (isEqual(GET_ROLLBACK_ONLY, op) | isEqual(SET_ROLLBACK_ONLY, op)) {
98             ctx.setRollbackOnly();
99             if (ctx.getRollbackOnly()) {
100                 log(MDBContext.class, ON_MESSAGE, MDBContext.class, GET_ROLLBACK_ONLY);
101             }
102
103         } else if (isEqual(TIMER, op)) {
104             try {
105                 checkInstance(ctx.getTimerService());
106                 log(MDBContext.class, ON_MESSAGE, MDBContext.class, TIMER);
107             } catch (Exception JavaDoc e) {
108                 e.printStackTrace();
109             }
110         } else if (isEqual(USER_TRANSACTION, op)) {
111             try {
112                 ctx.getUserTransaction();
113             } catch (IllegalStateException JavaDoc e) {
114                 log(MDBContext.class, ON_MESSAGE, MDBContext.class, USER_TRANSACTION);
115             }
116         }
117
118     }
119
120 }
121
Popular Tags