001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.messagedriven.mbeans;
023:
024: import java.util.ArrayList;
025: import java.util.Enumeration;
026: import java.util.Properties;
027:
028: import javax.jms.Message;
029: import javax.naming.InitialContext;
030: import javax.transaction.Transaction;
031: import javax.transaction.TransactionManager;
032:
033: import org.jboss.system.ServiceMBeanSupport;
034:
035: /**
036: * Management of the test message driven bean
037: *
038: * @author <a href="mailto:adrian@jboss.com>Adrian Brock</a>
039: * @version <tt>$Revision: 1.4</tt>
040: */
041: public class TestMessageDrivenManagement extends ServiceMBeanSupport
042: implements TestMessageDrivenManagementMBean {
043: private static final Properties defaultProps = new Properties();
044:
045: private TransactionManager tm;
046:
047: static {
048: defaultProps.put("destination", "NotSpecified");
049: defaultProps.put("destinationType", "NotSpecified");
050: defaultProps.put("transactionType", "Container");
051: defaultProps.put("transactionAttribute", "Required");
052: defaultProps.put("rollback", "None");
053: defaultProps.put("DLQMaxResent", "5");
054: defaultProps.put("DeliveryActive", "true");
055: defaultProps.put("durability", "NonDurable");
056: defaultProps.put("subscriptionName", "");
057: defaultProps.put("user", "guest");
058: defaultProps.put("password", "guest");
059: }
060:
061: protected ArrayList messages = new ArrayList();
062:
063: public TestMessageDrivenManagement() throws Exception {
064: tm = (TransactionManager) new InitialContext()
065: .lookup("java:/TransactionManager");
066: }
067:
068: public void initProperties(Properties props) {
069: setProperties(defaultProps);
070: setProperties(props);
071: }
072:
073: public void addMessage(Message message) {
074: synchronized (messages) {
075: messages.add(message);
076: }
077: }
078:
079: public ArrayList getMessages() {
080: synchronized (messages) {
081: ArrayList result = new ArrayList(messages);
082: messages.clear();
083: return result;
084: }
085: }
086:
087: public Transaction getTransaction() {
088: Transaction tx = null;
089: try {
090: tx = tm.getTransaction();
091: } catch (Throwable ignored) {
092: }
093: return tx;
094: }
095:
096: protected void setProperties(Properties props) {
097: for (Enumeration e = props.keys(); e.hasMoreElements();) {
098: String key = (String) e.nextElement();
099: System.setProperty("test.messagedriven." + key, props
100: .getProperty(key));
101: }
102: }
103: }
|