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: MDBBeanManagedListenerMethodAccess.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.common.ejbs.mdb.beanmanaged.access;
025:
026: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.ON_MESSAGE;
027: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.USER_TRANSACTION;
028: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.isEqual;
029: import static org.ow2.easybeans.tests.common.resources.UserTransactionTester.checkInstance;
030:
031: import javax.annotation.Resource;
032: import javax.ejb.ActivationConfigProperty;
033: import javax.ejb.MessageDriven;
034: import javax.ejb.TransactionManagement;
035: import javax.ejb.TransactionManagementType;
036: import javax.jms.JMSException;
037: import javax.jms.Message;
038: import javax.jms.MessageListener;
039: import javax.transaction.UserTransaction;
040:
041: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertOperation;
042: import org.ow2.easybeans.tests.common.jms.JMSManager;
043: import org.ow2.easybeans.tests.common.jms.MessageProperty;
044: import org.ow2.util.log.Log;
045: import org.ow2.util.log.LogFactory;
046:
047: /**
048: * This bean test operations allowed in message listener methods.
049: * @author Eduardo Studzinski Estima de Castro
050: * @author Gisele Pinheiro Souza
051: */
052: @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.access.MDBBeanManagedListenerMethodAccess'")})
053: @TransactionManagement(TransactionManagementType.BEAN)
054: public class MDBBeanManagedListenerMethodAccess extends
055: BaseInsertOperation {
056:
057: /**
058: * Log helper.
059: */
060: private Log logger = LogFactory
061: .getLog(MDBBeanManagedListenerMethodAccess.class);
062:
063: /**
064: * Message type.
065: */
066: public static final String MESSAGE_TYPE = "org.ow2.easybeans.tests.common.ejbs."
067: + "mdb.containermanaged.access.MDBBeanManagedListenerMethodAccess";
068:
069: /**
070: * ID.
071: */
072: private static final long serialVersionUID = 4108218174206348937L;
073:
074: /**
075: * UserTransaction must not be injected.
076: */
077: @Resource
078: private UserTransaction utx;
079:
080: /**
081: * Verifies MessageDrivenContext methods.
082: * @param message msg
083: * @throws JMSException
084: */
085: public void onMessage(final Message message) {
086: String op = null;
087:
088: try {
089: op = message.getStringProperty(MessageProperty.OPERATION
090: .toString());
091: } catch (JMSException e) {
092: logger.debug("Error getting operation type: {0}", e);
093: }
094:
095: if (isEqual(USER_TRANSACTION, op)) {
096: if (utx != null) {
097:
098: try {
099: checkInstance(utx);
100:
101: log(MDBBeanManagedListenerMethodAccess.class,
102: ON_MESSAGE,
103: MDBBeanManagedListenerMethodAccess.class,
104: USER_TRANSACTION);
105: } catch (Exception e) {
106: e.printStackTrace();
107: }
108: }
109: }
110:
111: }
112:
113: }
|