KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > mdb > beanmanaged > context > MDBBeanManagedContext


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: MDBBeanManagedContext.java 962 2006-07-27 14:24:55Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.mdb.beanmanaged.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.ejb.TransactionManagement JavaDoc;
41 import javax.ejb.TransactionManagementType JavaDoc;
42 import javax.jms.JMSException JavaDoc;
43 import javax.jms.Message JavaDoc;
44 import javax.jms.MessageListener JavaDoc;
45
46 import org.objectweb.easybeans.log.JLog;
47 import org.objectweb.easybeans.log.JLogFactory;
48 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertOperation;
49 import org.objectweb.easybeans.tests.common.jms.JMSManager;
50 import org.objectweb.easybeans.tests.common.jms.MessageProperty;
51
52 /**
53  * This bean tests the MessageDrivenContext.
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",
61                 propertyValue =
62                     "TYPE = 'org.objectweb.easybeans.tests.common.ejbs.mdb.beanmanaged.context.MDBBeanManagedContext'")})
63 @TransactionManagement JavaDoc(TransactionManagementType.BEAN)
64 public class MDBBeanManagedContext extends BaseInsertOperation {
65
66     /**
67      * Message type.
68      */

69     public static final String JavaDoc MESSAGE_TYPE =
70         "org.objectweb.easybeans.tests.common.ejbs.mdb.beanmanaged.context.MDBBeanManagedContext";
71
72     /**
73      * Context.
74      */

75     @Resource
76     private MessageDrivenContext JavaDoc ctx;
77
78     /**
79      * Logger.
80      */

81     private JLog logger = JLogFactory.getLog(MDBBeanManagedContext.class);
82
83     /**
84      * Verifies the MessageDrivenContext methods.
85      * @param msg message
86      */

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

102         } else if (isEqual(GET_ROLLBACK_ONLY, op)) {
103             try{
104                 ctx.getRollbackOnly();
105             }catch(IllegalStateException JavaDoc e){
106                 log(MDBBeanManagedContext.class, ON_MESSAGE, MDBBeanManagedContext.class, GET_ROLLBACK_ONLY);
107             }catch (Exception JavaDoc e) {
108                logger.debug("Unexpected error.", e);
109             }
110
111         } else if (isEqual(SET_ROLLBACK_ONLY, op)) {
112             try{
113                 ctx.setRollbackOnly();
114             }catch(IllegalStateException JavaDoc e){
115                 log(MDBBeanManagedContext.class, ON_MESSAGE, MDBBeanManagedContext.class, SET_ROLLBACK_ONLY);
116             }
117
118         }else if (isEqual(TIMER, op)){
119             try {
120                 checkInstance(ctx.getTimerService());
121                 log(MDBBeanManagedContext.class, ON_MESSAGE, MDBBeanManagedContext.class, TIMER);
122             } catch (Exception JavaDoc e) {
123                 logger.debug("Unexpected error.", e);
124             }
125
126         }else if (isEqual(USER_TRANSACTION, op)) {
127             try {
128                 checkInstance(ctx.getTimerService());
129                 log(MDBBeanManagedContext.class, ON_MESSAGE, MDBBeanManagedContext.class, USER_TRANSACTION);
130             } catch (Exception JavaDoc e) {
131                 logger.debug("Unexpected error.", e);
132             }
133         }
134     }
135 }
136
Popular Tags