[jboss-cvs] JBoss Messaging SVN: r5759 - in trunk: src/config and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 29 11:47:21 EST 2009


Author: jesper.pedersen
Date: 2009-01-29 11:47:21 -0500 (Thu, 29 Jan 2009)
New Revision: 5759

Added:
   trunk/src/config/ra.xml
   trunk/src/main/org/jboss/messaging/ra/
   trunk/src/main/org/jboss/messaging/ra/JBMBytesMessage.java
   trunk/src/main/org/jboss/messaging/ra/JBMConnectionFactory.java
   trunk/src/main/org/jboss/messaging/ra/JBMConnectionFactoryImpl.java
   trunk/src/main/org/jboss/messaging/ra/JBMConnectionManager.java
   trunk/src/main/org/jboss/messaging/ra/JBMConnectionMetaData.java
   trunk/src/main/org/jboss/messaging/ra/JBMConnectionRequestInfo.java
   trunk/src/main/org/jboss/messaging/ra/JBMCredential.java
   trunk/src/main/org/jboss/messaging/ra/JBMLocalTransaction.java
   trunk/src/main/org/jboss/messaging/ra/JBMMCFProperties.java
   trunk/src/main/org/jboss/messaging/ra/JBMManagedConnection.java
   trunk/src/main/org/jboss/messaging/ra/JBMManagedConnectionFactory.java
   trunk/src/main/org/jboss/messaging/ra/JBMMapMessage.java
   trunk/src/main/org/jboss/messaging/ra/JBMMessage.java
   trunk/src/main/org/jboss/messaging/ra/JBMMessageConsumer.java
   trunk/src/main/org/jboss/messaging/ra/JBMMessageListener.java
   trunk/src/main/org/jboss/messaging/ra/JBMMessageProducer.java
   trunk/src/main/org/jboss/messaging/ra/JBMMetaData.java
   trunk/src/main/org/jboss/messaging/ra/JBMObjectMessage.java
   trunk/src/main/org/jboss/messaging/ra/JBMQueueReceiver.java
   trunk/src/main/org/jboss/messaging/ra/JBMQueueSender.java
   trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java
   trunk/src/main/org/jboss/messaging/ra/JBMSession.java
   trunk/src/main/org/jboss/messaging/ra/JBMSessionFactory.java
   trunk/src/main/org/jboss/messaging/ra/JBMSessionFactoryImpl.java
   trunk/src/main/org/jboss/messaging/ra/JBMStreamMessage.java
   trunk/src/main/org/jboss/messaging/ra/JBMTextMessage.java
   trunk/src/main/org/jboss/messaging/ra/JBMTopicPublisher.java
   trunk/src/main/org/jboss/messaging/ra/JBMTopicSubscriber.java
   trunk/src/main/org/jboss/messaging/ra/JBMXAResource.java
   trunk/src/main/org/jboss/messaging/ra/Util.java
   trunk/src/main/org/jboss/messaging/ra/package.html
Modified:
   trunk/build-messaging.xml
   trunk/build.xml
Log:
[JBMESSAGING-1367] Create JCA resource adapter for JBM 2.0

Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml	2009-01-29 14:23:24 UTC (rev 5758)
+++ trunk/build-messaging.xml	2009-01-29 16:47:21 UTC (rev 5759)
@@ -66,6 +66,8 @@
    <property name="bootstrap.jar.name" value="jbm-bootstrap.jar"/>
    <property name="logging.jar.name" value="jbm-logging.jar"/>
    <property name="core.client.jar.name" value="jbm-core-client.jar"/>
+   <property name="ra.jar.name" value="jbm-ra.jar"/>
+   <property name="ra.rar.name" value="jbm-ra.rar"/>
 
    <!--source and build dirs-->
    <property name="build.dir" value="build"/>
@@ -80,6 +82,7 @@
    <property name="build.security.classes.dir" value="${build.dir}/classes/security"/>
    <property name="build.bootstrap.classes.dir" value="${build.dir}/classes/bootstrap"/>
    <property name="build.logging.classes.dir" value="${build.dir}/classes/logging"/>
+   <property name="build.ra.classes.dir" value="${build.dir}/classes/ra"/>
    <property name="build.jars.dir" value="${build.dir}/jars"/>
    <property name="build.src.dir" value="${build.dir}/src"/>
    <property name="src.dir" value="src"/>
@@ -397,6 +400,7 @@
       <mkdir dir="${build.security.classes.dir}"/>
       <mkdir dir="${build.bootstrap.classes.dir}"/>
       <mkdir dir="${build.logging.classes.dir}"/>
+      <mkdir dir="${build.ra.classes.dir}"/>
       <mkdir dir="${build.jars.dir}"/>
       <mkdir dir="${build.src.dir}"/>
    </target>
@@ -539,6 +543,27 @@
       </javac>
    </target>
 
+   <target name="compile-ra" depends="init">
+      <javac destdir="${build.ra.classes.dir}"
+             target="${javac.target}"
+             source="${javac.source}"
+             optimize="${javac.optimize}"
+             debug="${javac.debug}"
+             depend="${javac.depend}"
+             verbose="${javac.verbose}"
+             deprecation="${javac.deprecation}"
+             includeAntRuntime="${javac.include.ant.runtime}"
+             includeJavaRuntime="${javac.include.java.runtime}"
+             failonerror="${javac.fail.onerror}">
+         <src>
+            <pathelement path="${build.src.dir}"/>
+            <pathelement path="${src.main.dir}"/>
+         </src>
+         <include name="**/messaging/ra/**/*.java"/>
+         <classpath refid="jms.compilation.classpath"/>
+      </javac>
+   </target>
+
    <target name="build-native">
       <exec dir="native" executable="make">
          <arg line="clean"/>
@@ -653,9 +678,22 @@
 
    </target>
 
+   <target name="jar-ra" depends="compile-ra, jar-client, jar-jms">
+      <jar jarfile="${build.jars.dir}/${ra.jar.name}">
+         <fileset dir="${build.ra.classes.dir}">
+           <include name="org/jboss/messaging/ra/**/*.class"/>
+         </fileset>
+      </jar>
+      <jar jarfile="${build.jars.dir}/${ra.rar.name}">
+         <metainf dir="${src.config.dir}" includes="ra.xml"/>
+         <fileset file="${build.jars.dir}/${ra.jar.name}"/>
+         <fileset file="${build.jars.dir}/${core.client.jar.name}"/>
+         <fileset file="${build.jars.dir}/${jms.jar.name}"/>
+      </jar>
+   </target>
+
    <target name="jar"
-           depends="jar-core, jar-client, jar-jms, jar-transports, jar-security, jar-bootstrap, jar-logging">
-
+           depends="jar-core, jar-client, jar-jms, jar-transports, jar-security, jar-bootstrap, jar-logging, jar-ra">
    </target>
 
 

Modified: trunk/build.xml
===================================================================
--- trunk/build.xml	2009-01-29 14:23:24 UTC (rev 5758)
+++ trunk/build.xml	2009-01-29 16:47:21 UTC (rev 5759)
@@ -98,6 +98,10 @@
       <ant antfile="build-messaging.xml" target="compile-logging"/>
    </target>
 
+   <target name="compile-ra" depends="createthirdparty">
+      <ant antfile="build-messaging.xml" target="compile-ra"/>
+   </target>
+
    <target name="build-native" depends="createthirdparty">
       <ant antfile="build-messaging.xml" target="build-native"/>
    </target>
@@ -145,6 +149,10 @@
    <target name="jar-client" depends="createthirdparty">
       <ant antfile="build-messaging.xml" target="jar-client"/>
    </target>
+
+   <target name="jar-ra" depends="createthirdparty">
+      <ant antfile="build-messaging.xml" target="jar-ra"/>
+   </target>
    <!-- ======================================================================================== -->
    <!-- Distro Tasks                                                                           -->
    <!-- ======================================================================================== -->

Added: trunk/src/config/ra.xml
===================================================================
--- trunk/src/config/ra.xml	                        (rev 0)
+++ trunk/src/config/ra.xml	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- $Id: ra.xml 76819 2008-08-08 11:04:20Z jesper.pedersen $ -->
+
+<connector xmlns="http://java.sun.com/xml/ns/j2ee"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+           http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
+           version="1.5">
+
+   <description>JBoss Messaging 2.0 Resource Adapter</description>
+   <display-name>JBoss Messaging 2.0 Resource Adapter</display-name>
+
+   <vendor-name>Red Hat Middleware LLC</vendor-name>
+   <eis-type>JMS 1.1 Server</eis-type>
+   <resourceadapter-version>1.0</resourceadapter-version>
+
+   <license>
+      <description>
+ JBoss, Home of Professional Open Source.
+ Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ as indicated by the @author tags. See the copyright.txt file in the
+ distribution for a full listing of individual contributors.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+      </description>
+      <license-required>true</license-required>
+   </license>
+
+   <resourceadapter>
+      <resourceadapter-class>org.jboss.messaging.ra.JBMResourceAdapter</resourceadapter-class>
+
+      <outbound-resourceadapter>
+         <connection-definition>
+            <managedconnectionfactory-class>org.jboss.messaging.ra.JBMManagedConnectionFactory</managedconnectionfactory-class>
+
+            <config-property>
+               <description>The discovery group name</description>
+               <config-property-name>DiscoveryGroupName</config-property-name>
+               <config-property-type>java.lang.String</config-property-type>
+               <config-property-value>default</config-property-value>
+            </config-property>
+            <config-property>
+               <description>The discovery group port</description>
+               <config-property-name>DiscoveryGroupPort</config-property-name>
+               <config-property-type>java.lang.Integer</config-property-type>
+               <config-property-value>0</config-property-value>
+            </config-property>
+            <config-property>
+               <description>Use XA methods to obtain connections</description>
+               <config-property-name>UseXA</config-property-name>
+               <config-property-type>java.lang.Boolean</config-property-type>
+               <config-property-value>true</config-property-value>
+            </config-property>
+            <config-property>
+               <description>The user name used to login to the JMS server</description>
+               <config-property-name>UserName</config-property-name>
+               <config-property-type>java.lang.String</config-property-type>
+               <config-property-value></config-property-value>
+            </config-property>
+            <config-property>
+               <description>The password used to login to the JMS server</description>
+               <config-property-name>Password</config-property-name>
+               <config-property-type>java.lang.String</config-property-type>
+               <config-property-value></config-property-value>
+            </config-property>
+            <config-property>
+               <description>The client id</description>
+               <config-property-name>ClientID</config-property-name>
+               <config-property-type>java.lang.String</config-property-type>
+               <config-property-value></config-property-value>
+            </config-property>
+            <config-property>
+               <description>The default session type</description>
+               <config-property-name>SessionDefaultType</config-property-name>
+               <config-property-type>java.lang.String</config-property-type>
+               <config-property-value>javax.jms.Queue</config-property-value>
+            </config-property>
+            <config-property>
+               <description>Try to obtain a lock within specified number of seconds; <= 0 disable this functionality</description>
+               <config-property-name>UseTryLock</config-property-name>
+               <config-property-type>java.lang.Integer</config-property-type>
+               <config-property-value>0</config-property-value>
+            </config-property>
+
+            <connectionfactory-interface>org.jboss.messaging.ra.JBMConnectionFactory</connectionfactory-interface>
+            <connectionfactory-impl-class>org.jboss.messaging.ra.JBMConnectionFactoryImpl</connectionfactory-impl-class>
+            <connection-interface>javax.jms.Session</connection-interface>
+            <connection-impl-class>org.jboss.messaging.ra.JBMSession</connection-impl-class>
+         </connection-definition>
+         <transaction-support>XATransaction</transaction-support>
+         <authentication-mechanism>
+            <authentication-mechanism-type>BasicPassword</authentication-mechanism-type>
+            <credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
+         </authentication-mechanism>
+         <reauthentication-support>false</reauthentication-support>
+      </outbound-resourceadapter>
+
+   </resourceadapter>
+</connector>

Added: trunk/src/main/org/jboss/messaging/ra/JBMBytesMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMBytesMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMBytesMessage.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,411 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A wrapper for a message
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMBytesMessage extends JBMMessage implements BytesMessage
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMBytesMessage.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**
+    * Create a new wrapper
+    * @param message the message
+    * @param session the session
+    */
+   public JBMBytesMessage(BytesMessage message, JBMSession session)
+   {
+      super(message, session);
+
+      if (trace)
+         log.trace("constructor(" + message + ", " + session + ")");
+   }
+   
+   /**
+    * Get body length
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public long getBodyLength() throws JMSException
+   {
+      if (trace)
+         log.trace("getBodyLength()");
+
+      return ((BytesMessage) message).getBodyLength();
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean readBoolean() throws JMSException
+   {
+      if (trace)
+         log.trace("readBoolean()");
+
+      return ((BytesMessage) message).readBoolean();
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public byte readByte() throws JMSException
+   {
+      if (trace)
+         log.trace("readByte()");
+
+      return ((BytesMessage) message).readByte();
+   }
+   
+   /**
+    * Read
+    * @param value The value
+    * @param length The length
+    * @return The result
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int readBytes(byte[] value, int length) throws JMSException
+   {
+      if (trace)
+         log.trace("readBytes(" + value + ", " + length + ")");
+
+      return ((BytesMessage) message).readBytes(value, length);
+   }
+   
+   /**
+    * Read
+    * @param value The value
+    * @return The result
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int readBytes(byte[] value) throws JMSException
+   {
+      if (trace)
+         log.trace("readBytes(" + value + ")");
+
+      return ((BytesMessage) message).readBytes(value);
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public char readChar() throws JMSException
+   {
+      if (trace)
+         log.trace("readChar()");
+
+      return ((BytesMessage) message).readChar();
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public double readDouble() throws JMSException
+   {
+      if (trace)
+         log.trace("readDouble()");
+
+      return ((BytesMessage) message).readDouble();
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public float readFloat() throws JMSException
+   {
+      if (trace)
+         log.trace("readFloat()");
+
+      return ((BytesMessage) message).readFloat();
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int readInt() throws JMSException
+   {
+      if (trace)
+         log.trace("readInt()");
+
+      return ((BytesMessage) message).readInt();
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public long readLong() throws JMSException
+   {
+      if (trace)
+         log.trace("readLong()");
+
+      return ((BytesMessage) message).readLong();
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public short readShort() throws JMSException
+   {
+      if (trace)
+         log.trace("readShort()");
+
+      return ((BytesMessage) message).readShort();
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int readUnsignedByte() throws JMSException
+   {
+      if (trace)
+         log.trace("readUnsignedByte()");
+
+      return ((BytesMessage) message).readUnsignedByte();
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int readUnsignedShort() throws JMSException
+   {
+      if (trace)
+         log.trace("readUnsignedShort()");
+
+      return ((BytesMessage) message).readUnsignedShort();
+   }
+   
+   /**
+    * Read
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public String readUTF() throws JMSException
+   {
+      if (trace)
+         log.trace("readUTF()");
+
+      return ((BytesMessage) message).readUTF();
+   }
+   
+   /**
+    * Reset
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void reset() throws JMSException
+   {
+      if (trace)
+         log.trace("reset()");
+
+      ((BytesMessage) message).reset();
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeBoolean(boolean value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeBoolean(" + value + ")");
+
+      ((BytesMessage) message).writeBoolean(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeByte(byte value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeByte(" + value + ")");
+
+      ((BytesMessage) message).writeByte(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @param offset The offset
+    * @param length The length
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeBytes(byte[] value, int offset, int length) throws JMSException
+   {
+      if (trace)
+         log.trace("writeBytes(" + value + ", " + offset + ", " + length + ")");
+
+      ((BytesMessage) message).writeBytes(value, offset, length);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeBytes(byte[] value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeBytes(" + value + ")");
+
+      ((BytesMessage) message).writeBytes(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeChar(char value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeChar(" + value + ")");
+
+      ((BytesMessage) message).writeChar(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeDouble(double value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeDouble(" + value + ")");
+
+      ((BytesMessage) message).writeDouble(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeFloat(float value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeFloat(" + value + ")");
+
+      ((BytesMessage) message).writeFloat(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeInt(int value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeInt(" + value + ")");
+
+      ((BytesMessage) message).writeInt(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeLong(long value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeLong(" + value + ")");
+
+      ((BytesMessage) message).writeLong(value);
+   }
+
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeObject(Object value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeObject(" + value + ")");
+
+      ((BytesMessage) message).writeObject(value);
+   }
+
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeShort(short value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeShort(" + value + ")");
+
+      ((BytesMessage) message).writeShort(value);
+   }
+
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeUTF(String value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeUTF(" + value + ")");
+
+      ((BytesMessage) message).writeUTF(value);
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMConnectionFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMConnectionFactory.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMConnectionFactory.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.io.Serializable;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.XAConnectionFactory;
+import javax.jms.XAQueueConnectionFactory;
+import javax.jms.XATopicConnectionFactory;
+
+/**
+ * An aggregate interface for the JMS connection factories
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.com">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public interface JBMConnectionFactory extends ConnectionFactory, 
+                                              TopicConnectionFactory,
+                                              QueueConnectionFactory, 
+                                              XAConnectionFactory,
+                                              XAQueueConnectionFactory,
+                                              XATopicConnectionFactory,
+                                              Serializable
+{
+   /** Connection factory capable of handling connections */
+   public static final int CONNECTION = 0;
+
+   /** Connection factory capable of handling queues */
+   public static final int QUEUE_CONNECTION = 1;
+
+   /** Connection factory capable of handling topics */
+   public static final int TOPIC_CONNECTION = 2;
+
+   /** Connection factory capable of handling XA connections */
+   public static final int XA_CONNECTION = 3;
+
+   /** Connection factory capable of handling XA queues */
+   public static final int XA_QUEUE_CONNECTION = 4;
+
+   /** Connection factory capable of handling XA topics */
+   public static final int XA_TOPIC_CONNECTION = 5;
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMConnectionFactoryImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMConnectionFactoryImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMConnectionFactoryImpl.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,351 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.QueueConnection;
+import javax.jms.TopicConnection;
+import javax.jms.XAConnection;
+import javax.jms.XAQueueConnection;
+import javax.jms.XATopicConnection;
+import javax.naming.Reference;
+import javax.resource.Referenceable;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ManagedConnectionFactory;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * The connection factory
+ * 
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision:  $
+ */
+public class JBMConnectionFactoryImpl implements JBMConnectionFactory, Referenceable
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMConnectionFactoryImpl.class);
+
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The managed connection factory */
+   private JBMManagedConnectionFactory mcf;
+
+   /** The connection manager */
+   private ConnectionManager cm;
+
+   /** Naming reference */
+   private Reference reference;
+
+   /**
+    * Constructor
+    * @param mcf The managed connection factory
+    * @param cm The connection manager
+    */
+   public JBMConnectionFactoryImpl(JBMManagedConnectionFactory mcf, ConnectionManager cm) 
+   {
+      if (trace)
+         log.trace("constructor(" + mcf + ", " + cm + ")");
+
+      this.mcf = mcf;
+
+      if (cm == null)
+      {
+         // This is standalone usage, no appserver
+         this.cm = new JBMConnectionManager();
+         if (trace)
+            log.trace("Created new ConnectionManager=" + cm);
+      }
+      else
+         this.cm = cm;
+
+      if (trace)
+         log.trace("Using ManagedConnectionFactory=" + mcf + ", ConnectionManager=" + cm);
+   }
+
+   /**
+    * Set the reference
+    * @param reference The reference
+    */
+   public void setReference(Reference reference) 
+   {
+      if (trace)
+         log.trace("setReference(" + reference + ")");
+
+      this.reference = reference;
+   }
+    
+   /**
+    * Get the reference
+    * @return The reference
+    */
+   public Reference getReference() 
+   {
+      if (trace)
+         log.trace("getReference()");
+
+      return reference;
+   }
+   
+   /**
+    * Create a queue connection
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public QueueConnection createQueueConnection() throws JMSException 
+   {
+      if (trace)
+         log.trace("createQueueConnection()");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, QUEUE_CONNECTION);
+
+      if (trace)
+         log.trace("Created queue connection: " + s);
+      
+      return s;
+   }
+   
+   /**
+    * Create a queue connection
+    * @param userName The user name
+    * @param password The password
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public QueueConnection createQueueConnection(String userName, String password) throws JMSException 
+   {
+      if (trace)
+         log.trace("createQueueConnection(" + userName + ", ****)");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, QUEUE_CONNECTION);
+      s.setUserName(userName);
+      s.setPassword(password);
+
+      if (trace)
+         log.trace("Created queue connection: " + s);
+      
+      return s;
+   } 
+
+   /**
+    * Create a topic connection
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public TopicConnection createTopicConnection() throws JMSException 
+   {
+      if (trace)
+         log.trace("createTopicConnection()");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, TOPIC_CONNECTION);
+
+      if (trace)
+         log.trace("Created topic connection: " + s);
+
+      return s;
+   }
+   
+   /**
+    * Create a topic connection
+    * @param userName The user name
+    * @param password The password
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public TopicConnection createTopicConnection(String userName, String password) throws JMSException 
+   {
+      if (trace)
+         log.trace("createTopicConnection(" + userName + ", ****)");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, TOPIC_CONNECTION);
+      s.setUserName(userName);
+      s.setPassword(password);
+      
+      if (trace)
+         log.trace("Created topic connection: " + s);
+
+      return s;
+   }
+
+   /**
+    * Create a connection
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public Connection createConnection() throws JMSException 
+   {
+      if (trace)
+         log.trace("createConnection()");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, CONNECTION);
+
+      if (trace)
+         log.trace("Created connection: " + s);
+
+      return s;
+   }
+
+   /**
+    * Create a connection
+    * @param userName The user name
+    * @param password The password
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public Connection createConnection(String userName, String password) throws JMSException
+   {
+      if (trace)
+         log.trace("createConnection(" + userName + ", ****)");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, CONNECTION);
+      s.setUserName(userName);
+      s.setPassword(password);
+      
+      if (trace)
+         log.trace("Created connection: " + s);
+
+      return s;
+   }  
+
+   /**
+    * Create a XA queue connection
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public XAQueueConnection createXAQueueConnection() throws JMSException 
+   {
+      if (trace)
+         log.trace("createXAQueueConnection()");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, XA_QUEUE_CONNECTION);
+
+      if (trace)
+         log.trace("Created queue connection: " + s);
+      
+      return s;
+   }
+   
+   /**
+    * Create a XA  queue connection
+    * @param userName The user name
+    * @param password The password
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public XAQueueConnection createXAQueueConnection(String userName, String password) throws JMSException 
+   {
+      if (trace)
+         log.trace("createXAQueueConnection(" + userName + ", ****)");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, XA_QUEUE_CONNECTION);
+      s.setUserName(userName);
+      s.setPassword(password);
+
+      if (trace)
+         log.trace("Created queue connection: " + s);
+      
+      return s;
+   } 
+
+   /**
+    * Create a XA topic connection
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public XATopicConnection createXATopicConnection() throws JMSException 
+   {
+      if (trace)
+         log.trace("createXATopicConnection()");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, XA_TOPIC_CONNECTION);
+
+      if (trace)
+         log.trace("Created topic connection: " + s);
+
+      return s;
+   }
+   
+   /**
+    * Create a XA topic connection
+    * @param userName The user name
+    * @param password The password
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public XATopicConnection createXATopicConnection(String userName, String password) throws JMSException 
+   {
+      if (trace)
+         log.trace("createXATopicConnection(" + userName + ", ****)");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, XA_TOPIC_CONNECTION);
+      s.setUserName(userName);
+      s.setPassword(password);
+      
+      if (trace)
+         log.trace("Created topic connection: " + s);
+
+      return s;
+   }
+
+   /**
+    * Create a XA connection
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public XAConnection createXAConnection() throws JMSException 
+   {
+      if (trace)
+         log.trace("createXAConnection()");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, XA_CONNECTION);
+
+      if (trace)
+         log.trace("Created connection: " + s);
+
+      return s;
+   }
+
+   /**
+    * Create a XA connection
+    * @param userName The user name
+    * @param password The password
+    * @return The connection
+    * @exception JMSException Thrown if the operation fails
+    */
+   public XAConnection createXAConnection(String userName, String password) throws JMSException
+   {
+      if (trace)
+         log.trace("createXAConnection(" + userName + ", ****)");
+
+      JBMSessionFactoryImpl s = new JBMSessionFactoryImpl(mcf, cm, XA_CONNECTION);
+      s.setUserName(userName);
+      s.setPassword(password);
+      
+      if (trace)
+         log.trace("Created connection: " + s);
+
+      return s;
+   }  
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMConnectionManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMConnectionManager.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMConnectionManager.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnection;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * The connection manager used in non-managed environments.
+ * 
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMConnectionManager implements ConnectionManager
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMConnectionManager.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+   
+   /**
+    * Constructor
+    */
+   public JBMConnectionManager()
+   {
+      if (trace)
+         log.trace("constructor()");
+   }
+
+   /**
+    * Allocates a connection
+    * @param mcf The managed connection factory
+    * @param cxRequestInfo The connection request information 
+    * @return The connection
+    * @exception ResourceException Thrown if there is a problem obtaining the connection
+    */
+   public Object allocateConnection(ManagedConnectionFactory mcf,
+                                    ConnectionRequestInfo cxRequestInfo) 
+      throws ResourceException
+   {
+      if (trace)
+         log.trace("allocateConnection(" + mcf + ", " + cxRequestInfo + ")");
+      
+      ManagedConnection mc = mcf.createManagedConnection(null, cxRequestInfo);
+      Object c = mc.getConnection(null, cxRequestInfo);
+
+      if (trace)
+         log.trace("Allocated connection: " + c + ", with managed connection: " + mc);
+      
+      return c;
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMConnectionMetaData.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMConnectionMetaData.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMConnectionMetaData.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.jms.ConnectionMetaData;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * This class implements javax.jms.ConnectionMetaData
+ * 
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMConnectionMetaData implements ConnectionMetaData
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMConnectionMetaData.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**
+    * Constructor
+    */
+   public JBMConnectionMetaData()
+   {
+      if (trace)
+         log.trace("constructor()");
+   }
+
+   /**
+    * Get the JMS version
+    * @return The version
+    */
+   public String getJMSVersion()
+   {
+      if (trace)
+         log.trace("getJMSVersion()");
+
+      return "1.1";
+   }
+   
+   /**
+    * Get the JMS major version
+    * @return The major version
+    */
+   public int getJMSMajorVersion()
+   {
+      if (trace)
+         log.trace("getJMSMajorVersion()");
+
+      return 1;
+   }
+   
+   /**
+    * Get the JMS minor version
+    * @return The minor version
+    */
+   public int getJMSMinorVersion()
+   {
+      if (trace)
+         log.trace("getJMSMinorVersion()");
+
+      return 1;
+   }
+
+   /**
+    * Get the JMS provider name
+    * @return The name
+    */
+   public String getJMSProviderName()
+   {
+      if (trace)
+         log.trace("getJMSProviderName()");
+
+      return "JBoss Messaging";
+   }
+
+   /**
+    * Get the provider version
+    * @return The version
+    */
+   public String getProviderVersion()
+   {
+      if (trace)
+         log.trace("getJMSProviderName()");
+
+      return "2.0";
+   }
+
+   /**
+    * Get the provider major version
+    * @return The version
+    */
+   public int getProviderMajorVersion()
+   {
+      if (trace)
+         log.trace("getProviderMajorVersion()");
+
+      return 2;
+   }
+
+   /**
+    * Get the provider minor version
+    * @return The version
+    */
+   public int getProviderMinorVersion()
+   {
+      if (trace)
+         log.trace("getProviderMinorVersion()");
+
+      return 0;
+   }
+
+   /**
+    * Get the JMS XPropertyNames
+    * @return The names
+    */
+   public Enumeration getJMSXPropertyNames()
+   {
+      Vector v = new Vector();
+      return v.elements();
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMConnectionRequestInfo.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMConnectionRequestInfo.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMConnectionRequestInfo.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,298 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.Session;
+
+import javax.resource.spi.ConnectionRequestInfo;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * Connection request information
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision:  $
+ */
+public class JBMConnectionRequestInfo implements ConnectionRequestInfo
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMConnectionRequestInfo.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The user name */
+   private String userName;
+
+   /** The password */
+   private String password;
+
+   /** The client id */
+   private String clientID;
+
+   /** The type */
+   private int type;
+
+   /** Use XA */
+   private boolean useXA;
+
+   /** Use transactions */
+   private boolean transacted;
+
+   /** The acknowledge mode */
+   private int acknowledgeMode;
+
+   /**
+    * Constructor
+    * @param prop The managed connection factory properties
+    */
+   public JBMConnectionRequestInfo(JBMMCFProperties prop)
+   {
+      if (trace)
+         log.trace("constructor(" + prop + ")");
+
+      this.userName = prop.getUserName();
+      this.password = prop.getPassword();
+      this.clientID = prop.getClientID();
+      this.type = prop.getType();
+      this.useXA = prop.isUseXA();
+      this.transacted = true;
+      this.acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
+   }
+
+   /**
+    * Constructor
+    * @param type The connection type
+    */
+   public JBMConnectionRequestInfo(int type)
+   {
+      if (trace)
+         log.trace("constructor(" + type + ")");
+
+      this.type = type;
+      this.transacted = true;
+      this.acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
+   }
+
+   /**
+    * Constructor
+    * @param transacted Use transactions
+    * @param acknowledgeMode The acknowledge mode
+    * @param type The connection type
+    */
+   public JBMConnectionRequestInfo(boolean transacted, int acknowledgeMode, int type)
+   {
+      if (trace)
+         log.trace("constructor(" + transacted + ", " + acknowledgeMode + ", " + type + ")");
+
+      this.transacted = transacted;
+      this.acknowledgeMode = acknowledgeMode;
+      this.type = type;
+   }
+
+   /**
+    * Fill in default values if they are missing
+    * @param prop The managed connection factory properties
+    */
+   public void setDefaults(JBMMCFProperties prop)
+   {
+      if (trace)
+         log.trace("setDefaults(" + prop + ")");
+
+      if (userName == null)
+         userName = prop.getUserName();
+      if (password == null) 
+         password = prop.getPassword();
+      if (clientID == null) 
+         clientID = prop.getClientID();
+   }
+
+   /**
+    * Get the user name
+    * @return The value
+    */
+   public String getUserName() 
+   {
+      if (trace)
+         log.trace("getUserName()");
+
+      return userName;
+   }
+    
+   /**
+    * Set the user name
+    * @param userName The value
+    */
+   public void setUserName(String userName)
+   {
+      if (trace)
+         log.trace("setUserName(" + userName + ")");
+
+      this.userName = userName;
+   }
+  
+   /**
+    * Get the password
+    * @return The value
+    */
+   public String getPassword() 
+   {
+      if (trace)
+         log.trace("getPassword()");
+
+      return password;
+   }
+
+   /**
+    * Set the password
+    * @param password The value
+    */
+   public void setPassword(String password)
+   {
+      if (trace)
+         log.trace("setPassword(****)");
+
+      this.password = password;
+   }
+  
+   /**
+    * Get the client id
+    * @return The value
+    */
+   public String getClientID() 
+   {
+      if (trace)
+         log.trace("getClientID()");
+
+      return clientID;
+   }
+
+   /**
+    * Set the client id
+    * @param clientID The value
+    */
+   public void setClientID(String clientID)
+   {
+      if (trace)
+         log.trace("setClientID(" + clientID + ")");
+
+      this.clientID = clientID;
+   }
+   /**
+    * Get the connection type
+    * @return The type
+    */
+   public int getType()
+   {
+      if (trace)
+         log.trace("getType()");
+
+      return type;
+   }
+
+   /**
+    * Use XA communication
+    * @return True if XA; otherwise false
+    */
+   public boolean isUseXA()
+   {
+      if (trace)
+         log.trace("isUseXA()");
+
+      return useXA;
+   }
+
+   /**
+    * Use transactions
+    * @return True if transacted; otherwise false
+    */
+   public boolean isTransacted()
+   {
+      if (trace)
+         log.trace("isTransacted()");
+
+      return transacted;
+   }
+
+   /**
+    * Get the acknowledge mode
+    * @return The mode
+    */
+   public int getAcknowledgeMode()
+   {
+      if (trace)
+         log.trace("getAcknowledgeMode()");
+
+      return acknowledgeMode;
+   }
+
+   /**
+    * Indicates whether some other object is "equal to" this one.
+    * @param obj Object with which to compare
+    * @return True if this object is the same as the obj argument; false otherwise.
+    */
+   public boolean equals(Object obj)
+   {
+      if (trace)
+         log.trace("equals(" + obj + ")");
+
+      if (obj == null) 
+         return false;
+
+      if (obj instanceof JBMConnectionRequestInfo)
+      {
+         JBMConnectionRequestInfo you = (JBMConnectionRequestInfo) obj;
+         return (Util.compare(userName, you.getUserName()) &&
+                 Util.compare(password, you.getPassword()) &&
+                 Util.compare(clientID, you.getClientID()) &&
+                 (type == you.getType()) &&
+                 (useXA == you.isUseXA()) &&
+                 (transacted == you.isTransacted()) &&
+                 (acknowledgeMode == you.getAcknowledgeMode()));
+      }
+      else
+         return false;
+   }
+ 
+   /**
+    * Return the hash code for the object
+    * @return The hash code
+    */
+   public int hashCode()
+   {
+      if (trace)
+         log.trace("hashCode()");
+
+      int hash = 7;
+    
+      hash += 31 * hash + (userName != null ? userName.hashCode() : 0);
+      hash += 31 * hash + (password != null ? password.hashCode() : 0);
+      hash += 31 * hash + Integer.valueOf(type).hashCode();
+      hash += 31 * hash + (useXA ? 1 : 0);
+      hash += 31 * hash + (transacted ? 1 : 0);
+      hash += 31 * hash + Integer.valueOf(acknowledgeMode).hashCode();
+  
+      return hash;
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMCredential.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMCredential.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMCredential.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,232 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.io.Serializable;
+import java.util.Set;
+import java.util.Iterator;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javax.security.auth.Subject;
+
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.SecurityException;
+import javax.resource.spi.ConnectionRequestInfo;
+
+import javax.resource.spi.security.PasswordCredential;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * Credential information
+ * 
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: 71554 $
+ */
+public class JBMCredential implements Serializable
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMCredential.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The user name */
+   private String userName;
+
+   /** The password */
+   private String password;
+
+   /**
+    * Private constructor
+    */
+   private JBMCredential()
+   {
+      if (trace)
+         log.trace("constructor()");
+   }
+
+   /**
+    * Get the user name
+    * @return The value
+    */
+   public String getUserName()
+   {
+      if (trace)
+         log.trace("getUserName()");
+
+      return userName;
+   }
+
+   /**
+    * Set the user name
+    * @param userName The value
+    */
+   private void setUserName(String userName)
+   {
+      if (trace)
+         log.trace("setUserName(" + userName + ")");
+
+      this.userName = userName;
+   }
+  
+   /**
+    * Get the password
+    * @return The value
+    */
+   public String getPassword()
+   {
+      if (trace)
+         log.trace("getPassword()");
+
+      return password;
+   }
+
+   /**
+    * Set the password
+    * @param password The value
+    */
+   private void setPassword(String password)
+   {
+      if (trace)
+         log.trace("setPassword(****)");
+
+      this.password = password;
+   }
+
+   /**
+    * Get credentials
+    * @param mcf The managed connection factory
+    * @param subject The subject
+    * @param info The connection request info
+    * @return The credentials
+    * @exception SecurityException Thrown if the credentials cant be retrieved
+    */
+   public static JBMCredential getCredential(ManagedConnectionFactory mcf, Subject subject, ConnectionRequestInfo info)
+      throws SecurityException
+   {
+      if (trace)
+         log.trace("getCredential(" + mcf + ", " + subject + ", " + info + ")");
+
+      JBMCredential jc = new JBMCredential();
+      if (subject == null && info != null)
+      {
+         jc.setUserName(((JBMConnectionRequestInfo)info).getUserName());
+         jc.setPassword(((JBMConnectionRequestInfo)info).getPassword());
+      }
+      else if (subject != null)
+      {
+         PasswordCredential pwdc = GetCredentialAction.getCredential(subject, mcf);
+
+         if (pwdc == null)
+            throw new SecurityException("No password credentials found");
+
+         jc.setUserName(pwdc.getUserName());
+         jc.setPassword(new String(pwdc.getPassword()));
+      }
+      else
+      {
+         throw new SecurityException("No Subject or ConnectionRequestInfo set, could not get credentials");
+      }
+
+      return jc;
+   }
+
+   /**
+    * String representation
+    * @return The representation
+    */
+   public String toString()
+   {
+      if (trace)
+         log.trace("toString()");
+
+      return super.toString() + "{ username=" + userName + ", password=**** }";
+   }
+   
+   /**
+    * Privileged class to get credentials
+    */
+   private static class GetCredentialAction implements PrivilegedAction
+   {
+      /** The subject */
+      private Subject subject;
+
+      /** The managed connection factory */
+      private ManagedConnectionFactory mcf;
+
+      /**
+       * Constructor
+       * @param subject The subject
+       * @param mcf The managed connection factory
+       */
+      GetCredentialAction(Subject subject, ManagedConnectionFactory mcf)
+      {
+         if (trace)
+            log.trace("constructor(" + subject + ", " + mcf + ")");
+
+         this.subject = subject;
+         this.mcf = mcf;
+      }
+    
+      /**
+       * Run
+       * @return The credential
+       */
+      public Object run()
+      {
+         if (trace)
+            log.trace("run()");
+         
+         Set creds = subject.getPrivateCredentials(PasswordCredential.class);
+         PasswordCredential pwdc = null;
+         Iterator credentials = creds.iterator();
+         while (credentials.hasNext())
+         {
+            PasswordCredential curCred = (PasswordCredential) credentials.next();
+            if (curCred.getManagedConnectionFactory().equals(mcf))
+            {
+               pwdc = curCred;
+               break;
+            }
+         }
+         return pwdc;
+      }
+
+      /**
+       * Get credentials
+       * @param subject The subject
+       * @param mcf The managed connection factory
+       * @return The credential
+       */
+      static PasswordCredential getCredential(Subject subject, ManagedConnectionFactory mcf)
+      {
+         if (trace)
+            log.trace("getCredential(" + subject + ", " + mcf + ")");
+
+         GetCredentialAction action = new GetCredentialAction(subject, mcf);
+         return (PasswordCredential) AccessController.doPrivileged(action);
+      }
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMLocalTransaction.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMLocalTransaction.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMLocalTransaction.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.JMSException;
+import javax.resource.ResourceException;
+import javax.resource.spi.LocalTransaction;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * JMS Local transaction
+ * 
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMLocalTransaction implements LocalTransaction
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMLocalTransaction.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The managed connection */
+   private JBMManagedConnection mc;
+  
+   /**
+    * Constructor
+    * @param mc The managed connection
+    */
+   public JBMLocalTransaction(JBMManagedConnection mc)
+   {
+      if (trace)
+         log.trace("constructor(" + mc + ")");
+
+      this.mc = mc;
+   }
+
+   /**
+    * Begin
+    * @exception ResourceException Thrown if the operation fails
+    */
+   public void begin() throws ResourceException
+   {
+   }
+
+   /**
+    * Commit
+    * @exception ResourceException Thrown if the operation fails
+    */
+   public void commit() throws ResourceException
+   {
+      mc.lock();
+      try
+      {
+         if (mc.getSession().getTransacted())
+            mc.getSession().commit();
+      }
+      catch (JMSException e)
+      {
+         throw new ResourceException("Could not commit LocalTransaction", e);
+      }
+      finally
+      {
+         mc.unlock();
+      }
+   }
+
+   /**
+    * Rollback
+    * @exception ResourceException Thrown if the operation fails
+    */
+   public void rollback() throws ResourceException
+   {
+      mc.lock();
+      try
+      {
+         if (mc.getSession().getTransacted())
+            mc.getSession().rollback();
+      }
+      catch (JMSException ex)
+      {
+         throw new ResourceException("Could not rollback LocalTransaction", ex);
+      }
+      finally
+      {
+         mc.unlock();
+      }
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMMCFProperties.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMMCFProperties.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMMCFProperties.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,370 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.io.Serializable;
+import javax.jms.Queue;
+import javax.jms.Topic;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * The MCF default properties - these are set in the ra.xml file
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMMCFProperties implements Serializable
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMMCFProperties.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The queue type */
+   private static final String QUEUE_TYPE = Queue.class.getName();
+
+   /** The topic type */
+   private static final String TOPIC_TYPE = Topic.class.getName();
+
+   /** The discovery group name */
+   private String discoveryGroupName;
+
+   /** The discovery group port */
+   private Integer discoveryGroupPort;
+
+   /** The user name */
+   private String userName;
+
+   /** The password */
+   private String password;
+
+   /** The client ID */
+   private String clientID;
+
+   /** Use XA */
+   private Boolean useXA;
+
+   /** The connection type */
+   private int type = JBMConnectionFactory.CONNECTION;
+
+   /** Use tryLock */
+   private Integer useTryLock;
+   
+   /**
+    * Constructor
+    */
+   public JBMMCFProperties()
+   {
+      if (trace)
+         log.trace("constructor()");
+
+      discoveryGroupName = null;
+      discoveryGroupPort = null;
+      userName = null;
+      password = null;
+      clientID = null;
+      useXA = null;
+      useTryLock = null;
+   }
+   
+   /**
+    * Get the discovery group name
+    * @return The value
+    */
+   public String getDiscoveryGroupName()
+   {
+      if (trace)
+         log.trace("getDiscoveryGroupName()");
+
+      return discoveryGroupName;
+   }
+
+   /**
+    * Set the discovery group name
+    * @param dgn The value
+    */
+   public void setDiscoveryGroupName(String dgn)
+   {
+      if (trace)
+         log.trace("setDiscoveryGroupName(" + dgn + ")");
+
+      discoveryGroupName = dgn;
+   }
+
+   /**
+    * Get the discovery group port
+    * @return The value
+    */
+   public Integer getDiscoveryGroupPort()
+   {
+      if (trace)
+         log.trace("getDiscoveryGroupPort()");
+
+      return discoveryGroupPort;
+   }
+
+   /**
+    * Set the discovery group port
+    * @param dgp The value
+    */
+   public void setDiscoveryGroupPort(Integer dgp)
+   {
+      if (trace)
+         log.trace("setDiscoveryGroupPort(" + dgp + ")");
+
+      discoveryGroupPort = dgp;
+   }
+
+   /**
+    * Get the user name
+    * @return The value
+    */
+   public String getUserName()
+   {
+      if (trace)
+         log.trace("getUserName()");
+
+      return userName;
+   }
+
+   /**
+    * Set the user name
+    * @param userName The value
+    */
+   public void setUserName(String userName)
+   {
+      if (trace)
+         log.trace("setUserName(" + userName + ")");
+
+      this.userName = userName;
+   }
+  
+   /**
+    * Get the password
+    * @return The value
+    */
+   public String getPassword()
+   {
+      if (trace)
+         log.trace("getPassword()");
+
+      return password;
+   }
+
+   /**
+    * Set the password
+    * @param password The value
+    */
+   public void setPassword(String password)
+   {
+      if (trace)
+         log.trace("setPassword(****)");
+
+      this.password = password;
+   }
+  
+   /**
+    * Get the client id
+    * @return The value
+    */
+   public String getClientID()
+   {
+      if (trace)
+         log.trace("getClientID()");
+
+      return clientID;
+   }
+
+   /**
+    * Set the client id
+    * @param clientID The value
+    */
+   public void setClientID(String clientID)
+   {
+      if (trace)
+         log.trace("setClientID(" + clientID + ")");
+
+      this.clientID = clientID;
+   }
+  
+   /**
+    * Get the use XA flag
+    * @return The value
+    */
+   public Boolean getUseXA()
+   {
+      if (trace)
+         log.trace("getUseXA()");
+
+      return useXA;
+   }
+
+   /**
+    * Set the use XA flag
+    * @param xa The value
+    */
+   public void setUseXA(Boolean xa)
+   {
+      if (trace)
+         log.trace("setUseXA(" + xa + ")");
+
+      this.useXA = xa;
+   }
+
+   /**
+    * Use XA for communication
+    * @return The value
+    */
+   public boolean isUseXA()
+   {
+      if (trace)
+         log.trace("isUseXA()");
+
+      if (useXA == null)
+         return false;
+
+      return useXA.booleanValue();
+   }
+
+   /**
+    * Get the connection type
+    * @return The type
+    */
+   public int getType()
+   {
+      if (trace)
+         log.trace("getType()");
+
+      return type;
+   }
+
+   /**
+    * Set the default session type.
+    * @param defaultType either javax.jms.Topic or javax.jms.Queue
+    */
+   public void setSessionDefaultType(String defaultType)
+   {
+      if (trace)
+         log.trace("setSessionDefaultType(" + type + ")");
+
+      if (defaultType.equals(QUEUE_TYPE))
+         this.type = JBMConnectionFactory.QUEUE_CONNECTION;
+      else if(defaultType.equals(TOPIC_TYPE))
+         this.type = JBMConnectionFactory.TOPIC_CONNECTION;
+      else
+         this.type = JBMConnectionFactory.CONNECTION;
+   }
+
+   /**
+    * Get the default session type.
+    * @return The default session type
+    */
+   public String getSessionDefaultType()
+   {
+      if (trace)
+         log.trace("getSessionDefaultType()");
+
+      if (type == JBMConnectionFactory.CONNECTION)
+         return "BOTH";
+      else if (type == JBMConnectionFactory.QUEUE_CONNECTION)
+         return TOPIC_TYPE;
+      else
+         return QUEUE_TYPE;
+   }
+
+   /**
+    * Get the useTryLock.
+    * @return the useTryLock.
+    */
+   public Integer getUseTryLock()
+   {
+      if (trace)
+         log.trace("getUseTryLock()");
+
+      return useTryLock;
+   }
+   
+   /**
+    * Set the useTryLock.
+    * @param useTryLock the useTryLock.
+    */
+   public void setUseTryLock(Integer useTryLock)
+   {
+      if (trace)
+         log.trace("setUseTryLock(" + useTryLock + ")");
+
+      this.useTryLock = useTryLock;
+   }
+   
+   /**
+    * Indicates whether some other object is "equal to" this one.
+    * @param obj Object with which to compare
+    * @return True if this object is the same as the obj argument; false otherwise.
+    */
+   public boolean equals(Object obj)
+   {
+      if (trace)
+         log.trace("equals(" + obj + ")");
+
+      if (obj == null) 
+         return false;
+    
+      if (obj instanceof JBMMCFProperties)
+      {
+         JBMMCFProperties you = (JBMMCFProperties) obj;
+         return (Util.compare(discoveryGroupName, you.getDiscoveryGroupName()) &&
+                 Util.compare(discoveryGroupPort, you.getDiscoveryGroupPort()) &&
+                 Util.compare(userName, you.getUserName()) &&
+                 Util.compare(password, you.getPassword()) &&
+                 Util.compare(clientID, you.getClientID()) &&
+                 Util.compare(useXA, you.getUseXA()) &&
+                 Util.compare(useTryLock, you.getUseTryLock()));
+      }
+    
+      return false;
+   }
+  
+   /**
+    * Return the hash code for the object
+    * @return The hash code
+    */
+   public int hashCode()
+   {
+      if (trace)
+         log.trace("hashCode()");
+
+      int hash = 7;
+
+      hash += 31 * hash + (discoveryGroupName != null ? discoveryGroupName.hashCode() : 0);
+      hash += 31 * hash + (discoveryGroupPort != null ? discoveryGroupPort.hashCode() : 0);
+      hash += 31 * hash + (userName != null ? userName.hashCode() : 0);
+      hash += 31 * hash + (password != null ? password.hashCode() : 0);
+      hash += 31 * hash + (clientID != null ? clientID.hashCode() : 0);
+      hash += 31 * hash + (useXA != null ? useXA.hashCode() : 0);
+      hash += 31 * hash + (useTryLock != null ? useTryLock.hashCode() : 0);
+
+      return hash;
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMManagedConnection.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMManagedConnection.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMManagedConnection.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,838 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.jms.Connection;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.QueueConnection;
+import javax.jms.QueueSession;
+import javax.jms.ResourceAllocationException;
+import javax.jms.Session;
+import javax.jms.TopicConnection;
+import javax.jms.TopicSession;
+import javax.jms.XAConnection;
+import javax.jms.XAQueueConnection;
+import javax.jms.XAQueueSession;
+import javax.jms.XASession;
+import javax.jms.XATopicConnection;
+import javax.jms.XATopicSession;
+import javax.resource.NotSupportedException;
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionEvent;
+import javax.resource.spi.ConnectionEventListener;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.IllegalStateException;
+import javax.resource.spi.LocalTransaction;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionMetaData;
+import javax.resource.spi.SecurityException;
+import javax.security.auth.Subject;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * The managed connection
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision:  $
+ */
+public class JBMManagedConnection implements ManagedConnection, ExceptionListener
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMManagedConnection.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+   
+   /** The managed connection factory */
+   private JBMManagedConnectionFactory mcf;
+
+   /** The connection request information */
+   private JBMConnectionRequestInfo cri;
+
+   /** The user name */
+   private String userName;
+
+   /** The password */
+   private String password;
+
+   /** Has the connection been destroyed */
+   private AtomicBoolean isDestroyed = new AtomicBoolean(false);
+
+   /** Event listeners */
+   private List eventListeners;
+   
+   /** Handles */
+   private Set handles;
+
+   /** Lock */
+   private ReentrantLock lock = new ReentrantLock();
+   
+   // Physical JMS connection stuff
+   private Connection connection;
+   private XAConnection xaConnection;
+   private Session session;
+   private TopicSession topicSession;
+   private QueueSession queueSession;
+   private XASession xaSession;
+   private XATopicSession xaTopicSession;
+   private XAQueueSession xaQueueSession;
+   private XAResource xaResource;
+
+   /**
+    * Constructor
+    * @param mcf The managed connection factory
+    * @param cri The connection request information
+    * @param userName The user name
+    * @param password The password
+    */
+   public JBMManagedConnection(JBMManagedConnectionFactory mcf, 
+                               JBMConnectionRequestInfo cri,
+                               String userName, 
+                               String password)
+      throws ResourceException
+   {
+      if (trace)
+         log.trace("constructor(" + mcf + ", " + cri + ", " + userName + ", ****)");
+
+      this.mcf = mcf;
+      this.cri = cri;
+      this.userName = userName;
+      this.password = password;
+      this.eventListeners = Collections.synchronizedList(new ArrayList());
+      this.handles = Collections.synchronizedSet(new HashSet());
+
+      this.connection = null;
+      this.xaConnection = null;
+      this.session = null;
+      this.topicSession = null;
+      this.queueSession = null;
+      this.xaSession = null;
+      this.xaTopicSession = null;
+      this.xaQueueSession = null;
+      this.xaResource = null;
+
+      try
+      {
+         setup();
+      }
+      catch (Throwable t)
+      {
+         try
+         {
+            destroy();
+         }
+         catch (Throwable ignored)
+         {
+         }
+         throw new ResourceException("Error during setup", t);
+      }
+   }
+
+   /**
+    * Get a connection
+    * @param subject The security subject
+    * @param cxRequestInfo The request info
+    * @return The connection
+    * @exception ResourceException Thrown if an error occurs
+    */
+   public synchronized Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo)
+      throws ResourceException
+   {
+      if (trace)
+         log.trace("getConnection(" + subject + ", " + cxRequestInfo + ")");
+
+      // Check user first
+      JBMCredential credential = JBMCredential.getCredential(mcf, subject, cxRequestInfo);
+
+      // Null users are allowed!
+      if (userName != null && !userName.equals(credential.getUserName()))
+         throw new SecurityException("Password credentials not the same, reauthentication not allowed");
+
+      if (userName == null && credential.getUserName() != null)
+         throw new SecurityException("Password credentials not the same, reauthentication not allowed");
+
+      if (isDestroyed.get())
+         throw new IllegalStateException("The managed connection is already destroyed");
+
+      Object session = null; // TODO - get one from JBossConnection -- new JBMSession(this, (JBMConnectionRequestInfo)cxRequestInfo);
+      handles.add(session);
+      return session;
+   }
+
+   /**
+    * Destroy all handles.
+    * @exception ResourceException Failed to close one or more handles.
+    */
+   private void destroyHandles() throws ResourceException
+   {
+      if (trace)
+         log.trace("destroyHandles()");
+
+      try
+      {
+         if (xaConnection != null)
+            xaConnection.stop();  
+
+         if (connection != null)
+            connection.stop();  
+      }
+      catch (Throwable t)
+      {
+         log.trace("Ignored error stopping connection", t);
+      }
+      
+      Iterator it = handles.iterator();
+      while (it.hasNext())
+         ((JBMSession)it.next()).destroy();
+
+      handles.clear();
+   }
+
+   /**
+    * Destroy the physical connection.
+    * @exception ResourceException Could not property close the session and connection.
+    */
+   public void destroy() throws ResourceException
+   {
+      if (trace)
+         log.trace("destroy()");
+
+      if (isDestroyed.get() || (xaConnection == null && connection == null))
+         return;
+
+      isDestroyed.set(true);
+
+      try
+      {
+         if (xaConnection != null)
+         {
+            xaConnection.setExceptionListener(null);
+         }
+         else
+         {
+            connection.setExceptionListener(null);
+         }
+      }
+      catch (JMSException e)
+      {
+         log.debug("Error unsetting the exception listener " + this, e);
+      }
+      
+      destroyHandles();
+      
+      try
+      {
+         try
+         {
+            if (topicSession != null)
+               topicSession.close();
+
+            if (xaTopicSession != null)
+               xaTopicSession.close();
+
+            if (queueSession != null)
+               queueSession.close();
+
+            if (xaQueueSession != null)
+               xaQueueSession.close();
+
+            if (session != null)
+               session.close();
+
+            if (xaSession != null)
+               xaSession.close();
+         }
+         catch (JMSException e)
+         {
+            log.debug("Error closing session " + this, e);
+         }
+
+         if (connection != null)
+            connection.close();
+
+         if (xaConnection != null)
+            xaConnection.close();
+      }
+      catch (Throwable e)
+      {
+         throw new ResourceException("Could not properly close the session and connection", e);
+      }
+   }
+
+   /**
+    * Cleanup
+    * @exception ResourceException Thrown if an error occurs
+    */
+   public void cleanup() throws ResourceException
+   {
+      if (trace)
+         log.trace("cleanup()");
+
+      if (isDestroyed.get())
+         throw new IllegalStateException("ManagedConnection already destroyed");
+
+      destroyHandles();
+
+      // I'm recreating the lock object when we return to the pool
+      // because it looks too nasty to expect the connection handle
+      // to unlock properly in certain race conditions
+      // where the dissociation of the managed connection is "random".
+      lock = new ReentrantLock();
+   }
+
+   /**
+    * Move a handler from one mc to this one.
+    * @param obj An object of type JBMSession.
+    * @throws ResourceException Failed to associate connection.
+    * @throws IllegalStateException ManagedConnection in an illegal state.
+    */
+   public void associateConnection(final Object obj) throws ResourceException
+   {
+      if (trace)
+         log.trace("associateConnection(" + obj + ")");
+
+      if (!isDestroyed.get() && obj instanceof JBMSession)
+      {
+         JBMSession h = (JBMSession)obj;
+         h.setManagedConnection(this);
+         handles.add(h);
+      }
+      else
+         throw new IllegalStateException("ManagedConnection in an illegal state");
+   }
+
+   /**
+    * Aqquire a lock on the managed connection
+    */
+   protected void lock()
+   {
+      if (trace)
+         log.trace("lock()");
+
+      lock.lock();
+   }
+
+   /**
+    * Aqquire a lock on the managed connection within the specified period
+    * @exception JMSException Thrown if an error occurs
+    */
+   protected void tryLock() throws JMSException
+   {
+      if (trace)
+         log.trace("tryLock()");
+
+      Integer tryLock = mcf.getUseTryLock();
+      if (tryLock == null || tryLock.intValue() <= 0)
+      {
+         lock();
+         return;
+      }
+      try
+      {
+         if (lock.tryLock(tryLock.intValue(), TimeUnit.SECONDS) == false)
+            throw new ResourceAllocationException("Unable to obtain lock in " + tryLock + " seconds: " + this);
+      }
+      catch (InterruptedException e)
+      {
+         throw new ResourceAllocationException("Interrupted attempting lock: " + this);
+      }
+   }
+
+   /**
+    * Unlock the managed connection
+    */
+   protected void unlock()
+   {
+      if (trace)
+         log.trace("unlock()");
+
+      lock.unlock();
+   }
+
+   /**
+    * Add a connection event listener.
+    * @param l The connection event listener to be added.
+    */
+   public void addConnectionEventListener(ConnectionEventListener l)
+   {
+      if (trace)
+         log.trace("addConnectionEventListener(" + l + ")");
+      
+      eventListeners.add(l);
+   }
+
+   /**
+    * Remove a connection event listener.
+    * @param l The connection event listener to be removed.
+    */
+   public void removeConnectionEventListener(ConnectionEventListener l)
+   {
+      if (trace)
+         log.trace("removeConnectionEventListener(" + l + ")");
+
+      eventListeners.remove(l);
+   }
+
+   /**
+    * Get the XAResource for the connection.
+    * @return The XAResource for the connection.
+    * @exception ResourceException XA transaction not supported
+    */
+   public XAResource getXAResource() throws ResourceException
+   {
+      if (trace)
+         log.trace("getXAResource()");
+      
+      if (xaConnection == null)
+         throw new NotSupportedException("Non XA transaction not supported");
+
+      //
+      // Spec says a mc must allways return the same XA resource,
+      // so we cache it.
+      //
+      if (xaResource == null)
+      {
+         if (xaTopicSession != null)
+            xaResource = xaTopicSession.getXAResource();
+         else if (xaQueueSession != null)
+            xaResource = xaQueueSession.getXAResource();
+         else
+            xaResource = xaSession.getXAResource();
+      }
+
+      if (trace)
+         log.trace("XAResource=" + xaResource);
+
+      xaResource = new JBMXAResource(this, xaResource);
+      return xaResource;
+   }
+
+   /**
+    * Get the location transaction for the connection.
+    * @return The local transaction for the connection.
+    * @exception ResourceException Thrown if operation fails.
+    */
+   public LocalTransaction getLocalTransaction() throws ResourceException
+   {
+      if (trace)
+         log.trace("getLocalTransaction()");
+      
+      LocalTransaction tx = new JBMLocalTransaction(this);
+
+      if (trace)
+         log.trace("LocalTransaction=" + tx);
+
+      return tx;
+   }
+
+   /**
+    * Get the meta data for the connection.
+    * @return The meta data for the connection.
+    * @exception ResourceException Thrown if the operation fails.
+    * @exception IllegalStateException Thrown if the managed connection already is destroyed.
+    */
+   public ManagedConnectionMetaData getMetaData() throws ResourceException
+   {
+      if (trace)
+         log.trace("getMetaData()");
+      
+      if (isDestroyed.get())
+         throw new IllegalStateException("The managed connection is already destroyed");
+
+      return new JBMMetaData(this);
+   }
+
+   /**
+    * Set the log writer -- NOT SUPPORTED
+    * @param out The log writer
+    * @exception ResourceException If operation fails
+    */
+   public void setLogWriter(PrintWriter out) throws ResourceException
+   {
+      if (trace)
+         log.trace("setLogWriter(" + out + ")");
+   }
+
+   /**
+    * Get the log writer -- NOT SUPPORTED
+    * @return Always null
+    * @exception ResourceException If operation fails
+    */
+   public PrintWriter getLogWriter() throws ResourceException
+   {
+      if (trace)
+         log.trace("getLogWriter()");
+
+      return null;
+   }
+
+   /**
+    * Notifies user of a JMS exception.
+    * @param exception The JMS exception
+    */
+   public void onException(JMSException exception)
+   {
+      if (trace)
+         log.trace("onException(" + exception + ")");
+
+      if (isDestroyed.get())
+      {
+         if (trace)
+            log.trace("Ignoring error on already destroyed connection " + this, exception);
+         return;
+      }
+
+      log.warn("Handling JMS exception failure: " + this, exception);
+
+      try
+      {
+         if (xaConnection != null)
+         {
+            xaConnection.setExceptionListener(null);
+         }
+         else
+         {
+            connection.setExceptionListener(null);
+         }
+      }
+      catch (JMSException e)
+      {
+         log.debug("Unable to unset exception listener", e);
+      }
+      
+      ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, exception);
+      sendEvent(event);
+   }
+   
+   /**
+    * Is managed connection running in XA mode
+    * @return True if XA; otherwise false
+    */
+   protected boolean isXA()
+   {
+      if (trace)
+         log.trace("isXA()");
+
+      return xaConnection != null;
+   }
+
+   /**
+    * Get the XA session for this connection.
+    * @return The XA session
+    */
+   protected XASession getXASession()
+   {
+      if (trace)
+         log.trace("getXASession()");
+
+      if (isXA())
+      {
+         if (xaTopicSession != null)
+            return xaTopicSession;
+         else if (xaQueueSession != null)
+            return xaQueueSession;
+         else
+            return xaSession;
+      }
+      else
+         return null;
+   }
+
+   /**
+    * Get the session for this connection.
+    * @return The session
+    */
+   protected Session getSession()
+   {
+      if (trace)
+         log.trace("getSession()");
+
+      if (topicSession != null)
+         return topicSession;
+      else if (queueSession != null)
+         return queueSession;
+      else
+         return session;
+   }
+
+   /**
+    * Send an event.
+    * @param event The event to send.
+    */
+   protected void sendEvent(ConnectionEvent event)
+   {
+      if (trace)
+         log.trace("sendEvent(" + event + ")");
+
+      int type = event.getId();
+
+      // convert to an array to avoid concurrent modification exceptions
+      ConnectionEventListener[] list =
+         (ConnectionEventListener[])eventListeners.toArray(new ConnectionEventListener[eventListeners.size()]);
+
+      for (ConnectionEventListener l : list)
+      {
+         switch (type) {
+            case ConnectionEvent.CONNECTION_CLOSED:
+               l.connectionClosed(event);
+               break;
+
+            case ConnectionEvent.LOCAL_TRANSACTION_STARTED:
+               l.localTransactionStarted(event);
+               break;
+
+            case ConnectionEvent.LOCAL_TRANSACTION_COMMITTED:
+               l.localTransactionCommitted(event);
+               break;
+
+            case ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK:
+               l.localTransactionRolledback(event);
+               break;
+
+            case ConnectionEvent.CONNECTION_ERROR_OCCURRED:
+               l.connectionErrorOccurred(event);
+               break;
+
+            default:
+               throw new IllegalArgumentException("Illegal eventType: " + type);
+         }
+      }
+   }
+
+   /**
+    * Remove a handle from the handle map.
+    * @param handle The handle to remove.
+    */
+   protected void removeHandle(JBMSession handle)
+   {
+      if (trace)
+         log.trace("removeHandle(" + handle + ")");
+
+      handles.remove(handle);
+   }
+
+   /**
+    * Get the request info for this connection.
+    * @return The connection request info for this connection.
+    */
+   protected JBMConnectionRequestInfo getCRI()
+   {
+      if (trace)
+         log.trace("getCRI()");
+
+      return cri;
+   }
+
+   /**
+    * Get the connection factory for this connection.
+    * @return The connection factory for this connection.
+    */
+   protected JBMManagedConnectionFactory getManagedConnectionFactory()
+   {
+      if (trace)
+         log.trace("getManagedConnectionFactory()");
+
+      return mcf;
+   }
+
+   /**
+    * Start the connection
+    * @exception JMSException Thrown if the connection cant be started
+    */
+   void start() throws JMSException
+   {
+      if (trace)
+         log.trace("start()");
+
+      if (connection != null)
+         connection.start();
+
+      if (xaConnection != null)
+         xaConnection.start();
+   }
+
+   /**
+    * Stop the connection
+    * @exception JMSException Thrown if the connection cant be stopped
+    */
+   void stop() throws JMSException
+   {
+      if (trace)
+         log.trace("stop()");
+
+      if (xaConnection != null)
+         xaConnection.stop();
+
+      if (connection != null)
+         connection.stop();
+   }
+   
+   /**
+    * Get the user name
+    * @return The user name
+    */
+   protected String getUserName()
+   {
+      if (trace)
+         log.trace("getUserName()");
+
+      return userName;
+   }
+
+   /**
+    * Setup the connection.
+    * @exception ResourceException Thrown if a connection couldnt be created
+    */
+   private void setup() throws ResourceException
+   {
+      if (trace)
+         log.trace("setup()");
+
+      try
+      {
+         boolean transacted = cri.isTransacted();
+         int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
+
+         if (cri.getType() == JBMConnectionFactory.TOPIC_CONNECTION)
+         {
+            if (cri.isUseXA())
+            {
+               if (userName != null && password != null)
+               {
+                  xaConnection = mcf.getJBossConnectionFactory().createXATopicConnection(userName, password);
+               }
+               else
+               {
+                  xaConnection = mcf.getJBossConnectionFactory().createXATopicConnection();
+               }
+
+               xaConnection.setExceptionListener(this);
+
+               xaTopicSession = ((XATopicConnection)xaConnection).createXATopicSession();
+               topicSession = xaTopicSession.getTopicSession();
+            }
+            else
+            {
+               if (userName != null && password != null)
+               {
+                  connection = mcf.getJBossConnectionFactory().createTopicConnection(userName, password);
+               }
+               else
+               {
+                  connection = mcf.getJBossConnectionFactory().createTopicConnection();
+               }
+
+               connection.setExceptionListener(this);
+
+               topicSession = ((TopicConnection)connection).createTopicSession(transacted, acknowledgeMode);
+            }
+         }
+         else if (cri.getType() == JBMConnectionFactory.QUEUE_CONNECTION)
+         {
+            if (cri.isUseXA())
+            {
+               if (userName != null && password != null)
+               {
+                  xaConnection = mcf.getJBossConnectionFactory().createXAQueueConnection(userName, password);
+               }
+               else
+               {
+                  xaConnection = mcf.getJBossConnectionFactory().createXAQueueConnection();
+               }
+
+               xaConnection.setExceptionListener(this);
+
+               xaQueueSession = ((XAQueueConnection)xaConnection).createXAQueueSession();
+               queueSession = xaQueueSession.getQueueSession();
+            }
+            else
+            {
+               if (userName != null && password != null)
+               {
+                  connection = mcf.getJBossConnectionFactory().createQueueConnection(userName, password);
+               }
+               else
+               {
+                  connection = mcf.getJBossConnectionFactory().createQueueConnection();
+               }
+
+               connection.setExceptionListener(this);
+
+               queueSession = ((QueueConnection)connection).createQueueSession(transacted, acknowledgeMode);
+            }
+         }
+         else
+         {
+            if (cri.isUseXA())
+            {
+               if (userName != null && password != null)
+               {
+                  xaConnection = mcf.getJBossConnectionFactory().createXAConnection(userName, password);
+               }
+               else
+               {
+                  xaConnection = mcf.getJBossConnectionFactory().createXAConnection();
+               }
+
+               xaConnection.setExceptionListener(this);
+
+               xaSession = xaConnection.createXASession();
+               session = xaSession.getSession();
+            }
+            else
+            {
+               if (userName != null && password != null)
+               {
+                  connection = mcf.getJBossConnectionFactory().createConnection(userName, password);
+               }
+               else
+               {
+                  connection = mcf.getJBossConnectionFactory().createConnection();
+               }
+
+               connection.setExceptionListener(this);
+
+               session = connection.createSession(transacted, acknowledgeMode);
+            }
+         }
+      }
+      catch (JMSException je)
+      {
+         throw new ResourceException(je.getMessage(), je);
+      }
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMManagedConnectionFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMManagedConnectionFactory.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMManagedConnectionFactory.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,519 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.jms.ConnectionMetaData;
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+
+/**
+ * JBM ManagedConectionFactory
+ * 
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>.
+ * @version $Revision: $
+ */
+public class JBMManagedConnectionFactory implements ManagedConnectionFactory
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMManagedConnectionFactory.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+   
+   /** Connection manager */
+   private ConnectionManager cm;
+
+   /** The managed connection factory properties */
+   private JBMMCFProperties mcfProperties;
+
+   /** The JBoss connection factory */
+   private JBossConnectionFactory factory;
+   
+   /** Have the factory been configured */
+   private AtomicBoolean configured;
+
+   /**
+    * Constructor
+    */
+   public JBMManagedConnectionFactory()
+   {
+      if (trace)
+         log.trace("constructor()");
+      
+      mcfProperties = new JBMMCFProperties();
+      configured = new AtomicBoolean(false);
+   }
+  
+   /**
+    * Creates a Connection Factory instance
+    * @return javax.resource.cci.ConnectionFactory instance
+    * @exception ResourceException Thrown if a connection factory cant be created
+    */
+   public Object createConnectionFactory() throws ResourceException
+   {
+      if (trace)
+         log.debug("createConnectionFactory()");
+      
+      return createConnectionFactory(new JBMConnectionManager());
+   }
+
+   /**
+    * Creates a Connection Factory instance
+    * @param cxManager The connection manager
+    * @return javax.resource.cci.ConnectionFactory instance
+    * @exception ResourceException Thrown if a connection factory cant be created
+    */
+   public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException
+   {
+      if (trace)
+         log.trace("createConnectionFactory(" + cxManager + ")");
+
+      cm = cxManager;
+
+      JBMConnectionFactory cf = new JBMConnectionFactoryImpl(this, cm);
+
+      if (trace)
+         log.trace("Created connection factory: " + cf + ", using connection manager: " + cm);
+      
+      return cf;
+   }
+   
+   /**
+    * Creates a new physical connection to the underlying EIS resource manager.
+    * @param subject Caller's security information
+    * @param cxRequestInfo Additional resource adapter specific connection request information
+    * @return The managed connection
+    * @exception ResourceException Thrown if a managed connection cant be created
+    */
+   public ManagedConnection createManagedConnection(Subject subject,
+                                                    ConnectionRequestInfo cxRequestInfo)
+      throws ResourceException 
+   {
+      if (trace)
+         log.trace("createManagedConnection(" + subject + ", " + cxRequestInfo + ")");
+
+      JBMConnectionRequestInfo cri = getCRI((JBMConnectionRequestInfo)cxRequestInfo);
+
+      JBMCredential credential = JBMCredential.getCredential(this, subject, cri);
+
+      if (trace)
+         log.trace("jms credential: " + credential);
+
+      JBMManagedConnection mc = new JBMManagedConnection(this, cri, credential.getUserName(), credential.getPassword());
+    
+      if (trace)
+         log.trace("created new managed connection: " + mc);
+      
+      return mc;
+   }
+
+   /**
+    * Returns a matched connection from the candidate set of connections.
+    * @param connectionSet The candidate connection set
+    * @param subject Caller's security information
+    * @param cxRequestInfo Additional resource adapter specific connection request information
+    * @return The managed connection
+    * @exception ResourceException Thrown if no managed connection cant be found
+    */
+   public ManagedConnection matchManagedConnections(Set connectionSet,
+                                                    Subject subject,
+                                                    ConnectionRequestInfo cxRequestInfo)
+      throws ResourceException
+   {
+      if (trace)
+         log.trace("matchManagedConnections(" + connectionSet + ", " + subject + ", " + cxRequestInfo + ")");
+
+      JBMConnectionRequestInfo cri = getCRI((JBMConnectionRequestInfo)cxRequestInfo);
+      JBMCredential credential = JBMCredential.getCredential(this, subject, cri);
+      
+      if (trace)
+         log.trace("Looking for connection matching credentials: " + credential);
+      
+      Iterator connections = connectionSet.iterator();
+      
+      while (connections.hasNext())
+      {
+         Object obj = connections.next();
+      
+         if (obj instanceof JBMManagedConnection)
+         {
+            JBMManagedConnection mc = (JBMManagedConnection) obj;
+            ManagedConnectionFactory mcf = mc.getManagedConnectionFactory();
+        
+            if ((mc.getUserName() == null || (mc.getUserName() != null && mc.getUserName().equals(credential.getUserName()))) && mcf.equals(this))
+            {
+               if (cri.equals(mc.getCRI()))
+               {
+                  if (trace)
+                     log.trace("Found matching connection: " + mc);
+                  
+                  return mc;
+               }
+            }
+         }
+      }
+      
+      if (trace)
+         log.trace("No matching connection was found");
+
+      return null;
+   }
+
+   /**
+    * Set the log writer -- NOT SUPPORTED
+    * @param out The writer
+    * @exception ResourceException Thrown if the writer cant be set
+    */
+   public void setLogWriter(PrintWriter out) throws ResourceException
+   {
+      if (trace)
+         log.trace("setLogWriter(" + out + ")");
+   }
+
+   /**
+    * Get the log writer -- NOT SUPPORTED
+    * @return The writer
+    * @exception ResourceException Thrown if the writer cant be retrieved
+    */
+   public PrintWriter getLogWriter() throws ResourceException
+   {
+      if (trace)
+         log.trace("getLogWriter()");
+
+      return null;
+   }
+
+   /**
+    * Indicates whether some other object is "equal to" this one.
+    * @param obj Object with which to compare
+    * @return True if this object is the same as the obj argument; false otherwise.
+    */
+   public boolean equals(Object obj)
+   {
+      if (trace)
+         log.trace("equals(" + obj + ")");
+
+      if (obj == null)
+         return false;
+
+      if (obj instanceof JBMManagedConnectionFactory)
+      {
+         return mcfProperties.equals(((JBMManagedConnectionFactory)obj).getProperties());
+      }
+      else
+      {
+         return false;
+      }
+   }
+
+   /**
+    * Return the hash code for the object
+    * @return The hash code
+    */
+   public int hashCode()
+   {
+      if (trace)
+         log.trace("hashCode()");
+
+      return mcfProperties.hashCode();
+   }
+
+   /**
+    * Get the discovery group name
+    * @return The value
+    */
+   public String getDiscoveryGroupName()
+   {
+      if (trace)
+         log.trace("getDiscoveryGroupName()");
+
+      return mcfProperties.getDiscoveryGroupName();
+   }
+
+   /**
+    * Set the discovery group name
+    * @param dgn The value
+    */
+   public void setDiscoveryGroupName(String dgn)
+   {
+      if (trace)
+         log.trace("setDiscoveryGroupName(" + dgn + ")");
+
+      mcfProperties.setDiscoveryGroupName(dgn);
+   }
+
+   /**
+    * Get the discovery group port
+    * @return The value
+    */
+   public Integer getDiscoveryGroupPort()
+   {
+      if (trace)
+         log.trace("getDiscoveryGroupPort()");
+
+      return mcfProperties.getDiscoveryGroupPort();
+   }
+
+   /**
+    * Set the discovery group port
+    * @param dgp The value
+    */
+   public void setDiscoveryGroupPort(Integer dgp)
+   {
+      if (trace)
+         log.trace("setDiscoveryGroupPort(" + dgp + ")");
+
+      mcfProperties.setDiscoveryGroupPort(dgp);
+   }
+
+   /**
+    * Get the user name
+    * @return The value
+    */
+   public String getUserName()
+   {
+      if (trace)
+         log.trace("getUserName()");
+
+      return mcfProperties.getUserName();
+   }
+
+   /**
+    * Set the user name
+    * @param userName The value
+    */
+   public void setUserName(String userName)
+   {
+      if (trace)
+         log.trace("setUserName(" + userName + ")");
+
+      mcfProperties.setUserName(userName);
+   }
+
+   /**
+    * Get the password
+    * @return The value
+    */
+   public String getPassword()
+   {
+      if (trace)
+         log.trace("getPassword()");
+
+      return mcfProperties.getPassword();
+   }
+
+   /**
+    * Set the password
+    * @param password The value
+    */
+   public void setPassword(String password)
+   {
+      if (trace)
+         log.trace("setPassword(****)");
+
+      mcfProperties.setPassword(password);
+   }
+   
+   /**
+    * Get the client ID
+    * @return The value
+    */
+   public String getClientID()
+   {
+      if (trace)
+         log.trace("getClientID()");
+
+      return mcfProperties.getClientID();
+   }
+
+   /**
+    * Set the client ID
+    * @param clientId The client id
+    */
+   public void setClientID(String clientID)
+   {
+      if (trace)
+         log.trace("setClientID(" + clientID + ")");
+
+      mcfProperties.setClientID(clientID);
+   }
+   
+   /**
+    * Get the use XA flag
+    * @return The value
+    */
+   public Boolean getUseXA()
+   {
+      if (trace)
+         log.trace("getUseXA()");
+
+      return mcfProperties.getUseXA();
+   }
+
+   /**
+    * Set the use XA flag
+    * @param xa The value
+    */
+   public void setUseXA(Boolean xa)
+   {
+      if (trace)
+         log.trace("setUseXA(" + xa + ")");
+
+      mcfProperties.setUseXA(xa);
+   }
+
+   /**
+    * Get the default session type
+    * @return The value
+    */
+   public String getSessionDefaultType()
+   {
+      if (trace)
+         log.trace("getSessionDefaultType()");
+
+      return mcfProperties.getSessionDefaultType();
+   }
+
+   /**
+    * Set the default session type
+    * @param type either javax.jms.Topic or javax.jms.Queue
+    */
+   public void setSessionDefaultType(String type)
+   {
+      if (trace)
+         log.trace("setSessionDefaultType(" + type + ")");
+
+      mcfProperties.setSessionDefaultType(type);
+   }
+
+   /**
+    * Get the useTryLock.
+    * @return the useTryLock.
+    */
+   public Integer getUseTryLock()
+   {
+      if (trace)
+         log.trace("getUseTryLock()");
+
+      return mcfProperties.getUseTryLock();
+   }
+   
+   /**
+    * Set the useTryLock.
+    * @param useTryLock the useTryLock.
+    */
+   public void setUseTryLock(Integer useTryLock)
+   {
+      if (trace)
+         log.trace("setUseTryLock(" + useTryLock + ")");
+
+      mcfProperties.setUseTryLock(useTryLock);
+   }
+   
+   /**
+    * Get a connection request info instance
+    * @param info The instance that should be updated; may be <code>null</code>
+    * @return The instance
+    */
+   private JBMConnectionRequestInfo getCRI(JBMConnectionRequestInfo info)
+   {
+      if (trace)
+         log.trace("getCRI(" + info + ")");
+
+      if (info == null)
+      {
+         // Create a default one
+         return new JBMConnectionRequestInfo(mcfProperties);
+      }
+      else
+      {
+         // Fill the one with any defaults
+         info.setDefaults(mcfProperties);
+         return info;
+      }
+   }
+   
+   /**
+    * Get the connection metadata
+    * @return The metadata
+    */
+   public ConnectionMetaData getMetaData()
+   {
+      if (trace)
+         log.trace("getMetadata()");
+
+      return new JBMConnectionMetaData();
+   }
+
+   /**
+    * Get the managed connection factory properties
+    * @return The properties
+    */
+   public JBMMCFProperties getProperties()
+   {
+      if (trace)
+         log.trace("getProperties()");
+
+      return mcfProperties;
+   }
+
+   /**
+    * Get the JBoss connection factory
+    * @return The factory
+    */
+   protected JBossConnectionFactory getJBossConnectionFactory()
+   {
+      if (!configured.get()) {
+         setup();
+      }
+
+      return factory;
+   }
+
+   /**
+    * Setup the factory
+    */
+   protected void setup()
+   {
+      if (getDiscoveryGroupName() != null &&
+          !getDiscoveryGroupName().trim().equals("") &&
+          getDiscoveryGroupPort() != null)
+      {
+         factory = new JBossConnectionFactory(getDiscoveryGroupName(), getDiscoveryGroupPort().intValue());
+
+         configured.set(true);
+      }
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMMapMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMMapMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMMapMessage.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,410 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.util.Enumeration;
+
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A wrapper for a message
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: 71554 $
+ */
+public class JBMMapMessage extends JBMMessage implements MapMessage
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMMapMessage.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**
+    * Create a new wrapper
+    * 
+    * @param message the message
+    * @param session the session
+    */
+   public JBMMapMessage(MapMessage message, JBMSession session)
+   {
+      super(message, session);
+
+      if (trace)
+         log.trace("constructor(" + message + ", " + session + ")");
+   }
+
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean getBoolean(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getBoolean(" + name + ")");
+
+      return ((MapMessage) message).getBoolean(name);
+   }
+   
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public byte getByte(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getByte(" + name + ")");
+
+      return ((MapMessage) message).getByte(name);
+   }
+
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public byte[] getBytes(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getBytes(" + name + ")");
+
+      return ((MapMessage) message).getBytes(name);
+   }
+
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public char getChar(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getChar(" + name + ")");
+
+      return ((MapMessage) message).getChar(name);
+   }
+
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public double getDouble(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getDouble(" + name + ")");
+
+      return ((MapMessage) message).getDouble(name);
+   }
+
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public float getFloat(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getFloat(" + name + ")");
+
+      return ((MapMessage) message).getFloat(name);
+   }
+   
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int getInt(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getInt(" + name + ")");
+
+      return ((MapMessage) message).getInt(name);
+   }
+
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public long getLong(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getLong(" + name + ")");
+
+      return ((MapMessage) message).getLong(name);
+   }
+
+   /**
+    * Get the map names
+    * @return The values 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Enumeration getMapNames() throws JMSException
+   {
+      if (trace)
+         log.trace("getMapNames()");
+
+      return ((MapMessage) message).getMapNames();
+   }
+
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Object getObject(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getObject(" + name + ")");
+
+      return ((MapMessage) message).getObject(name);
+   }
+
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public short getShort(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getShort(" + name + ")");
+
+      return ((MapMessage) message).getShort(name);
+   }
+
+   /**
+    * Get
+    * @param name The name
+    * @return The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public String getString(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getString(" + name + ")");
+
+      return ((MapMessage) message).getString(name);
+   }
+
+   /**
+    * Does the item exist
+    * @param name The name
+    * @return True / false
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean itemExists(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("itemExists(" + name + ")");
+
+      return ((MapMessage) message).itemExists(name);
+   }
+
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setBoolean(String name, boolean value) throws JMSException
+   {
+      if (trace)
+         log.trace("setBoolean(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setBoolean(name, value);
+   }
+
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setByte(String name, byte value) throws JMSException
+   {
+      if (trace)
+         log.trace("setByte(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setByte(name, value);
+   }
+
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @param offset The offset
+    * @param length The length
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setBytes(String name, byte[] value, int offset, int length) throws JMSException
+   {
+      if (trace)
+         log.trace("setBytes(" + name + ", " + value + ", " + offset + ", " + length + ")");
+
+      ((MapMessage) message).setBytes(name, value, offset, length);
+   }
+
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setBytes(String name, byte[] value) throws JMSException
+   {
+      if (trace)
+         log.trace("setBytes(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setBytes(name, value);
+   }
+
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setChar(String name, char value) throws JMSException
+   {
+      if (trace)
+         log.trace("setChar(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setChar(name, value);
+   }
+
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setDouble(String name, double value) throws JMSException
+   {
+      if (trace)
+         log.trace("setDouble(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setDouble(name, value);
+   }
+
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setFloat(String name, float value) throws JMSException
+   {
+      if (trace)
+         log.trace("setFloat(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setFloat(name, value);
+   }
+
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setInt(String name, int value) throws JMSException
+   {
+      if (trace)
+         log.trace("setInt(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setInt(name, value);
+   }
+
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setLong(String name, long value) throws JMSException
+   {
+      if (trace)
+         log.trace("setLong(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setLong(name, value);
+   }
+   
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setObject(String name, Object value) throws JMSException
+   {
+      if (trace)
+         log.trace("setObject(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setObject(name, value);
+   }
+   
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setShort(String name, short value) throws JMSException
+   {
+      if (trace)
+         log.trace("setShort(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setShort(name, value);
+   }
+
+   /**
+    * Set
+    * @param name The name
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setString(String name, String value) throws JMSException
+   {
+      if (trace)
+         log.trace("setString(" + name + ", " + value + ")");
+
+      ((MapMessage) message).setString(name, value);
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMMessage.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,707 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.util.Enumeration;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A wrapper for a message
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMMessage implements Message
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMMessage.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The message */
+   protected Message message;
+   
+   /** The session */
+   protected JBMSession session;
+
+   /**
+    * Create a new wrapper
+    * @param message the message
+    * @param session the session
+    */
+   public JBMMessage(Message message, JBMSession session)
+   {
+      if (trace)
+         log.trace("constructor(" + message + ", " + session + ")");
+
+      this.message = message;
+      this.session = session;
+   }
+
+   /**
+    * Acknowledge
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void acknowledge() throws JMSException
+   {
+      if (trace)
+         log.trace("acknowledge()");
+
+      session.getSession(); // Check for closed
+      message.acknowledge();
+   }
+   
+   /**
+    * Clear body
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void clearBody() throws JMSException
+   {
+      if (trace)
+         log.trace("clearBody()");
+
+      message.clearBody();
+   }
+   
+   /**
+    * Clear properties
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void clearProperties() throws JMSException
+   {
+      if (trace)
+         log.trace("clearProperties()");
+
+      message.clearProperties();
+   }
+   
+   /**
+    * Get property
+    * @param name The name
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean getBooleanProperty(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getBooleanProperty(" + name + ")");
+
+      return message.getBooleanProperty(name);
+   }
+   
+   /**
+    * Get property
+    * @param name The name
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public byte getByteProperty(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getByteProperty(" + name + ")");
+
+      return message.getByteProperty(name);
+   }
+
+   /**
+    * Get property
+    * @param name The name
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public double getDoubleProperty(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getDoubleProperty(" + name + ")");
+
+      return message.getDoubleProperty(name);
+   }
+   
+   /**
+    * Get property
+    * @param name The name
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public float getFloatProperty(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getFloatProperty(" + name + ")");
+
+      return message.getFloatProperty(name);
+   }
+   
+   /**
+    * Get property
+    * @param name The name
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int getIntProperty(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getIntProperty(" + name + ")");
+
+      return message.getIntProperty(name);
+   }
+   
+   /**
+    * Get correlation id
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public String getJMSCorrelationID() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSCorrelationID()");
+
+      return message.getJMSCorrelationID();
+   }
+   
+   /**
+    * Get correlation id
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public byte[] getJMSCorrelationIDAsBytes() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSCorrelationIDAsBytes()");
+
+      return message.getJMSCorrelationIDAsBytes();
+   }
+   
+   /**
+    * Get delivery mode
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int getJMSDeliveryMode() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSDeliveryMode()");
+
+      return message.getJMSDeliveryMode();
+   }
+   
+   /**
+    * Get destination
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Destination getJMSDestination() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSDestination()");
+
+      return message.getJMSDestination();
+   }
+   
+   /**
+    * Get expiration
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public long getJMSExpiration() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSExpiration()");
+
+      return message.getJMSExpiration();
+   }
+   
+   /**
+    * Get message id
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public String getJMSMessageID() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSMessageID()");
+
+      return message.getJMSMessageID();
+   }
+   
+   /**
+    * Get priority
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int getJMSPriority() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSPriority()");
+
+      return message.getJMSPriority();
+   }
+   
+   /**
+    * Get redelivered status
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean getJMSRedelivered() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSRedelivered()");
+
+      return message.getJMSRedelivered();
+   }
+   
+   /**
+    * Get reply to destination
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Destination getJMSReplyTo() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSReplyTo()");
+
+      return message.getJMSReplyTo();
+   }
+   
+   /**
+    * Get timestamp
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public long getJMSTimestamp() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSTimestamp()");
+
+      return message.getJMSTimestamp();
+   }
+   
+   /**
+    * Get type
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public String getJMSType() throws JMSException
+   {
+      if (trace)
+         log.trace("getJMSType()");
+
+      return message.getJMSType();
+   }
+   
+   /**
+    * Get property
+    * @param name The name
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public long getLongProperty(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getLongProperty(" + name + ")");
+
+      return message.getLongProperty(name);
+   }
+   
+   /**
+    * Get property
+    * @param name The name
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Object getObjectProperty(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getObjectProperty(" + name + ")");
+
+      return message.getObjectProperty(name);
+   }
+   
+   /**
+    * Get property names
+    * @return The values
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Enumeration getPropertyNames() throws JMSException
+   {
+      if (trace)
+         log.trace("getPropertyNames()");
+
+      return message.getPropertyNames();
+   }
+   
+   /**
+    * Get property
+    * @param name The name
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public short getShortProperty(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getShortProperty(" + name + ")");
+
+      return message.getShortProperty(name);
+   }
+   
+   /**
+    * Get property
+    * @param name The name
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public String getStringProperty(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("getStringProperty(" + name + ")");
+
+      return message.getStringProperty(name);
+   }
+   
+   /**
+    * Do property exist
+    * @param name The name
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean propertyExists(String name) throws JMSException
+   {
+      if (trace)
+         log.trace("propertyExists(" + name + ")");
+
+      return message.propertyExists(name);
+   }
+   
+   /**
+    * Set property
+    * @param name The name
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setBooleanProperty(String name, boolean value) throws JMSException
+   {
+      if (trace)
+         log.trace("setBooleanProperty(" + name + ", " + value + ")");
+
+      message.setBooleanProperty(name, value);
+   }
+   
+   /**
+    * Set property
+    * @param name The name
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setByteProperty(String name, byte value) throws JMSException
+   {
+      if (trace)
+         log.trace("setByteProperty(" + name + ", " + value + ")");
+
+      message.setByteProperty(name, value);
+   }
+   
+   /**
+    * Set property
+    * @param name The name
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setDoubleProperty(String name, double value) throws JMSException
+   {
+      if (trace)
+         log.trace("setDoubleProperty(" + name + ", " + value + ")");
+
+      message.setDoubleProperty(name, value);
+   }
+   
+   /**
+    * Set property
+    * @param name The name
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setFloatProperty(String name, float value) throws JMSException
+   {
+      if (trace)
+         log.trace("setFloatProperty(" + name + ", " + value + ")");
+
+      message.setFloatProperty(name, value);
+   }
+   
+   /**
+    * Set property
+    * @param name The name
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setIntProperty(String name, int value) throws JMSException
+   {
+      if (trace)
+         log.trace("setIntProperty(" + name + ", " + value + ")");
+
+      message.setIntProperty(name, value);
+   }
+   
+   /**
+    * Set correlation id
+    * @param correlationID The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSCorrelationID(String correlationID) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSCorrelationID(" + correlationID + ")");
+
+      message.setJMSCorrelationID(correlationID);
+   }
+
+   /**
+    * Set correlation id
+    * @param correlationID The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSCorrelationIDAsBytes(" + correlationID + ")");
+
+      message.setJMSCorrelationIDAsBytes(correlationID);
+   }
+
+   /**
+    * Set delivery mode
+    * @param deliveryMode The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSDeliveryMode(int deliveryMode) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSDeliveryMode(" + deliveryMode + ")");
+
+      message.setJMSDeliveryMode(deliveryMode);
+   }
+
+   /**
+    * Set destination
+    * @param destination The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSDestination(Destination destination) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSDestination(" + destination + ")");
+
+      message.setJMSDestination(destination);
+   }
+   
+   /**
+    * Set expiration
+    * @param expiration The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSExpiration(long expiration) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSExpiration(" + expiration + ")");
+
+      message.setJMSExpiration(expiration);
+   }
+   
+   /**
+    * Set message id
+    * @param id The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSMessageID(String id) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSMessageID(" + id + ")");
+
+      message.setJMSMessageID(id);
+   }
+   
+   /**
+    * Set priority
+    * @param priority The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSPriority(int priority) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSPriority(" + priority + ")");
+
+      message.setJMSPriority(priority);
+   }
+   
+   /**
+    * Set redelivered status
+    * @param redelivered The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSRedelivered(boolean redelivered) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSRedelivered(" + redelivered + ")");
+
+      message.setJMSRedelivered(redelivered);
+   }
+
+   /**
+    * Set reply to
+    * @param replyTo The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSReplyTo(Destination replyTo) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSReplyTo(" + replyTo + ")");
+
+      message.setJMSReplyTo(replyTo);
+   }
+
+   /**
+    * Set timestamp
+    * @param timestamp The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSTimestamp(long timestamp) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSTimestamp(" + timestamp + ")");
+
+      message.setJMSTimestamp(timestamp);
+   }
+   
+   /**
+    * Set type
+    * @param type The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setJMSType(String type) throws JMSException
+   {
+      if (trace)
+         log.trace("setJMSType(" + type + ")");
+
+      message.setJMSType(type);
+   }
+   
+   /**
+    * Set property
+    * @param name The name
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setLongProperty(String name, long value) throws JMSException
+   {
+      if (trace)
+         log.trace("setLongProperty(" + name + ", " + value + ")");
+
+      message.setLongProperty(name, value);
+   }
+   
+   /**
+    * Set property
+    * @param name The name
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setObjectProperty(String name, Object value) throws JMSException
+   {
+      if (trace)
+         log.trace("setObjectProperty(" + name + ", " + value + ")");
+
+      message.setObjectProperty(name, value);
+   }
+   
+   /**
+    * Set property
+    * @param name The name
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setShortProperty(String name, short value) throws JMSException
+   {
+      if (trace)
+         log.trace("setShortProperty(" + name + ", " + value + ")");
+
+      message.setShortProperty(name, value);
+   }
+   
+   /**
+    * Set property
+    * @param name The name
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setStringProperty(String name, String value) throws JMSException
+   {
+      if (trace)
+         log.trace("setStringProperty(" + name + ", " + value + ")");
+
+      message.setStringProperty(name, value);
+   }
+   
+   /**
+    * Return the hash code
+    * @return The hash code
+    */
+   public int hashCode()
+   {
+      if (trace)
+         log.trace("hashCode()");
+
+      return message.hashCode();
+   }
+   
+   /**
+    * Check for equality
+    * @param object The other object
+    * @return True / false
+    */
+   public boolean equals(Object object)
+   {
+      if (trace)
+         log.trace("equals(" + object + ")");
+
+      if (object != null && object instanceof JBMMessage)
+         return message.equals(((JBMMessage) object).message);
+      else
+         return message.equals(object);
+   }
+   
+   /**
+    * Return string representation
+    * @return The string
+    */
+   public String toString()
+   {
+      if (trace)
+         log.trace("toString()");
+
+      return message.toString();
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMMessageConsumer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMMessageConsumer.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMMessageConsumer.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,289 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+import javax.jms.StreamMessage;
+import javax.jms.TextMessage;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A wrapper for a message consumer
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMMessageConsumer implements MessageConsumer
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMMessageConsumer.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The wrapped message consumer */
+   protected MessageConsumer consumer;
+   
+   /** The session for this consumer */
+   protected JBMSession session;
+
+   /**
+    * Create a new wrapper
+    * @param consumer the consumer
+    * @param session the session
+    */
+   public JBMMessageConsumer(MessageConsumer consumer, JBMSession session)
+   {
+      this.consumer = consumer;
+      this.session = session;
+      
+      if (trace)
+         log.trace("new JBMMessageConsumer " + this + " consumer=" + consumer + " session=" + session);
+   }
+
+   /**
+    * Close
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void close() throws JMSException
+   {
+      if (trace)
+         log.trace("close " + this);
+      try
+      {
+         closeConsumer();
+      }
+      finally
+      {
+         session.removeConsumer(this);
+      }
+   }
+
+   /**
+    * Check state
+    * @exception JMSException Thrown if an error occurs
+    */
+   void checkState() throws JMSException
+   {
+      if (trace)
+         log.trace("checkState()");
+   }
+   
+   /**
+    * Get message listener
+    * @return The listener
+    * @exception JMSException Thrown if an error occurs
+    */
+   public MessageListener getMessageListener() throws JMSException
+   {
+      if (trace)
+         log.trace("getMessageListener()");
+
+      checkState();
+      session.checkStrict();
+      return consumer.getMessageListener();
+   }
+   
+   /**
+    * Set message listener
+    * @param listener The listener
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setMessageListener(MessageListener listener) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         checkState();
+         session.checkStrict();
+         if (listener == null)
+            consumer.setMessageListener(null);
+         else
+            consumer.setMessageListener(wrapMessageListener(listener));
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Get message selector
+    * @return The selector
+    * @exception JMSException Thrown if an error occurs
+    */
+   public String getMessageSelector() throws JMSException
+   {
+      if (trace)
+         log.trace("getMessageSelector()");
+
+      checkState();
+      return consumer.getMessageSelector();
+   }
+   
+   /**
+    * Receive
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Message receive() throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("receive " + this);
+
+         checkState();
+         Message message = consumer.receive();
+
+         if (trace)
+            log.trace("received " + this + " result=" + message);
+
+         if (message == null)
+            return null;
+         else
+            return wrapMessage(message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Receive
+    * @param timeout The timeout value
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Message receive(long timeout) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("receive " + this + " timeout=" + timeout);
+
+         checkState();
+         Message message = consumer.receive(timeout);
+
+         if (trace)
+            log.trace("received " + this + " result=" + message);
+
+         if (message == null)
+            return null;
+         else
+            return wrapMessage(message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Receive
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Message receiveNoWait() throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("receiveNoWait " + this);
+
+         checkState();
+         Message message = consumer.receiveNoWait();
+
+         if (trace)
+            log.trace("received " + this + " result=" + message);
+
+         if (message == null)
+            return null;
+         else
+            return wrapMessage(message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+   
+   /**
+    * Close consumer
+    * @exception JMSException Thrown if an error occurs
+    */
+   void closeConsumer() throws JMSException
+   {
+      if (trace)
+         log.trace("closeConsumer()");
+
+      consumer.close();
+   }
+   
+   /**
+    * Wrap message
+    * @param message The message to be wrapped
+    * @return The wrapped message
+    */
+   Message wrapMessage(Message message)
+   {
+      if (trace)
+         log.trace("wrapMessage(" + message + ")");
+
+      if (message instanceof BytesMessage)
+         return new JBMBytesMessage((BytesMessage) message, session);
+      else if (message instanceof MapMessage)
+         return new JBMMapMessage((MapMessage) message, session);
+      else if (message instanceof ObjectMessage)
+         return new JBMObjectMessage((ObjectMessage) message, session);
+      else if (message instanceof StreamMessage)
+         return new JBMStreamMessage((StreamMessage) message, session);
+      else if (message instanceof TextMessage)
+         return new JBMTextMessage((TextMessage) message, session);
+      return new JBMMessage(message, session);
+   }
+   
+   /**
+    * Wrap message listener
+    * @param listener The listener to be wrapped
+    * @return The wrapped listener
+    */
+   MessageListener wrapMessageListener(MessageListener listener)
+   {
+      if (trace)
+         log.trace("getMessageSelector()");
+
+      return new JBMMessageListener(listener, this);
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMMessageListener.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMMessageListener.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMMessageListener.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A wrapper for a message listener
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMMessageListener implements MessageListener
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMMessageListener.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The message listener */
+   private MessageListener listener;
+   
+   /** The consumer */
+   private JBMMessageConsumer consumer;
+
+   /**
+    * Create a new wrapper
+    * @param listener the listener
+    * @param consumer the consumer
+    */
+   public JBMMessageListener(MessageListener listener, JBMMessageConsumer consumer)
+   {
+      if (trace)
+         log.trace("constructor(" + listener + ", " + consumer + ")");
+
+      this.listener = listener;
+      this.consumer = consumer;
+   }
+
+   /**
+    * On message
+    * @param message The message
+    */
+   public void onMessage(Message message)
+   {
+      if (trace)
+         log.trace("onMessage(" + message + ")");
+
+      message = consumer.wrapMessage(message);
+      listener.onMessage(message);
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMMessageProducer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMMessageProducer.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMMessageProducer.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,355 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * JBMMessageProducer.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision:  $
+ */
+public class JBMMessageProducer implements MessageProducer
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMMessageProducer.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The wrapped message producer */
+   protected MessageProducer producer;
+   
+   /** The session for this consumer */
+   protected JBMSession session;
+
+   /**
+    * Create a new wrapper
+    * @param producer the producer
+    * @param session the session
+    */
+   public JBMMessageProducer(MessageProducer producer, JBMSession session)
+   {
+      this.producer = producer;
+      this.session = session;
+      
+      if (trace)
+         log.trace("new JBMMessageProducer " + this + " producer=" + producer + " session=" + session);
+   }
+
+   /**
+    * Close
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void close() throws JMSException
+   {
+      if (trace)
+         log.trace("close " + this);
+      try
+      {
+         closeProducer();
+      }
+      finally
+      {
+         session.removeProducer(this);
+      }
+   }
+
+   /**
+    * Send message
+    * @param destination The destination
+    * @param message The message
+    * @param deliveryMode The delivery mode
+    * @param priority The priority
+    * @param timeToLive The time to live
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("send " + this + " destination=" + destination + " message=" + message + " deliveryMode=" + deliveryMode + " priority=" + priority + " ttl=" + timeToLive);
+
+         checkState();
+
+         producer.send(destination, message, deliveryMode, priority, timeToLive);
+
+         if (trace)
+            log.trace("sent " + this + " result=" + message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Send message
+    * @param destination The destination
+    * @param message The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void send(Destination destination, Message message) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("send " + this + " destination=" + destination + " message=" + message);
+
+         checkState();
+
+         producer.send(destination, message);
+
+         if (trace)
+            log.trace("sent " + this + " result=" + message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Send message
+    * @param message The message
+    * @param deliveryMode The delivery mode
+    * @param priority The priority
+    * @param timeToLive The time to live
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("send " + this + " message=" + message + " deliveryMode=" + deliveryMode + " priority=" + priority + " ttl=" + timeToLive);
+
+         checkState();
+
+         producer.send(message, deliveryMode, priority, timeToLive);
+
+         if (trace)
+            log.trace("sent " + this + " result=" + message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Send message
+    * @param message The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void send(Message message) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("send " + this + " message=" + message);
+
+         checkState();
+
+         producer.send(message);
+
+         if (trace)
+            log.trace("sent " + this + " result=" + message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Get the delivery mode
+    * @return The mode
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int getDeliveryMode() throws JMSException
+   {
+      if (trace)
+         log.trace("getDeliveryMode()");
+
+      return producer.getDeliveryMode();
+   }
+
+   /**
+    * Get the destination
+    * @return The destination
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Destination getDestination() throws JMSException
+   {
+      if (trace)
+         log.trace("getDestination()");
+
+      return producer.getDestination();
+   }
+
+   /**
+    * Disable message id
+    * @return True if disable
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean getDisableMessageID() throws JMSException
+   {
+      if (trace)
+         log.trace("getDisableMessageID()");
+
+      return producer.getDisableMessageID();
+   }
+
+   /**
+    * Disable message timestamp
+    * @return True if disable
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean getDisableMessageTimestamp() throws JMSException
+   {
+      if (trace)
+         log.trace("getDisableMessageTimestamp()");
+
+      return producer.getDisableMessageTimestamp();
+   }
+
+   /**
+    * Get the priority
+    * @return The priority
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int getPriority() throws JMSException
+   {
+      if (trace)
+         log.trace("getPriority()");
+
+      return producer.getPriority();
+   }
+
+   /**
+    * Get the time to live
+    * @return The ttl
+    * @exception JMSException Thrown if an error occurs
+    */
+   public long getTimeToLive() throws JMSException
+   {
+      if (trace)
+         log.trace("getTimeToLive()");
+
+      return producer.getTimeToLive();
+   }
+
+   /**
+    * Set the delivery mode
+    * @param deliveryMode The mode
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setDeliveryMode(int deliveryMode) throws JMSException
+   {
+      if (trace)
+         log.trace("setDeliveryMode(" + deliveryMode + ")");
+
+      producer.setDeliveryMode(deliveryMode);
+   }
+
+   /**
+    * Set disable message id
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setDisableMessageID(boolean value) throws JMSException
+   {
+      if (trace)
+         log.trace("setDisableMessageID(" + value + ")");
+
+      producer.setDisableMessageID(value);
+   }
+
+   /**
+    * Set disable message timestamp
+    * @param value The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setDisableMessageTimestamp(boolean value) throws JMSException
+   {
+      if (trace)
+         log.trace("setDisableMessageTimestamp(" + value + ")");
+
+      producer.setDisableMessageTimestamp(value);
+   }
+
+   /**
+    * Set the priority
+    * @param defaultPriority The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setPriority(int defaultPriority) throws JMSException
+   {
+      if (trace)
+         log.trace("setPriority(" + defaultPriority + ")");
+
+      producer.setPriority(defaultPriority);
+   }
+
+   /**
+    * Set the ttl
+    * @param timeToLive The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setTimeToLive(long timeToLive) throws JMSException
+   {
+      if (trace)
+         log.trace("setTimeToLive(" + timeToLive + ")");
+
+      producer.setTimeToLive(timeToLive);
+   }
+
+   /**
+    * Check state
+    * @exception JMSException Thrown if an error occurs
+    */
+   void checkState() throws JMSException
+   {
+   }
+
+   /**
+    * Close producer
+    * @exception JMSException Thrown if an error occurs
+    */
+   void closeProducer() throws JMSException
+   {
+      producer.close();
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMMetaData.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMMetaData.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMMetaData.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ManagedConnectionMetaData;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * Managed connection meta data
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision:  $
+ */
+public class JBMMetaData implements ManagedConnectionMetaData
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMMetaData.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The managed connection */
+   private JBMManagedConnection mc;
+   
+   /**
+    * Constructor
+    * @param mc The managed connection
+    */
+   public JBMMetaData(JBMManagedConnection mc) {
+      if (trace)
+         log.trace("constructor(" + mc + ")");
+
+      this.mc = mc;
+   }
+   
+   /**
+    * Get the EIS product name
+    * @return The name
+    * @exception ResourceException Thrown if operation fails
+    */
+   public String getEISProductName() throws ResourceException {
+      if (trace)
+         log.trace("getEISProductName()");
+      
+      return "JBoss Messaging";
+   }
+
+   /**
+    * Get the EIS product version
+    * @return The version
+    * @exception ResourceException Thrown if operation fails
+    */
+   public String getEISProductVersion() throws ResourceException {
+      if (trace)
+         log.trace("getEISProductVersion()");
+
+      return "2.0";
+   }
+
+   /**
+    * Get the maximum number of connections -- RETURNS 0
+    * @return The number
+    * @exception ResourceException Thrown if operation fails
+    */
+   public int getMaxConnections() throws ResourceException {
+      if (trace)
+         log.trace("getMaxConnections()");
+
+      return 0;
+   }
+    
+   /**
+    * Get the user name
+    * @return The user name
+    * @exception ResourceException Thrown if operation fails
+    */
+   public String getUserName() throws ResourceException {
+      if (trace)
+         log.trace("getUserName()");
+
+      return mc.getUserName();
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMObjectMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMObjectMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMObjectMessage.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.ObjectMessage;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A wrapper for a message
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMObjectMessage extends JBMMessage implements ObjectMessage
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMObjectMessage.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**
+    * Create a new wrapper
+    * @param message the message
+    * @param session the session
+    */
+   public JBMObjectMessage(ObjectMessage message, JBMSession session)
+   {
+      super(message, session);
+
+      if (trace)
+         log.trace("constructor(" + message + ", " + session + ")");
+   }
+
+   /**
+    * Get the object
+    * @return The object
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Serializable getObject() throws JMSException
+   {
+      if (trace)
+         log.trace("getObject()");
+
+      return ((ObjectMessage) message).getObject();
+   }
+   
+   /**
+    * Set the object
+    * @param object The object
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setObject(Serializable object) throws JMSException
+   {
+      if (trace)
+         log.trace("setObject(" + object + ")");
+
+      ((ObjectMessage) message).setObject(object);
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMQueueReceiver.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMQueueReceiver.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMQueueReceiver.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueReceiver;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A wrapper for a queue receiver
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMQueueReceiver extends JBMMessageConsumer implements QueueReceiver
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMQueueReceiver.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**
+    * Create a new wrapper
+    * @param consumer the queue receiver
+    * @param session the session
+    */
+   public JBMQueueReceiver(QueueReceiver consumer, JBMSession session)
+   {
+      super(consumer, session);
+
+      if (trace)
+         log.trace("constructor(" + consumer + ", " + session + ")");
+   }
+
+   /**
+    * Get queue
+    * @return The queue
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Queue getQueue() throws JMSException
+   {
+      if (trace)
+         log.trace("getQueue()");
+
+      checkState();
+      return ((QueueReceiver) consumer).getQueue();
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMQueueSender.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMQueueSender.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMQueueSender.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.QueueSender;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * JBMQueueSender.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMQueueSender extends JBMMessageProducer implements QueueSender
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMQueueSender.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**
+    * Create a new wrapper
+    * @param producer the producer
+    * @param session the session
+    */
+   public JBMQueueSender(QueueSender producer, JBMSession session)
+   {
+      super(producer, session);
+
+      if (trace)
+         log.trace("constructor(" + producer + ", " + session + ")");
+   }
+
+   /**
+    * Get queue
+    * @return The queue
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Queue getQueue() throws JMSException
+   {
+      if (trace)
+         log.trace("getQueue()");
+
+      return ((QueueSender) producer).getQueue();
+   }
+
+   /**
+    * Send message
+    * @param destination The destination
+    * @param message The message
+    * @param deliveryMode The delivery mode
+    * @param priority The priority
+    * @param timeToLive The time to live
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void send(Queue destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("send " + this + " destination=" + destination + " message=" + message + " deliveryMode=" + deliveryMode + " priority=" + priority + " ttl=" + timeToLive);
+
+         checkState();
+         producer.send(destination, message, deliveryMode, priority, timeToLive);
+
+         if (trace)
+            log.trace("sent " + this + " result=" + message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Send message
+    * @param destination The destination
+    * @param message The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void send(Queue destination, Message message) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("send " + this + " destination=" + destination + " message=" + message);
+
+         checkState();
+         producer.send(destination, message);
+
+         if (trace)
+            log.trace("sent " + this + " result=" + message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.resource.NotSupportedException;
+import javax.resource.ResourceException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * The resource adapter for JBoss Messaging
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMResourceAdapter implements ResourceAdapter
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMResourceAdapter.class);
+
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** Hash code */
+   private static final int HASH_CODE = 0x42;
+
+   /** The bootstrap context */
+   private BootstrapContext ctx;
+
+   /**
+    * Constructor
+    */
+   public JBMResourceAdapter()
+   {
+      if (trace)
+         log.trace("constructor()");
+   }
+
+   public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) throws ResourceException
+   {
+      if (trace)
+         log.trace("endpointActivation(" + endpointFactory + ", " + spec + ")");
+
+      throw new NotSupportedException("Unsupported");
+   }
+
+   public void endpointDeactivation(MessageEndpointFactory endpointFactory, ActivationSpec spec)
+   {
+      if (trace)
+         log.trace("endpointDeactivation(" + endpointFactory + ", " + spec + ")");
+   }
+   
+   public XAResource[] getXAResources(ActivationSpec[] specs) throws ResourceException
+   {
+      if (trace)
+         log.trace("getXAResources(" + specs + ")");
+
+      throw new ResourceException("Unsupported");
+   }
+   
+   public void start(BootstrapContext ctx) throws ResourceAdapterInternalException
+   {
+      if (trace)
+         log.trace("start(" + ctx + ")");
+
+      this.ctx = ctx;
+
+      log.info("JBoss Messaging resource adapter started");
+   }
+
+   public void stop()
+   {
+      if (trace)
+         log.trace("stop()");
+
+      log.info("JBoss Messaging resource adapter stopped");
+   }
+
+   /**
+    * Indicates whether some other object is "equal to" this one.
+    * @param obj Object with which to compare
+    * @return True if this object is the same as the obj argument; false otherwise.
+    */
+   public boolean equals(Object obj) {
+      if (trace)
+         log.trace("equals(" + obj + ")");
+
+      if (!(obj instanceof JBMResourceAdapter)) {
+         return false;
+      }
+
+      return true;
+   }
+   
+   /**
+    * Return the hash code for the object
+    * @return The hash code
+    */
+   public int hashCode() {
+      if (trace)
+         log.trace("hashCode()");
+
+      return HASH_CODE;
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMSession.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMSession.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMSession.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,1418 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.jms.BytesMessage;
+import javax.jms.Destination;
+import javax.jms.IllegalStateException;
+import javax.jms.InvalidDestinationException;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.StreamMessage;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.jms.TransactionInProgressException;
+import javax.jms.XAQueueSession;
+import javax.jms.XASession;
+import javax.jms.XATopicSession;
+import javax.resource.spi.ConnectionEvent;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A joint interface for JMS sessions
+ * 
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMSession implements Session, QueueSession, TopicSession, XASession, XAQueueSession, XATopicSession
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMSession.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The managed connection */
+   private JBMManagedConnection mc;
+
+   /** The connection request info */
+   private JBMConnectionRequestInfo cri;
+
+   /** The session factory */
+   private JBMSessionFactory sf;
+   
+   /** The message consumers */
+   private Set consumers;
+   
+   /** The message producers */
+   private Set producers;
+   
+   /**
+    * Constructor
+    * @param mc The managed connection
+    * @param cri The connection request info
+    */
+   public JBMSession(JBMManagedConnection mc, JBMConnectionRequestInfo cri)
+   {
+      if (trace)
+         log.trace("constructor(" + mc + ", " + cri + ")");
+
+      this.mc = mc;
+      this.cri = cri;
+      this.sf = null;
+      this.consumers = new HashSet();
+      this.producers = new HashSet();
+   }
+
+   /**
+    * Set the session factory
+    * @param sf The session factory
+    */
+   public void setJBMSessionFactory(JBMSessionFactory sf)
+   {
+      if (trace)
+         log.trace("setJBMSessionFactory(" + sf + ")");
+
+      this.sf = sf;
+   }
+
+   /**
+    * Lock
+    * @exception JMSException Thrown if an error occurs
+    * @exception IllegalStateException The session is closed
+    */
+   protected void lock() throws JMSException
+   {
+      if (trace)
+         log.trace("lock()");
+
+      JBMManagedConnection mc = this.mc;
+      if (mc != null)
+         mc.tryLock();
+      else
+         throw new IllegalStateException("Connection is not associated with a managed connection. " + this);
+   }
+
+   /**
+    * Unlock
+    */
+   protected void unlock()
+   {
+      if (trace)
+         log.trace("unlock()");
+
+      JBMManagedConnection mc = this.mc;
+      if (mc != null)
+         mc.unlock();
+
+      // We recreate the lock when returned to the pool
+      // so missing the unlock after disassociation is not important
+   }
+   
+   /**
+    * Create a bytes message
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public BytesMessage createBytesMessage() throws JMSException
+   {
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createBytesMessage" + session);
+
+      return session.createBytesMessage();
+   }
+
+   /**
+    * Create a map message
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public MapMessage createMapMessage() throws JMSException
+   {
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createMapMessage" + session);
+
+      return session.createMapMessage();
+   }
+
+   /**
+    * Create a message
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Message createMessage() throws JMSException
+   {
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createMessage" + session);
+
+      return session.createMessage();
+   }
+
+   /**
+    * Create an object message
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public ObjectMessage createObjectMessage() throws JMSException
+   {
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createObjectMessage" + session);
+
+      return session.createObjectMessage();
+   }
+
+   /**
+    * Create an object message
+    * @param object The object
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public ObjectMessage createObjectMessage(Serializable object) throws JMSException
+   {
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createObjectMessage(" + object + ")" + session);
+
+      return session.createObjectMessage(object);
+   }
+
+   /**
+    * Create a stream message
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public StreamMessage createStreamMessage() throws JMSException
+   {
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createStreamMessage" + session);
+
+      return session.createStreamMessage();
+   }
+
+   /**
+    * Create a text message
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TextMessage createTextMessage() throws JMSException
+   {
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createTextMessage" + session);
+
+      return session.createTextMessage();
+   }
+
+   /**
+    * Create a text message
+    * @param string The text
+    * @return The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TextMessage createTextMessage(String string) throws JMSException
+   {
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createTextMessage(" + string + ")" + session);
+
+      return session.createTextMessage(string);
+   }
+
+   /**
+    * Get transacted
+    * @return True if transacted; otherwise false
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean getTransacted() throws JMSException
+   {
+      if (trace)
+         log.trace("getTransacted()");
+
+      getSessionInternal();
+      return cri.isTransacted();
+   }
+
+   /**
+    * Get the message listener -- throws IllegalStateException
+    * @return The message listener
+    * @exception JMSException Thrown if an error occurs
+    */
+   public MessageListener getMessageListener() throws JMSException
+   {
+      if (trace)
+         log.trace("getMessageListener()");
+
+      throw new IllegalStateException("Method not allowed");
+   }
+
+   /**
+    * Set the message listener -- Throws IllegalStateException
+    * @param listener The message listener
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setMessageListener(MessageListener listener) throws JMSException
+   {
+      if (trace)
+         log.trace("setMessageListener(" + listener + ")");
+
+      throw new IllegalStateException("Method not allowed");
+   }
+
+   /**
+    * Always throws an Error.
+    * @exception Error Method not allowed.
+    */
+   public void run()
+   {
+      if (trace)
+         log.trace("run()");
+
+      throw new Error("Method not allowed");
+   }
+
+   /**
+    * Closes the session. Sends a ConnectionEvent.CONNECTION_CLOSED to the
+    * managed connection.
+    * @exception JMSException Failed to close session.
+    */
+   public void close() throws JMSException
+   {
+      if (trace)
+         log.trace("close()");
+
+      sf.closeSession(this);
+      closeSession();
+   }
+
+   /**
+    * Commit
+    * @exception JMSException Failed to close session.
+    */
+   public void commit() throws JMSException
+   {
+      if (cri.getType() == JBMConnectionFactory.XA_CONNECTION ||
+          cri.getType() == JBMConnectionFactory.XA_QUEUE_CONNECTION ||
+          cri.getType() == JBMConnectionFactory.XA_TOPIC_CONNECTION)
+      {
+         throw new TransactionInProgressException("XA connection");
+      }
+
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (cri.isTransacted() == false)
+            throw new IllegalStateException("Session is not transacted");
+
+         if (trace)
+            log.trace("Commit session " + this);
+
+         session.commit();
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Rollback
+    * @exception JMSException Failed to close session.
+    */
+   public void rollback() throws JMSException
+   {
+      if (cri.getType() == JBMConnectionFactory.XA_CONNECTION ||
+          cri.getType() == JBMConnectionFactory.XA_QUEUE_CONNECTION ||
+          cri.getType() == JBMConnectionFactory.XA_TOPIC_CONNECTION)
+      {
+         throw new TransactionInProgressException("XA connection");
+      }
+
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (cri.isTransacted() == false)
+            throw new IllegalStateException("Session is not transacted");
+
+         if (trace)
+            log.trace("Rollback session " + this);
+
+         session.rollback();
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Recover
+    * @exception JMSException Failed to close session.
+    */
+   public void recover() throws JMSException
+   {
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (cri.isTransacted())
+            throw new IllegalStateException("Session is transacted");
+
+         if (trace)
+            log.trace("Recover session " + this);
+
+         session.recover();
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a topic
+    * @param topicName The topic name
+    * @return The topic
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Topic createTopic(String topicName) throws JMSException
+   {
+      if (cri.getType() == JBMConnectionFactory.QUEUE_CONNECTION || cri.getType() == JBMConnectionFactory.XA_QUEUE_CONNECTION)
+      {
+         throw new IllegalStateException("Cannot create topic for javax.jms.QueueSession");         
+      }
+
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createTopic " + session + " topicName=" + topicName);
+
+      Topic result = session.createTopic(topicName);
+
+      if (trace)
+         log.trace("createdTopic " + session + " topic=" + result);
+
+      return result;
+   }
+
+   /**
+    * Create a topic subscriber
+    * @param topic The topic
+    * @return The subscriber
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TopicSubscriber createSubscriber(Topic topic) throws JMSException
+   {
+      lock();
+      try
+      {
+         TopicSession session = getTopicSessionInternal();
+
+         if (trace)
+            log.trace("createSubscriber " + session + " topic=" + topic);
+
+         TopicSubscriber result = session.createSubscriber(topic);
+         result = new JBMTopicSubscriber(result, this);
+
+         if (trace)
+            log.trace("createdSubscriber " + session + " JBMTopicSubscriber=" + result);
+
+         addConsumer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a topic subscriber
+    * @param topic The topic
+    * @param messageSelector The message selector
+    * @param noLocal If true inhibits the delivery of messages published by its own connection 
+    * @return The subscriber
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TopicSubscriber createSubscriber(Topic topic, String messageSelector, boolean noLocal) throws JMSException
+   {
+      lock();
+      try
+      {
+         TopicSession session = getTopicSessionInternal();
+
+         if (trace)
+            log.trace("createSubscriber " + session + " topic=" + topic + " selector=" + messageSelector + " noLocal=" + noLocal);
+
+         TopicSubscriber result = session.createSubscriber(topic, messageSelector, noLocal);
+         result = new JBMTopicSubscriber(result, this);
+
+         if (trace)
+            log.trace("createdSubscriber " + session + " JBMTopicSubscriber=" + result);
+
+         addConsumer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a durable topic subscriber
+    * @param topic The topic
+    * @param name The name
+    * @return The subscriber
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException
+   {
+      if (cri.getType() == JBMConnectionFactory.QUEUE_CONNECTION || cri.getType() == JBMConnectionFactory.XA_QUEUE_CONNECTION)
+      {
+         throw new IllegalStateException("Cannot create durable subscriber from javax.jms.QueueSession");         
+      }
+      
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (trace)
+            log.trace("createDurableSubscriber " + session + " topic=" + topic + " name=" + name);
+
+         TopicSubscriber result = session.createDurableSubscriber(topic, name);
+         result = new JBMTopicSubscriber(result, this);
+
+         if (trace)
+            log.trace("createdDurableSubscriber " + session + " JBMTopicSubscriber=" + result);
+
+         addConsumer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a topic subscriber
+    * @param topic The topic
+    * @param name The name
+    * @param messageSelector The message selector
+    * @param noLocal If true inhibits the delivery of messages published by its own connection 
+    * @return The subscriber
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException
+   {
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (trace)
+            log.trace("createDurableSubscriber " + session + " topic=" + topic + " name=" + name + " selector=" + messageSelector + " noLocal=" + noLocal);
+
+         TopicSubscriber result = session.createDurableSubscriber(topic, name, messageSelector, noLocal);
+         result = new JBMTopicSubscriber(result, this);
+
+         if (trace)
+            log.trace("createdDurableSubscriber " + session + " JBMTopicSubscriber=" + result);
+
+         addConsumer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a topic publisher
+    * @param topic The topic
+    * @return The publisher
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TopicPublisher createPublisher(Topic topic) throws JMSException
+   {
+      lock();
+      try
+      {
+         TopicSession session = getTopicSessionInternal();
+
+         if (trace)
+            log.trace("createPublisher " + session + " topic=" + topic);
+
+         TopicPublisher result = session.createPublisher(topic);
+         result = new JBMTopicPublisher(result, this);
+
+         if (trace)
+            log.trace("createdPublisher " + session + " publisher=" + result);
+
+         addProducer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a temporary topic
+    * @return The temporary topic
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TemporaryTopic createTemporaryTopic() throws JMSException
+   {
+      if (cri.getType() == JBMConnectionFactory.QUEUE_CONNECTION || cri.getType() == JBMConnectionFactory.XA_QUEUE_CONNECTION)
+      {
+         throw new IllegalStateException("Cannot create temporary topic for javax.jms.QueueSession");         
+      }
+      
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (trace)
+            log.trace("createTemporaryTopic " + session);
+
+         TemporaryTopic temp = session.createTemporaryTopic();
+
+         if (trace)
+            log.trace("createdTemporaryTopic " + session + " temp=" + temp);
+
+         sf.addTemporaryTopic(temp);
+
+         return temp;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Unsubscribe
+    * @param name The name
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void unsubscribe(String name) throws JMSException
+   {
+      if (cri.getType() == JBMConnectionFactory.QUEUE_CONNECTION || cri.getType() == JBMConnectionFactory.XA_QUEUE_CONNECTION)
+      {
+         throw new IllegalStateException("Cannot unsubscribe for javax.jms.QueueSession");         
+      }
+
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (trace)
+            log.trace("unsubscribe " + session + " name=" + name);
+
+         session.unsubscribe(name);
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a browser
+    * @param queue The queue
+    * @return The browser
+    * @exception JMSException Thrown if an error occurs
+    */
+   public QueueBrowser createBrowser(Queue queue) throws JMSException
+   {
+      if (cri.getType() == JBMConnectionFactory.TOPIC_CONNECTION || cri.getType() == JBMConnectionFactory.XA_TOPIC_CONNECTION)
+      {
+         throw new IllegalStateException("Cannot create browser for javax.jms.TopicSession");
+      }
+
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createBrowser " + session + " queue=" + queue);
+
+      QueueBrowser result = session.createBrowser(queue);
+
+      if (trace)
+         log.trace("createdBrowser " + session + " browser=" + result);
+
+      return result;
+   }
+
+   /**
+    * Create a browser
+    * @param queue The queue
+    * @param messageSelector The message selector
+    * @return The browser
+    * @exception JMSException Thrown if an error occurs
+    */
+   public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException
+   {
+      if (cri.getType() == JBMConnectionFactory.TOPIC_CONNECTION || cri.getType() == JBMConnectionFactory.XA_TOPIC_CONNECTION)
+      {
+         throw new IllegalStateException("Cannot create browser for javax.jms.TopicSession");
+      }
+
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createBrowser " + session + " queue=" + queue + " selector=" + messageSelector);
+
+      QueueBrowser result = session.createBrowser(queue, messageSelector);
+
+      if (trace)
+         log.trace("createdBrowser " + session + " browser=" + result);
+
+      return result;
+   }
+
+   /**
+    * Create a queue
+    * @param queueName The queue name
+    * @return The queue
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Queue createQueue(String queueName) throws JMSException
+   {
+      if (cri.getType() == JBMConnectionFactory.TOPIC_CONNECTION || cri.getType() == JBMConnectionFactory.XA_TOPIC_CONNECTION)
+      {
+         throw new IllegalStateException("Cannot create browser or javax.jms.TopicSession");
+      }
+
+      Session session = getSessionInternal();
+
+      if (trace)
+         log.trace("createQueue " + session + " queueName=" + queueName);
+
+      Queue result = session.createQueue(queueName);
+
+      if (trace)
+         log.trace("createdQueue " + session + " queue=" + result);
+
+      return result;
+   }
+
+   /**
+    * Create a queue receiver
+    * @param queue The queue
+    * @return The queue receiver
+    * @exception JMSException Thrown if an error occurs
+    */
+   public QueueReceiver createReceiver(Queue queue) throws JMSException
+   {
+      lock();
+      try
+      {
+         QueueSession session = getQueueSessionInternal();
+
+         if (trace)
+            log.trace("createReceiver " + session + " queue=" + queue);
+
+         QueueReceiver result = session.createReceiver(queue);
+         result = new JBMQueueReceiver(result, this);
+
+         if (trace)
+            log.trace("createdReceiver " + session + " receiver=" + result);
+
+         addConsumer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a queue receiver
+    * @param queue The queue
+    * @param messageSelector
+    * @return The queue receiver
+    * @exception JMSException Thrown if an error occurs
+    */
+   public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException
+   {
+      lock();
+      try
+      {
+         QueueSession session = getQueueSessionInternal();
+
+         if (trace)
+            log.trace("createReceiver " + session + " queue=" + queue + " selector=" + messageSelector);
+
+         QueueReceiver result = session.createReceiver(queue, messageSelector);
+         result = new JBMQueueReceiver(result, this);
+
+         if (trace)
+            log.trace("createdReceiver " + session + " receiver=" + result);
+
+         addConsumer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a queue sender
+    * @param queue The queue
+    * @return The queue sender
+    * @exception JMSException Thrown if an error occurs
+    */
+   public QueueSender createSender(Queue queue) throws JMSException
+   {
+      lock();
+      try
+      {
+         QueueSession session = getQueueSessionInternal();
+
+         if (trace)
+            log.trace("createSender " + session + " queue=" + queue);
+
+         QueueSender result = session.createSender(queue);
+         result = new JBMQueueSender(result, this);
+
+         if (trace)
+            log.trace("createdSender " + session + " sender=" + result);
+
+         addProducer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a temporary queue
+    * @return The temporary queue
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TemporaryQueue createTemporaryQueue() throws JMSException
+   {
+      if (cri.getType() == JBMConnectionFactory.TOPIC_CONNECTION || cri.getType() == JBMConnectionFactory.XA_TOPIC_CONNECTION)
+      {
+         throw new IllegalStateException("Cannot create temporary queue for javax.jms.TopicSession");
+      }
+
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (trace)
+            log.trace("createTemporaryQueue " + session);
+
+         TemporaryQueue temp = session.createTemporaryQueue();
+
+         if (trace)
+            log.trace("createdTemporaryQueue " + session + " temp=" + temp);
+
+         sf.addTemporaryQueue(temp);
+
+         return temp;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a message consumer
+    * @param destination The destination
+    * @return The message consumer
+    * @exception JMSException Thrown if an error occurs
+    */
+   public MessageConsumer createConsumer(Destination destination) throws JMSException
+   {
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (trace)
+            log.trace("createConsumer " + session + " dest=" + destination);
+
+         MessageConsumer result = session.createConsumer(destination);
+         result = new JBMMessageConsumer(result, this);
+
+         if (trace)
+            log.trace("createdConsumer " + session + " consumer=" + result);
+
+         addConsumer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a message consumer
+    * @param destination The destination
+    * @param messageSelector The message selector
+    * @return The message consumer
+    * @exception JMSException Thrown if an error occurs
+    */
+   public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException
+   {
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (trace)
+            log.trace("createConsumer " + session + " dest=" + destination + " messageSelector=" + messageSelector);
+
+         MessageConsumer result = session.createConsumer(destination, messageSelector);
+         result = new JBMMessageConsumer(result, this);
+
+         if (trace)
+            log.trace("createdConsumer " + session + " consumer=" + result);
+
+         addConsumer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a message consumer
+    * @param destination The destination
+    * @param messageSelector The message selector
+    * @param noLocal If true inhibits the delivery of messages published by its own connection 
+    * @return The message consumer
+    * @exception JMSException Thrown if an error occurs
+    */
+   public MessageConsumer createConsumer(Destination destination, String messageSelector, boolean noLocal) throws JMSException
+   {
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (trace)
+            log.trace("createConsumer " + session + " dest=" + destination + " messageSelector=" + messageSelector + " noLocal=" + noLocal);
+
+         MessageConsumer result = session.createConsumer(destination, messageSelector, noLocal);
+         result = new JBMMessageConsumer(result, this);
+
+         if (trace)
+            log.trace("createdConsumer " + session + " consumer=" + result);
+
+         addConsumer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Create a message producer
+    * @param destination The destination
+    * @return The message producer
+    * @exception JMSException Thrown if an error occurs
+    */
+   public MessageProducer createProducer(Destination destination) throws JMSException
+   {
+      lock();
+      try
+      {
+         Session session = getSessionInternal();
+
+         if (trace)
+            log.trace("createProducer " + session + " dest=" + destination);
+
+         MessageProducer result = session.createProducer(destination);
+         result = new JBMMessageProducer(result, this);
+
+         if (trace)
+            log.trace("createdProducer " + session + " producer=" + result);
+
+         addProducer(result);
+
+         return result;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Get the acknowledge mode
+    * @return The mode
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int getAcknowledgeMode() throws JMSException
+   {
+      if (trace)
+         log.trace("getAcknowledgeMode()");
+
+      getSessionInternal();
+      return cri.getAcknowledgeMode();
+   }
+
+   /**
+    * Get the XA resource
+    * @return The XA resource
+    * @exception IllegalStateException If non XA connection
+    */
+   public XAResource getXAResource()
+   {
+      if (trace)
+         log.trace("getXAResource()");
+
+      if (cri.getType() == JBMConnectionFactory.CONNECTION ||
+          cri.getType() == JBMConnectionFactory.QUEUE_CONNECTION ||
+          cri.getType() == JBMConnectionFactory.TOPIC_CONNECTION)
+      {
+         return null;
+      }
+
+      try
+      {
+         lock();
+
+         XASession session = getXASessionInternal();
+
+         return session.getXAResource();
+      }
+      catch (Throwable t)
+      {
+         return null;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Get the session
+    * @return The session
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Session getSession() throws JMSException
+   {
+      if (trace)
+         log.trace("getSession()");
+
+      if (cri.getType() == JBMConnectionFactory.CONNECTION ||
+          cri.getType() == JBMConnectionFactory.QUEUE_CONNECTION ||
+          cri.getType() == JBMConnectionFactory.TOPIC_CONNECTION)
+      {
+         throw new IllegalStateException("Non XA connection");
+      }
+
+      lock();
+      try
+      {
+         return this;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Get the queue session
+    * @return The queue session
+    * @exception JMSException Thrown if an error occurs
+    */
+   public QueueSession getQueueSession() throws JMSException
+   {
+      if (trace)
+         log.trace("getQueueSession()");
+
+      if (cri.getType() == JBMConnectionFactory.CONNECTION ||
+          cri.getType() == JBMConnectionFactory.QUEUE_CONNECTION ||
+          cri.getType() == JBMConnectionFactory.TOPIC_CONNECTION)
+      {
+         throw new IllegalStateException("Non XA connection");
+      }
+
+      lock();
+      try
+      {
+         return this;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Get the topic session
+    * @return The topic session
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TopicSession getTopicSession() throws JMSException
+   {
+      if (trace)
+         log.trace("getTopicSession()");
+
+      if (cri.getType() == JBMConnectionFactory.CONNECTION ||
+          cri.getType() == JBMConnectionFactory.QUEUE_CONNECTION ||
+          cri.getType() == JBMConnectionFactory.TOPIC_CONNECTION)
+      {
+         throw new IllegalStateException("Non XA connection");
+      }
+
+      lock();
+      try
+      {
+         return this;
+      }
+      finally
+      {
+         unlock();
+      }
+   }
+
+   /**
+    * Set the managed connection
+    * @param managedConnection The managed connection
+    */
+   void setManagedConnection(JBMManagedConnection managedConnection)
+   {
+      if (trace)
+         log.trace("setManagedConnection(" + managedConnection + ")");
+
+      if (mc != null)
+         mc.removeHandle(this);
+
+      this.mc = managedConnection;
+   }
+
+   /**
+    * Destroy
+    */
+   void destroy()
+   {
+      if (trace)
+         log.trace("destroy()");
+
+      mc = null;
+   }
+
+   /**
+    * Start
+    * @exception JMSException Thrown if an error occurs
+    */
+   void start() throws JMSException
+   {
+      if (trace)
+         log.trace("start()");
+
+      if (mc != null)
+         mc.start();
+   }
+
+   /**
+    * Stop
+    * @exception JMSException Thrown if an error occurs
+    */
+   void stop() throws JMSException
+   {
+      if (trace)
+         log.trace("stop()");
+
+      if (mc != null)
+         mc.stop();
+   }
+
+   /**
+    * Check strict
+    * @exception JMSException Thrown if an error occurs
+    */
+   void checkStrict() throws JMSException
+   {
+      if (trace)
+         log.trace("checkStrict()");
+
+      if (mc != null)
+         throw new IllegalStateException(JBMSessionFactory.ISE);
+   }
+   
+   /**
+    * Close session
+    * @exception JMSException Thrown if an error occurs
+    */
+   void closeSession() throws JMSException
+   {
+      if (mc != null)
+      {
+         log.trace("Closing session");
+
+         try
+         {
+            mc.stop();
+         }
+         catch (Throwable t)
+         {
+            log.trace("Error stopping managed connection", t);
+         }
+         
+         synchronized (consumers)
+         {
+            for (Iterator i = consumers.iterator(); i.hasNext();)
+            {
+               JBMMessageConsumer consumer = (JBMMessageConsumer) i.next();
+               try
+               {
+                  consumer.closeConsumer();
+               }
+               catch (Throwable t)
+               {
+                  log.trace("Error closing consumer", t);
+               }
+               i.remove();
+            }
+         }
+
+         synchronized (producers)
+         {
+            for (Iterator i = producers.iterator(); i.hasNext();)
+            {
+               JBMMessageProducer producer = (JBMMessageProducer) i.next();
+               try
+               {
+                  producer.closeProducer();
+               }
+               catch (Throwable t)
+               {
+                  log.trace("Error closing producer", t);
+               }
+               i.remove();
+            }
+         }
+         
+         mc.removeHandle(this);
+         ConnectionEvent ev = new ConnectionEvent(mc, ConnectionEvent.CONNECTION_CLOSED);
+         ev.setConnectionHandle(this);
+         mc.sendEvent(ev);
+         mc = null;
+      }
+   }
+   
+   /**
+    * Add consumer
+    * @param consumer The consumer
+    */
+   void addConsumer(MessageConsumer consumer)
+   {
+      if (trace)
+         log.trace("addConsumer(" + consumer + ")");
+
+      synchronized (consumers)
+      {
+         consumers.add(consumer);
+      }
+   }
+   
+   /**
+    * Remove consumer
+    * @param consumer The consumer
+    */
+   void removeConsumer(MessageConsumer consumer)
+   {
+      if (trace)
+         log.trace("removeConsumer(" + consumer + ")");
+
+      synchronized (consumers)
+      {
+         consumers.remove(consumer);
+      }
+   }
+   
+   /**
+    * Add producer
+    * @param producer The producer
+    */
+   void addProducer(MessageProducer producer)
+   {
+      if (trace)
+         log.trace("addProducer(" + producer + ")");
+
+      synchronized (producers)
+      {
+         producers.add(producer);
+      }
+   }
+   
+   /**
+    * Remove producer
+    * @param producer The producer
+    */
+   void removeProducer(MessageProducer producer)
+   {
+      if (trace)
+         log.trace("removeProducer(" + producer + ")");
+
+      synchronized (producers)
+      {
+         producers.remove(producer);
+      }
+   }
+   
+   /**
+    * Get the session and ensure that it is open
+    * @return The session
+    * @exception JMSException Thrown if an error occurs
+    * @exception IllegalStateException The session is closed
+    */
+   Session getSessionInternal() throws JMSException
+   {
+      if (mc == null)
+         throw new IllegalStateException("The session is closed");
+      
+      Session session = mc.getSession();
+
+      if (trace)
+         log.trace("getSessionInternal " + session + " for " + this);
+
+      return session;
+   }
+
+   /**
+    * Get the XA session and ensure that it is open
+    * @return The session
+    * @exception JMSException Thrown if an error occurs
+    * @exception IllegalStateException The session is closed
+    */
+   XASession getXASessionInternal() throws JMSException
+   {
+      if (mc == null)
+         throw new IllegalStateException("The session is closed");
+      
+      XASession session = mc.getXASession();
+
+      if (trace)
+         log.trace("getXASessionInternal " + session + " for " + this);
+
+      return session;
+   }
+
+   /**
+    * Get the queue session
+    * @return The queue session
+    * @exception JMSException Thrown if an error occurs
+    * @exception IllegalStateException The session is closed
+    */
+   QueueSession getQueueSessionInternal() throws JMSException
+   {
+      Session s = getSessionInternal();
+      if( !(s instanceof QueueSession) )
+         throw new InvalidDestinationException("Attempting to use QueueSession methods on: " + this);
+      return (QueueSession) s; 
+   }
+   
+   /**
+    * Get the topic session
+    * @return The topic session
+    * @exception JMSException Thrown if an error occurs
+    * @exception IllegalStateException The session is closed
+    */
+   TopicSession getTopicSessionInternal() throws JMSException
+   {
+      Session s = getSessionInternal();
+      if( !(s instanceof TopicSession) )
+         throw new InvalidDestinationException("Attempting to use TopicSession methods on: " + this);
+      return (TopicSession) s;
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMSessionFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMSessionFactory.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMSessionFactory.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.QueueConnection;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TopicConnection;
+import javax.jms.XAConnection;
+import javax.jms.XAQueueConnection;
+import javax.jms.XATopicConnection;
+
+/**
+ * A joint interface for all connection types
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: 71554 $
+ */
+public interface JBMSessionFactory extends Connection, TopicConnection, QueueConnection, XAConnection, XATopicConnection, XAQueueConnection
+{
+   /** Error message for strict behaviour */
+   String ISE = "This method is not applicable inside the application server. See the J2EE spec, e.g. J2EE1.4 Section 6.6";
+
+   /**
+    * Add a temporary queue
+    * @param temp The temporary queue
+    */
+   void addTemporaryQueue(TemporaryQueue temp);
+
+   /**
+    * Add a temporary topic
+    * @param temp The temporary topic
+    */
+   void addTemporaryTopic(TemporaryTopic temp);
+   
+   /** 
+    * Notification that a session is closed
+    * @param session The session
+    * @throws JMSException for any error 
+    */
+   void closeSession(JBMSession session) throws JMSException;
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMSessionFactoryImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMSessionFactoryImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMSessionFactoryImpl.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,736 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.jms.ConnectionConsumer;
+import javax.jms.ConnectionMetaData;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.IllegalStateException;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.Topic;
+import javax.jms.TopicSession;
+import javax.jms.XAQueueSession;
+import javax.jms.XATopicSession;
+import javax.jms.XASession;
+import javax.naming.Reference;
+import javax.resource.Referenceable;
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ManagedConnectionFactory;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * Implements the JMS Connection API and produces {@link JBMSession} objects.
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision:  $
+ */
+public class JBMSessionFactoryImpl implements JBMSessionFactory, Referenceable
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMSessionFactoryImpl.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** Are we closed? */
+   private boolean closed = false;
+
+   /** The naming reference */
+   private Reference reference;
+
+   /** The user name */
+   private String userName;
+
+   /** The password */
+   private String password;
+
+   /** The client ID */
+   private String clientID;
+
+   /** The connection type */
+   private int type;
+
+   /** Whether we are started */
+   private boolean started = false;
+   
+   /** The managed connection factory */
+   private JBMManagedConnectionFactory mcf;
+
+   /** The connection manager */
+   private ConnectionManager cm;
+
+   /** The sessions */
+   private Set sessions = new HashSet();
+
+   /** The temporary queues */
+   private Set tempQueues = new HashSet();
+
+   /** The temporary topics */
+   private Set tempTopics = new HashSet();
+   
+   /**
+    * Constructor
+    * @param mcf The managed connection factory
+    * @param cm The connection manager
+    * @param type The connection type
+    */
+   public JBMSessionFactoryImpl(JBMManagedConnectionFactory mcf, ConnectionManager cm, int type)
+   {
+      this.mcf = mcf;
+
+      if (cm == null)
+         this.cm = new JBMConnectionManager();
+      else 
+         this.cm = cm;
+
+      this.type = type;
+
+      if (trace)
+         log.trace("constructor(" + mcf + ", " + cm + ", " + type);
+   }
+
+   /**
+    * Set the naming reference
+    * @param reference The reference
+    */
+   public void setReference(Reference reference)
+   {
+      if (trace)
+         log.trace("setReference(" + reference + ")");
+
+      this.reference = reference;
+   }
+    
+   /**
+    * Get the naming reference
+    * @return The reference
+    */
+   public Reference getReference()
+   {
+      if (trace)
+         log.trace("getReference()");
+
+      return reference;
+   }
+    
+   /**
+    * Set the user name
+    * @param name The user name
+    */
+   public void setUserName(String name) 
+   {
+      if (trace)
+         log.trace("setUserName(" + name + ")");
+
+      this.userName = name;
+   }
+    
+   /**
+    * Set the password
+    * @param password The password
+    */
+   public void setPassword(String password) 
+   {
+      if (trace)
+         log.trace("setPassword(****)");
+
+      this.password = password;
+   }
+
+   /**
+    * Get the client ID
+    * @return The client ID
+    * @exception JMSException Thrown if an error occurs
+    */
+   public String getClientID() throws JMSException
+   {
+      if (trace)
+         log.trace("getClientID()");
+
+      checkClosed();
+      return clientID;
+   }
+    
+   /**
+    * Set the client ID -- throws IllegalStateException
+    * @param cID The client ID
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setClientID(String cID) throws JMSException
+   {
+      if (trace)
+         log.trace("setClientID(" + cID + ")");
+
+      throw new IllegalStateException(ISE);
+   }
+    
+   /**
+    * Create a queue session
+    * @param transacted Use transactions
+    * @param acknowledgeMode The acknowledge mode
+    * @return The queue session
+    * @exception JMSException Thrown if an error occurs
+    */
+   public QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException
+   {
+      if (trace)
+         log.trace("createQueueSession(" + transacted + ", " + acknowledgeMode + ")");
+
+      checkClosed();
+
+      if (type == JBMConnectionFactory.TOPIC_CONNECTION || type == JBMConnectionFactory.XA_TOPIC_CONNECTION)
+         throw new IllegalStateException("Can not get a queue session from a topic connection");
+
+      return allocateConnection(transacted, acknowledgeMode, type);
+   }
+    
+   /**
+    * Create a XA queue session
+    * @return The XA queue session
+    * @exception JMSException Thrown if an error occurs
+    */
+   public XAQueueSession createXAQueueSession() throws JMSException
+   { 
+      if (trace)
+         log.trace("createXAQueueSession()");
+
+      checkClosed();
+
+      if (type == JBMConnectionFactory.CONNECTION || type == JBMConnectionFactory.TOPIC_CONNECTION || type == JBMConnectionFactory.XA_TOPIC_CONNECTION)
+         throw new IllegalStateException("Can not get a topic session from a queue connection");
+
+      return allocateConnection(type);
+   }
+
+   /**
+    * Create a connection consumer -- throws IllegalStateException
+    * @param queue The queue
+    * @param messageSelector The message selector
+    * @param sessionPool The session pool
+    * @param maxMessages The number of max messages
+    * @return The connection consumer
+    * @exception JMSException Thrown if an error occurs
+    */
+   public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException 
+   {
+      if (trace)
+         log.trace("createConnectionConsumer(" + queue + ", " + messageSelector + ", " + sessionPool + ", " + maxMessages + ")");
+
+      throw new IllegalStateException(ISE);
+   }
+    
+   /**
+    * Create a topic session
+    * @param transacted Use transactions
+    * @param acknowledgeMode The acknowledge mode
+    * @return The topic session
+    * @exception JMSException Thrown if an error occurs
+    */
+   public TopicSession createTopicSession(boolean transacted, int acknowledgeMode) throws JMSException
+   { 
+      if (trace)
+         log.trace("createTopicSession(" + transacted + ", " + acknowledgeMode + ")");
+
+      checkClosed();
+
+      if (type == JBMConnectionFactory.QUEUE_CONNECTION || type == JBMConnectionFactory.XA_QUEUE_CONNECTION)
+         throw new IllegalStateException("Can not get a topic session from a queue connection");
+
+      return allocateConnection(transacted, acknowledgeMode, type);
+   }
+
+   /**
+    * Create a XA topic session
+    * @return The XA topic session
+    * @exception JMSException Thrown if an error occurs
+    */
+   public XATopicSession createXATopicSession() throws JMSException
+   { 
+      if (trace)
+         log.trace("createXATopicSession()");
+
+      checkClosed();
+
+      if (type == JBMConnectionFactory.CONNECTION || type == JBMConnectionFactory.QUEUE_CONNECTION || type == JBMConnectionFactory.XA_QUEUE_CONNECTION)
+         throw new IllegalStateException("Can not get a topic session from a queue connection");
+
+      return allocateConnection(type);
+   }
+
+   /**
+    * Create a connection consumer -- throws IllegalStateException
+    * @param topic The topic
+    * @param messageSelector The message selector
+    * @param sessionPool The session pool
+    * @param maxMessages The number of max messages
+    * @return The connection consumer
+    * @exception JMSException Thrown if an error occurs
+    */
+   public ConnectionConsumer createConnectionConsumer(Topic topic, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException 
+   {
+      if (trace)
+         log.trace("createConnectionConsumer(" + topic + ", " + messageSelector + ", " + sessionPool + ", " + maxMessages + ")");
+
+      throw new IllegalStateException(ISE);
+   }		       
+
+   /**
+    * Create a durable connection consumer -- throws IllegalStateException
+    * @param topic The topic
+    * @param subscriptionName The subscription name
+    * @param messageSelector The message selector
+    * @param sessionPool The session pool
+    * @param maxMessages The number of max messages
+    * @return The connection consumer
+    * @exception JMSException Thrown if an error occurs
+    */
+   public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
+   {
+      if (trace)
+         log.trace("createConnectionConsumer(" + topic + ", " + subscriptionName + ", " + messageSelector + ", " + sessionPool + ", " + maxMessages + ")");
+
+      throw new IllegalStateException(ISE);
+   }
+
+   /**
+    * Create a connection consumer -- throws IllegalStateException
+    * @param destination The destination
+    * @param pool The session pool
+    * @param maxMessages The number of max messages
+    * @return The connection consumer
+    * @exception JMSException Thrown if an error occurs
+    */
+   public ConnectionConsumer createConnectionConsumer(Destination destination, ServerSessionPool pool, int maxMessages) throws JMSException
+   {
+      if (trace)
+         log.trace("createConnectionConsumer(" + destination + ", " + pool + ", " + maxMessages + ")");
+
+      throw new IllegalStateException(ISE);
+   }
+
+   /**
+    * Create a connection consumer -- throws IllegalStateException
+    * @param destination The destination
+    * @param name The name
+    * @param pool The session pool
+    * @param maxMessages The number of max messages
+    * @return The connection consumer
+    * @exception JMSException Thrown if an error occurs
+    */
+   public ConnectionConsumer createConnectionConsumer(Destination destination, String name, ServerSessionPool pool, int maxMessages) throws JMSException
+   {
+      if (trace)
+         log.trace("createConnectionConsumer(" + destination + ", " + name + ", " + pool + ", " + maxMessages + ")");
+
+      throw new IllegalStateException(ISE);
+   }
+
+   /**
+    * Create a session
+    * @param transacted Use transactions
+    * @param acknowledgeMode The acknowledge mode
+    * @return The session
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException
+   {
+      if (trace)
+         log.trace("createSession(" + transacted + ", " + acknowledgeMode + ")");
+
+      checkClosed();
+      return allocateConnection(transacted, acknowledgeMode, type);
+   }
+
+   /**
+    * Create a XA session
+    * @return The XA session
+    * @exception JMSException Thrown if an error occurs
+    */
+   public XASession createXASession() throws JMSException
+   {
+      if (trace)
+         log.trace("createXASession()");
+
+      checkClosed();
+      return allocateConnection(type);
+   }
+
+   /**
+    * Get the connection metadata
+    * @return The connection metadata
+    * @exception JMSException Thrown if an error occurs
+    */
+   public ConnectionMetaData getMetaData() throws JMSException
+   {
+      if (trace)
+         log.trace("getMetaData()");
+
+      checkClosed();
+      return mcf.getMetaData();
+   }
+    
+   /**
+    * Get the exception listener -- throws IllegalStateException
+    * @return The exception listener
+    * @exception JMSException Thrown if an error occurs
+    */
+   public ExceptionListener getExceptionListener() throws JMSException
+   {
+      if (trace)
+         log.trace("getExceptionListener()");
+
+      throw new IllegalStateException(ISE);
+   }
+    
+   /**
+    * Set the exception listener -- throws IllegalStateException
+    * @param listener The exception listener
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setExceptionListener(ExceptionListener listener) throws JMSException
+   {
+      if (trace)
+         log.trace("setExceptionListener(" + listener + ")");
+
+      throw new IllegalStateException(ISE);
+   }
+
+   /**
+    * Start
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void start() throws JMSException
+   {
+      checkClosed();
+
+      if (trace)
+         log.trace("start() " + this);
+
+      synchronized (sessions)
+      {
+         if (started)
+            return;
+         started = true;
+         for (Iterator i = sessions.iterator(); i.hasNext();)
+         {
+            JBMSession session = (JBMSession) i.next();
+            session.start();
+         }
+      }
+   }
+    
+   /**
+    * Stop -- throws IllegalStateException
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void stop() throws JMSException
+   {
+      if (trace)
+         log.trace("stop() " + this);
+
+      throw new IllegalStateException(ISE);
+   }
+
+   /**
+    * Close
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void close() throws JMSException
+   {
+      if (trace)
+         log.trace("close() " + this);
+      
+      if (closed)
+         return;
+
+      closed = true;
+
+      synchronized (sessions)
+      {
+         for (Iterator i = sessions.iterator(); i.hasNext();)
+         {
+            JBMSession session = (JBMSession) i.next();
+            try
+            {
+               session.closeSession();
+            }
+            catch (Throwable t)
+            {
+               log.trace("Error closing session", t);
+            }
+            i.remove();
+         }
+      }
+      
+      synchronized (tempQueues)
+      {
+         for (Iterator i = tempQueues.iterator(); i.hasNext();)
+         {
+            TemporaryQueue temp = (TemporaryQueue) i.next();
+            try
+            {
+               if (trace)
+                  log.trace("Closing temporary queue " + temp + " for " + this);
+               temp.delete();
+            }
+            catch (Throwable t)
+            {
+               log.trace("Error deleting temporary queue", t);
+            }
+            i.remove();
+         }
+      }
+      
+      synchronized (tempTopics)
+      {
+         for (Iterator i = tempTopics.iterator(); i.hasNext();)
+         {
+            TemporaryTopic temp = (TemporaryTopic) i.next();
+            try
+            {
+               if (trace)
+                  log.trace("Closing temporary topic " + temp + " for " + this);
+               temp.delete();
+            }
+            catch (Throwable t)
+            {
+               log.trace("Error deleting temporary queue", t);
+            }
+            i.remove();
+         }
+      }
+   }
+
+   /**
+    * Close session
+    * @param session The session
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void closeSession(JBMSession session) throws JMSException
+   {
+      if (trace)
+         log.trace("closeSession(" + session + ")");
+      
+      synchronized (sessions)
+      {
+         sessions.remove(session);
+      }
+   }
+   
+   /**
+    * Add temporary queue
+    * @param temp The temporary queue
+    */
+   public void addTemporaryQueue(TemporaryQueue temp)
+   {
+      if (trace)
+         log.trace("addTemporaryQueue(" + temp + ")");
+      
+      synchronized(tempQueues)
+      {
+         tempQueues.add(temp);
+      }
+   }
+   
+   /**
+    * Add temporary topic
+    * @param temp The temporary topic
+    */
+   public void addTemporaryTopic(TemporaryTopic temp)
+   {
+      if (trace)
+         log.trace("addTemporaryTopic(" + temp + ")");
+      
+      synchronized(tempTopics)
+      {
+         tempTopics.add(temp);
+      }
+   }
+
+   /**
+    * Allocation a connection
+    * @param sessionType The session type
+    * @return The session 
+    * @exception JMSException Thrown if an error occurs
+    */
+   protected JBMSession allocateConnection(int sessionType) throws JMSException
+   {
+      if (trace)
+         log.trace("allocateConnection(" + sessionType + ")");
+
+      try
+      {
+         synchronized (sessions)
+         {
+            if (sessions.isEmpty() == false)
+               throw new IllegalStateException("Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6");
+
+            JBMConnectionRequestInfo info = new JBMConnectionRequestInfo(sessionType);
+            info.setUserName(userName);
+            info.setPassword(password);
+            info.setClientID(clientID);
+
+            if (trace)
+               log.trace("Allocating session for " + this + " with request info=" + info);
+
+            JBMSession session = (JBMSession) cm.allocateConnection(mcf, info);
+
+            try
+            {
+               if (trace)
+                  log.trace("Allocated  " + this + " session=" + session);
+
+               session.setJBMSessionFactory(this);
+
+               if (started)
+                  session.start();
+
+               sessions.add(session);
+
+               return session;
+            }
+            catch (Throwable t)
+            {
+               try
+               {
+                  session.close();
+               }
+               catch (Throwable ignored)
+               {
+               }
+               if (t instanceof Exception)
+                  throw (Exception) t;
+               else
+                  throw new RuntimeException("Unexpected error: ", t);
+            }
+         }
+      }
+      catch (Exception e)
+      {
+         log.error("Could not create session", e);
+         
+         JMSException je = new JMSException("Could not create a session: " + e.getMessage());
+         je.setLinkedException(e);
+         throw je;
+      }
+   }
+
+   /**
+    * Allocation a connection
+    * @param transacted Use transactions
+    * @param acknowledgeMode The acknowledge mode
+    * @param sessionType The session type
+    * @return The session 
+    * @exception JMSException Thrown if an error occurs
+    */
+   protected JBMSession allocateConnection(boolean transacted, int acknowledgeMode, int sessionType) throws JMSException
+   {
+      if (trace)
+         log.trace("allocateConnection(" + transacted + ", " + acknowledgeMode + ", " + sessionType + ")");
+
+      try
+      {
+         synchronized (sessions)
+         {
+            if (sessions.isEmpty() == false)
+               throw new IllegalStateException("Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6");
+
+            if (transacted)
+               acknowledgeMode = Session.SESSION_TRANSACTED;
+
+            JBMConnectionRequestInfo info = new JBMConnectionRequestInfo(transacted, acknowledgeMode, sessionType);
+            info.setUserName(userName);
+            info.setPassword(password);
+            info.setClientID(clientID);
+
+            if (trace)
+               log.trace("Allocating session for " + this + " with request info=" + info);
+
+            JBMSession session = (JBMSession) cm.allocateConnection(mcf, info);
+
+            try
+            {
+               if (trace)
+                  log.trace("Allocated  " + this + " session=" + session);
+
+               session.setJBMSessionFactory(this);
+
+               if (started)
+                  session.start();
+
+               sessions.add(session);
+
+               return session;
+            }
+            catch (Throwable t)
+            {
+               try
+               {
+                  session.close();
+               }
+               catch (Throwable ignored)
+               {
+               }
+               if (t instanceof Exception)
+                  throw (Exception) t;
+               else
+                  throw new RuntimeException("Unexpected error: ", t);
+            }
+         }
+      }
+      catch (Exception e)
+      {
+         log.error("Could not create session", e);
+         
+         JMSException je = new JMSException("Could not create a session: " + e.getMessage());
+         je.setLinkedException(e);
+         throw je;
+      }
+   }
+
+   /**
+    * Check if we are closed
+    * @exception IllegalStateException Thrown if closed
+    */
+   protected void checkClosed() throws IllegalStateException
+   {
+      if (trace)
+         log.trace("checkClosed()" + this);
+
+      if (closed)
+         throw new IllegalStateException("The connection is closed");
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMStreamMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMStreamMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMStreamMessage.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,370 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.JMSException;
+import javax.jms.StreamMessage;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A wrapper for a message
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMStreamMessage extends JBMMessage implements StreamMessage
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMStreamMessage.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**
+    * Create a new wrapper
+    * @param message the message
+    * @param session the session
+    */
+   public JBMStreamMessage(StreamMessage message, JBMSession session)
+   {
+      super(message, session);
+
+      if (trace)
+         log.trace("constructor(" + message + ", " + session + ")");
+   }
+   
+   /**
+    * Read 
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean readBoolean() throws JMSException
+   {
+      if (trace)
+         log.trace("readBoolean()");
+
+      return ((StreamMessage) message).readBoolean();
+   }
+   
+   /**
+    * Read 
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public byte readByte() throws JMSException
+   {
+      if (trace)
+         log.trace("readByte()");
+
+      return ((StreamMessage) message).readByte();
+   }
+   
+   /**
+    * Read 
+    * @param value The value
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int readBytes(byte[] value) throws JMSException
+   {
+      if (trace)
+         log.trace("readBytes(" + value + ")");
+
+      return ((StreamMessage) message).readBytes(value);
+   }
+   
+   /**
+    * Read 
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public char readChar() throws JMSException
+   {
+      if (trace)
+         log.trace("readChar()");
+
+      return ((StreamMessage) message).readChar();
+   }
+   
+   /**
+    * Read 
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public double readDouble() throws JMSException
+   {
+      if (trace)
+         log.trace("readDouble()");
+
+      return ((StreamMessage) message).readDouble();
+   }
+   
+   /**
+    * Read 
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public float readFloat() throws JMSException
+   {
+      if (trace)
+         log.trace("readFloat()");
+
+      return ((StreamMessage) message).readFloat();
+   }
+   
+   /**
+    * Read 
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public int readInt() throws JMSException
+   {
+      if (trace)
+         log.trace("readInt()");
+
+      return ((StreamMessage) message).readInt();
+   }
+   
+   /**
+    * Read 
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public long readLong() throws JMSException
+   {
+      if (trace)
+         log.trace("readLong()");
+
+      return ((StreamMessage) message).readLong();
+   }
+   
+   /**
+    * Read 
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Object readObject() throws JMSException
+   {
+      if (trace)
+         log.trace("readObject()");
+
+      return ((StreamMessage) message).readObject();
+   }
+   
+   /**
+    * Read 
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public short readShort() throws JMSException
+   {
+      if (trace)
+         log.trace("readShort()");
+
+      return ((StreamMessage) message).readShort();
+   }
+   
+   /**
+    * Read 
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public String readString() throws JMSException
+   {
+      if (trace)
+         log.trace("readString()");
+
+      return ((StreamMessage) message).readString();
+   }
+   
+   /**
+    * Reset 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void reset() throws JMSException
+   {
+      if (trace)
+         log.trace("reset()");
+
+      ((StreamMessage) message).reset();
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeBoolean(boolean value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeBoolean(" + value + ")");
+
+      ((StreamMessage) message).writeBoolean(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeByte(byte value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeByte(" + value + ")");
+
+      ((StreamMessage) message).writeByte(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @param offset The offset
+    * @param length The length
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeBytes(byte[] value, int offset, int length) throws JMSException
+   {
+      if (trace)
+         log.trace("writeBytes(" + value + ", " + offset + ", " + length + ")");
+
+      ((StreamMessage) message).writeBytes(value, offset, length);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeBytes(byte[] value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeBytes(" + value + ")");
+
+      ((StreamMessage) message).writeBytes(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeChar(char value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeChar(" + value + ")");
+
+      ((StreamMessage) message).writeChar(value);
+   }
+   
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeDouble(double value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeDouble(" + value + ")");
+
+      ((StreamMessage) message).writeDouble(value);
+   }
+
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeFloat(float value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeFloat(" + value + ")");
+
+      ((StreamMessage) message).writeFloat(value);
+   }
+
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeInt(int value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeInt(" + value + ")");
+
+      ((StreamMessage) message).writeInt(value);
+   }
+
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeLong(long value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeLong(" + value + ")");
+
+      ((StreamMessage) message).writeLong(value);
+   }
+
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeObject(Object value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeObject(" + value + ")");
+
+      ((StreamMessage) message).writeObject(value);
+   }
+
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeShort(short value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeShort(" + value + ")");
+
+      ((StreamMessage) message).writeShort(value);
+   }
+
+   /**
+    * Write
+    * @param value The value 
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void writeString(String value) throws JMSException
+   {
+      if (trace)
+         log.trace("writeString(" + value + ")");
+
+      ((StreamMessage) message).writeString(value);
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMTextMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMTextMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMTextMessage.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A wrapper for a message
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMTextMessage extends JBMMessage implements TextMessage
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMTextMessage.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**
+    * Create a new wrapper
+    * @param message the message
+    * @param session the session
+    */
+   public JBMTextMessage(TextMessage message, JBMSession session)
+   {
+      super(message, session);
+
+      if (trace)
+         log.trace("constructor(" + message + ", " + session + ")");
+   }
+
+   /**
+    * Get text
+    * @return The text
+    * @exception JMSException Thrown if an error occurs
+    */
+   public String getText() throws JMSException
+   {
+      if (trace)
+         log.trace("getText()");
+
+      return ((TextMessage) message).getText();
+   }
+   
+   /**
+    * Set text
+    * @param string The text
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void setText(String string) throws JMSException
+   {
+      if (trace)
+         log.trace("setText(" + string + ")");
+
+      ((TextMessage) message).setText(string);
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMTopicPublisher.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMTopicPublisher.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMTopicPublisher.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,183 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Topic;
+import javax.jms.TopicPublisher;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * JBMQueueSender.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision:  $
+ */
+public class JBMTopicPublisher extends JBMMessageProducer implements TopicPublisher
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMTopicPublisher.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**
+    * Create a new wrapper
+    * @param producer the producer
+    * @param session the session
+    */
+   public JBMTopicPublisher(TopicPublisher producer, JBMSession session)
+   {
+      super(producer, session);
+
+      if (trace)
+         log.trace("constructor(" + producer + ", " + session + ")");
+   }
+
+   /**
+    * Get the topic
+    * @return The topic
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Topic getTopic() throws JMSException
+   {
+      if (trace)
+         log.trace("getTopic()");
+
+      return ((TopicPublisher) producer).getTopic();
+   }
+
+   /**
+    * Publish message
+    * @param message The message
+    * @param deliveryMode The delivery mode
+    * @param priority The priority
+    * @param timeToLive The time to live
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void publish(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("send " + this  + " message=" + message + " deliveryMode=" + deliveryMode + " priority=" + priority + " ttl=" + timeToLive);
+
+         checkState();
+
+         ((TopicPublisher) producer).publish(message, deliveryMode, priority, timeToLive);
+
+         if (trace)
+            log.trace("sent " + this + " result=" + message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Publish message
+    * @param message The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void publish(Message message) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("send " + this + " message=" + message);
+
+         checkState();
+
+         ((TopicPublisher) producer).publish(message);
+
+         if (trace)
+            log.trace("sent " + this + " result=" + message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Publish message
+    * @param destination The destination
+    * @param message The message
+    * @param deliveryMode The delivery mode
+    * @param priority The priority
+    * @param timeToLive The time to live
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void publish(Topic destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("send " + this + " destination=" + destination + " message=" + message + " deliveryMode=" + deliveryMode + " priority=" + priority + " ttl=" + timeToLive);
+
+         checkState();
+
+         ((TopicPublisher) producer).publish(destination, message, deliveryMode, priority, timeToLive);
+
+         if (trace)
+            log.trace("sent " + this + " result=" + message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+
+   /**
+    * Publish message
+    * @param destination The destination
+    * @param message The message
+    * @exception JMSException Thrown if an error occurs
+    */
+   public void publish(Topic destination, Message message) throws JMSException
+   {
+      session.lock();
+      try
+      {
+         if (trace)
+            log.trace("send " + this + " destination=" + destination + " message=" + message);
+
+         checkState();
+
+         ((TopicPublisher) producer).publish(destination, message);
+
+         if (trace)
+            log.trace("sent " + this + " result=" + message);
+      }
+      finally
+      {
+         session.unlock();
+      }
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMTopicSubscriber.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMTopicSubscriber.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMTopicSubscriber.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.jms.JMSException;
+import javax.jms.Topic;
+import javax.jms.TopicSubscriber;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A wrapper for a topic subscriber
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMTopicSubscriber extends JBMMessageConsumer implements TopicSubscriber
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMTopicSubscriber.class);
+   
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**
+    * Create a new wrapper
+    * @param consumer the topic subscriber
+    * @param session the session
+    */
+   public JBMTopicSubscriber(TopicSubscriber consumer, JBMSession session)
+   {
+      super(consumer, session);
+
+      if (trace)
+         log.trace("constructor(" + consumer + ", " + session + ")");
+   }
+
+   /**
+    * Get the no local value
+    * @return The value
+    * @exception JMSException Thrown if an error occurs
+    */
+   public boolean getNoLocal() throws JMSException
+   {
+      if (trace)
+         log.trace("getNoLocal()");
+
+      checkState();
+      return ((TopicSubscriber) consumer).getNoLocal();
+   }
+
+   /**
+    * Get the topic
+    * @return The topic
+    * @exception JMSException Thrown if an error occurs
+    */
+   public Topic getTopic() throws JMSException
+   {
+      if (trace)
+         log.trace("getTopic()");
+
+      checkState();
+      return ((TopicSubscriber) consumer).getTopic();
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/JBMXAResource.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMXAResource.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/JBMXAResource.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,225 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * JBMXAResource.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class JBMXAResource implements XAResource
+{
+   /** The logger */
+   private static final Logger log = Logger.getLogger(JBMXAResource.class);
+   
+   /** Trace enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /** The managed connection */
+   private JBMManagedConnection managedConnection;
+   
+   /** The resource */
+   private XAResource xaResource;
+
+   /**
+    * Create a new JBMXAResource.
+    * @param managedConnection the managed connection
+    * @param xaResource the xa resource
+    */
+   public JBMXAResource(JBMManagedConnection managedConnection, XAResource xaResource)
+   {
+      if (trace)
+         log.trace("constructor(" + managedConnection + ", " + xaResource + ")");
+
+      this.managedConnection = managedConnection;
+      this.xaResource = xaResource;
+   }
+
+   /**
+    * Start
+    * @param xid A global transaction identifier
+    * @param flags One of TMNOFLAGS, TMJOIN, or TMRESUME
+    * @exception XAException An error has occurred
+    */
+   public void start(Xid xid, int flags) throws XAException
+   {
+      if (trace)
+         log.trace("start(" + xid + ", " + flags + ")");
+
+      managedConnection.lock();
+      try
+      {
+         xaResource.start(xid, flags);
+      }
+      finally
+      {
+         managedConnection.unlock();
+      }
+   }
+
+   /**
+    * End
+    * @param xid A global transaction identifier
+    * @param flags One of TMSUCCESS, TMFAIL, or TMSUSPEND.
+    * @exception XAException An error has occurred
+    */
+   public void end(Xid xid, int flags) throws XAException
+   {
+      if (trace)
+         log.trace("end(" + xid + ", " + flags + ")");
+
+      managedConnection.lock();
+      try
+      {
+         xaResource.end(xid, flags);
+      }
+      finally
+      {
+         managedConnection.unlock();
+      }
+   }
+
+   /**
+    * Prepare
+    * @param xid A global transaction identifier
+    * @return XA_RDONLY or XA_OK
+    * @exception XAException An error has occurred
+    */
+   public int prepare(Xid xid) throws XAException
+   {
+      if (trace)
+         log.trace("prepare(" + xid + ")");
+
+      return xaResource.prepare(xid);
+   }
+
+   /**
+    * Commit
+    * @param xid A global transaction identifier
+    * @param onePhase If true, the resource manager should use a one-phase commit protocol to commit the work done on behalf of xid. 
+    * @exception XAException An error has occurred
+    */
+   public void commit(Xid xid, boolean onePhase) throws XAException
+   {
+      if (trace)
+         log.trace("commit(" + xid + ", " + onePhase + ")");
+
+      xaResource.commit(xid, onePhase);
+   }
+
+   /**
+    * Rollback
+    * @param xid A global transaction identifier
+    * @exception XAException An error has occurred
+    */
+   public void rollback(Xid xid) throws XAException
+   {
+      if (trace)
+         log.trace("rollback(" + xid + ")");
+
+      xaResource.rollback(xid);
+   }
+
+   /**
+    * Forget
+    * @param xid A global transaction identifier
+    * @exception XAException An error has occurred
+    */
+   public void forget(Xid xid) throws XAException
+   {
+      if (trace)
+         log.trace("forget(" + xid + ")");
+
+      managedConnection.lock();
+      try
+      {
+         xaResource.forget(xid);
+      }
+      finally
+      {
+         managedConnection.unlock();
+      }
+   }
+
+   /**
+    * IsSameRM
+    * @param xaRes An XAResource object whose resource manager instance is to be compared with the resource manager instance of the target object. 
+    * @return True if its the same RM instance; otherwise false. 
+    * @exception XAException An error has occurred
+    */
+   public boolean isSameRM(XAResource xaRes) throws XAException
+   {
+      if (trace)
+         log.trace("isSameRM(" + xaRes + ")");
+
+      return xaResource.isSameRM(xaRes);
+   }
+
+   /**
+    * Recover 
+    * @param flags One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS
+    * @return Zero or more XIDs
+    * @exception XAException An error has occurred
+    */
+   public Xid[] recover(int flag) throws XAException
+   {
+      if (trace)
+         log.trace("recover(" + flag + ")");
+
+      return xaResource.recover(flag);
+   }
+
+   /**
+    * Get the transaction timeout in seconds
+    * @return The transaction timeout
+    * @exception XAException An error has occurred
+    */
+   public int getTransactionTimeout() throws XAException
+   {
+      if (trace)
+         log.trace("getTransactionTimeout()");
+
+      return xaResource.getTransactionTimeout();
+   }
+
+   /**
+    * Set the transaction timeout
+    * @param seconds The number of seconds
+    * @return True if the transaction timeout value is set successfully; otherwise false. 
+    * @exception XAException An error has occurred
+    */
+   public boolean setTransactionTimeout(int seconds) throws XAException
+   {
+      if (trace)
+         log.trace("setTransactionTimeout(" + seconds + ")");
+
+      return xaResource.setTransactionTimeout(seconds);
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/Util.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/Util.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/Util.java	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.ra;
+
+/**
+ * Various utility functions
+ *
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class Util {
+
+   /**
+    * Private constructor
+    */
+   private Util()
+   {
+   }
+
+   /**
+    * Compare two strings.
+    * @param me First value
+    * @param you Second value
+    * @return True if object equals else false. 
+    */
+   public static boolean compare(final String me, final String you)
+   {
+      // If both null or intern equals
+      if (me == you)
+         return true;
+      
+      // if me null and you are not
+      if (me == null && you != null)
+         return false;
+      
+      // me will not be null, test for equality
+      return me.equals(you);
+   }
+
+   /**
+    * Compare two integers.
+    * @param me First value
+    * @param you Second value
+    * @return True if object equals else false. 
+    */
+   public static boolean compare(final Integer me, final Integer you)
+   {
+      // If both null or intern equals
+      if (me == you)
+         return true;
+      
+      // if me null and you are not
+      if (me == null && you != null)
+         return false;
+      
+      // me will not be null, test for equality
+      return me.equals(you);
+   }
+
+   /**
+    * Compare two booleans.
+    * @param me First value
+    * @param you Second value
+    * @return True if object equals else false. 
+    */
+   public static boolean compare(final Boolean me, final Boolean you)
+   {
+      // If both null or intern equals
+      if (me == you)
+         return true;
+      
+      // if me null and you are not
+      if (me == null && you != null)
+         return false;
+      
+      // me will not be null, test for equality
+      return me.equals(you);
+   }
+}

Added: trunk/src/main/org/jboss/messaging/ra/package.html
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/package.html	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/ra/package.html	2009-01-29 16:47:21 UTC (rev 5759)
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+  <head>
+    <!-- $Id: package.html 71554 2008-04-01 13:25:40Z adrian at jboss.org $ -->
+    <!--
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+    -->
+  </head>
+
+  <body bgcolor="white">
+    <h1>JBoss Messaging Resource Adaptor</h1>
+
+  </body>
+</html>




More information about the jboss-cvs-commits mailing list