KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > mdb > beanmanaged > access > MDBBeanManagedListenerMethodAccess


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: MDBBeanManagedListenerMethodAccess.java 715 2006-06-22 13:04:39Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.mdb.beanmanaged.access;
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.USER_TRANSACTION;
29 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.isEqual;
30 import static org.objectweb.easybeans.tests.common.resources.UserTransactionTester.checkInstance;
31
32 import javax.annotation.Resource;
33 import javax.ejb.ActivationConfigProperty JavaDoc;
34 import javax.ejb.MessageDriven JavaDoc;
35 import javax.ejb.TransactionManagement JavaDoc;
36 import javax.ejb.TransactionManagementType JavaDoc;
37 import javax.jms.JMSException JavaDoc;
38 import javax.jms.Message JavaDoc;
39 import javax.jms.MessageListener JavaDoc;
40 import javax.transaction.UserTransaction JavaDoc;
41
42 import org.objectweb.easybeans.log.JLog;
43 import org.objectweb.easybeans.log.JLogFactory;
44 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertOperation;
45 import org.objectweb.easybeans.tests.common.jms.JMSManager;
46 import org.objectweb.easybeans.tests.common.jms.MessageProperty;
47
48 /**
49  * This bean test operations allowed in message listener methods.
50  * @author Eduardo Studzinski Estima de Castro
51  * @author Gisele Pinheiro Souza
52  */

53 @MessageDriven JavaDoc(messageListenerInterface = MessageListener JavaDoc.class, activationConfig = {
54         @ActivationConfigProperty JavaDoc(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
55         @ActivationConfigProperty JavaDoc(propertyName = "destination", propertyValue = JMSManager.DEFAULT_QUEUE),
56         @ActivationConfigProperty JavaDoc(propertyName = "messageSelector", propertyValue =
57             "TYPE ='org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.access.MDBBeanManagedListenerMethodAccess'")})
58 @TransactionManagement JavaDoc(TransactionManagementType.BEAN)
59 public class MDBBeanManagedListenerMethodAccess extends BaseInsertOperation {
60
61     /**
62      * Log helper.
63      */

64     private JLog logger = JLogFactory.getLog(MDBBeanManagedListenerMethodAccess.class);
65
66     /**
67      * Message type.
68      */

69     public static final String JavaDoc MESSAGE_TYPE = "org.objectweb.easybeans.tests.common.ejbs."
70             + "mdb.containermanaged.access.MDBBeanManagedListenerMethodAccess";
71
72     /**
73      * ID.
74      */

75     private static final long serialVersionUID = 4108218174206348937L;
76
77     /**
78      * UserTransaction must not be injected.
79      */

80     @Resource
81     private UserTransaction JavaDoc utx;
82
83     /**
84      * Verifies MessageDrivenContext methods.
85      * @param message msg
86      * @throws JMSException
87      */

88     public void onMessage(final Message JavaDoc message) {
89         String JavaDoc op = null;
90
91         try {
92             op = message.getStringProperty(MessageProperty.OPERATION.toString());
93         } catch (JMSException JavaDoc e) {
94             logger.debug("Error getting operation type: {0}", e);
95         }
96
97         if (isEqual(USER_TRANSACTION, op)) {
98             if (utx != null) {
99
100                 try {
101                     checkInstance(utx);
102
103                     log(MDBBeanManagedListenerMethodAccess.class, ON_MESSAGE, MDBBeanManagedListenerMethodAccess.class,
104                             USER_TRANSACTION);
105                 } catch (Exception JavaDoc e) {
106                     e.printStackTrace();
107                 }
108             }
109         }
110
111     }
112
113 }
114
Popular Tags