You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2006/12/18 14:02:57 UTC

svn commit: r488262 [2/4] - in /incubator/qpid/branches/jmsselectors/java/client: ./ example/ example/src/ example/src/main/ example/src/main/java/ example/src/main/java/org/ example/src/main/java/org/apache/ example/src/main/java/org/apache/qpid/ exam...

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java Mon Dec 18 05:02:27 2006
@@ -26,22 +26,45 @@
 /**
  * AMQ implementation of a TemporaryQueue.
  */
-final class AMQTemporaryQueue extends AMQQueue implements TemporaryQueue {
+final class AMQTemporaryQueue extends AMQQueue implements TemporaryQueue, TemporaryDestination
+{
+
+
+    private final AMQSession _session;
+    private boolean _deleted;
 
     /**
      * Create a new instance of an AMQTemporaryQueue
      */
-    public AMQTemporaryQueue() {
-        super("TempQueue" + Long.toString(System.currentTimeMillis()),
-                null, true, true);
+    public AMQTemporaryQueue(AMQSession session)
+    {
+        super("TempQueue" + Long.toString(System.currentTimeMillis()), true);
+        _session = session;
     }
 
     /**
      * @see javax.jms.TemporaryQueue#delete()
      */
-    public void delete() throws JMSException {
-        throw new UnsupportedOperationException("Delete not supported, " +
-            "will auto-delete when connection closed");
+    public synchronized void delete() throws JMSException
+    {
+        if(_session.hasConsumer(this))
+        {
+            throw new JMSException("Temporary Queue has consumers so cannot be deleted");
+        }
+        _deleted = true;
+
+        // Currently TemporaryQueue is set to be auto-delete which means that the queue will be deleted
+        // by the server when there are no more subscriptions to that queue.  This is probably not
+        // quite right for JMSCompliance.
+    }
+
+    public AMQSession getSession()
+    {
+        return _session;
+    }
+
+    public boolean isDeleted()
+    {
+        return _deleted;
     }
-    
 }

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java Mon Dec 18 05:02:27 2006
@@ -26,15 +26,18 @@
 /**
  * AMQ implementation of TemporaryTopic.
  */
-class AMQTemporaryTopic extends AMQTopic implements TemporaryTopic
+class AMQTemporaryTopic extends AMQTopic implements TemporaryTopic, TemporaryDestination
 {
 
+    private final AMQSession _session;
+    private boolean _deleted;
     /**
      * Create new temporary topic.
      */
-    public AMQTemporaryTopic()
+    public AMQTemporaryTopic(AMQSession session)
     {
         super("TempQueue" + Long.toString(System.currentTimeMillis()));
+        _session = session;
     }
 
     /**
@@ -42,8 +45,25 @@
      */
     public void delete() throws JMSException
     {
-        throw new UnsupportedOperationException("Delete not supported, " +
-                "will auto-delete when connection closed");
+        if(_session.hasConsumer(this))
+        {
+            throw new JMSException("Temporary Topic has consumers so cannot be deleted");
+        }
+
+        _deleted = true;
+        // Currently TemporaryQueue is set to be auto-delete which means that the queue will be deleted
+        // by the server when there are no more subscriptions to that queue.  This is probably not
+        // quite right for JMSCompliance.
+    }
+
+    public AMQSession getSession()
+    {
+        return _session;
+    }
+
+    public boolean isDeleted()
+    {
+        return _deleted;
     }
 
 }

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java Mon Dec 18 05:02:27 2006
@@ -7,9 +7,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -40,30 +40,30 @@
 
     public AMQTopic(String name)
     {
-        super(ExchangeDefaults.TOPIC_EXCHANGE_NAME, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, name, true, true, null);
-        _isDurable = false;
+        this(name, true, null, false);
     }
 
-    /**
-     * Constructor for use in creating a topic to represent a durable subscription
-     * @param topic
-     * @param clientId
-     * @param subscriptionName
-     */
-    public AMQTopic(AMQTopic topic, String clientId, String subscriptionName)
+    public AMQTopic(String name, boolean isAutoDelete, String queueName, boolean isDurable)
     {
-        super(ExchangeDefaults.TOPIC_EXCHANGE_NAME, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, topic.getDestinationName(), true, false, clientId + ":" + subscriptionName);
-        _isDurable = true;
+        super(ExchangeDefaults.TOPIC_EXCHANGE_NAME, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, name, true, isAutoDelete,
+              queueName, isDurable);
     }
 
-    public String getTopicName() throws JMSException
+    public static AMQTopic createDurableTopic(AMQTopic topic, String subscriptionName, AMQConnection connection)
+            throws JMSException
     {
-        return super.getDestinationName();
+        return new AMQTopic(topic.getDestinationName(), false, getDurableTopicQueueName(subscriptionName, connection),
+                            true);
     }
 
-    public String getEncodedName()
+    public static String getDurableTopicQueueName(String subscriptionName, AMQConnection connection) throws JMSException
     {
-        return 'T' + getDestinationName();
+        return connection.getClientID() + ":" + subscriptionName;
+    }
+
+    public String getTopicName() throws JMSException
+    {
+        return super.getDestinationName();
     }
 
      public String getRoutingKey()

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTopicSessionAdaptor.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTopicSessionAdaptor.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTopicSessionAdaptor.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/AMQTopicSessionAdaptor.java Mon Dec 18 05:02:27 2006
@@ -7,9 +7,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -33,136 +33,169 @@
         _session = (AMQSession) session;
     }
 
-    public Topic createTopic(String string) throws JMSException {
+    public Topic createTopic(String string) throws JMSException
+    {
         return _session.createTopic(string);
     }
 
-    public TopicSubscriber createSubscriber(Topic topic) throws JMSException {
+    public TopicSubscriber createSubscriber(Topic topic) throws JMSException
+    {
         return _session.createSubscriber(topic);
     }
 
-    public TopicSubscriber createSubscriber(Topic topic, String string, boolean b) throws JMSException {
+    public TopicSubscriber createSubscriber(Topic topic, String string, boolean b) throws JMSException
+    {
         return _session.createSubscriber(topic, string, b);
     }
 
-    public TopicSubscriber createDurableSubscriber(Topic topic, String string) throws JMSException {
+    public TopicSubscriber createDurableSubscriber(Topic topic, String string) throws JMSException
+    {
         return _session.createDurableSubscriber(topic, string);
     }
 
-    public TopicSubscriber createDurableSubscriber(Topic topic, String string, String string1, boolean b) throws JMSException {
+    public TopicSubscriber createDurableSubscriber(Topic topic, String string, String string1, boolean b) throws JMSException
+    {
         return _session.createDurableSubscriber(topic, string, string1, b);
     }
 
-    public TopicPublisher createPublisher(Topic topic) throws JMSException {
+    public TopicPublisher createPublisher(Topic topic) throws JMSException
+    {
         return _session.createPublisher(topic);
     }
 
-    public TemporaryTopic createTemporaryTopic() throws JMSException {
+    public TemporaryTopic createTemporaryTopic() throws JMSException
+    {
         return _session.createTemporaryTopic();
     }
 
-    public void unsubscribe(String string) throws JMSException {
+    public void unsubscribe(String string) throws JMSException
+    {
         _session.unsubscribe(string);
     }
 
-    public BytesMessage createBytesMessage() throws JMSException {
+    public BytesMessage createBytesMessage() throws JMSException
+    {
         return _session.createBytesMessage();
     }
 
-    public MapMessage createMapMessage() throws JMSException {
+    public MapMessage createMapMessage() throws JMSException
+    {
         return _session.createMapMessage();
     }
 
-    public Message createMessage() throws JMSException {
+    public Message createMessage() throws JMSException
+    {
         return _session.createMessage();
     }
 
-    public ObjectMessage createObjectMessage() throws JMSException {
+    public ObjectMessage createObjectMessage() throws JMSException
+    {
         return _session.createObjectMessage();
     }
 
-    public ObjectMessage createObjectMessage(Serializable serializable) throws JMSException {
+    public ObjectMessage createObjectMessage(Serializable serializable) throws JMSException
+    {
         return _session.createObjectMessage();
     }
 
-    public StreamMessage createStreamMessage() throws JMSException {
+    public StreamMessage createStreamMessage() throws JMSException
+    {
         return _session.createStreamMessage();
     }
 
-    public TextMessage createTextMessage() throws JMSException {
+    public TextMessage createTextMessage() throws JMSException
+    {
         return _session.createTextMessage();
     }
 
-    public TextMessage createTextMessage(String string) throws JMSException {
-        return _session.createTextMessage();
+    public TextMessage createTextMessage(String string) throws JMSException
+    {
+        return _session.createTextMessage(string);
     }
 
-    public boolean getTransacted() throws JMSException {
+    public boolean getTransacted() throws JMSException
+    {
         return _session.getTransacted();
     }
 
-    public int getAcknowledgeMode() throws JMSException {
+    public int getAcknowledgeMode() throws JMSException
+    {
         return _session.getAcknowledgeMode();
     }
 
-    public void commit() throws JMSException {
+    public void commit() throws JMSException
+    {
         _session.commit();
     }
 
-    public void rollback() throws JMSException {
+    public void rollback() throws JMSException
+    {
         _session.rollback();
     }
 
-    public void close() throws JMSException {
+    public void close() throws JMSException
+    {
         _session.close();
     }
 
-    public void recover() throws JMSException {
+    public void recover() throws JMSException
+    {
         _session.recover();
     }
 
-    public MessageListener getMessageListener() throws JMSException {
+    public MessageListener getMessageListener() throws JMSException
+    {
         return _session.getMessageListener();
     }
 
-    public void setMessageListener(MessageListener messageListener) throws JMSException {
+    public void setMessageListener(MessageListener messageListener) throws JMSException
+    {
         _session.setMessageListener(messageListener);
     }
 
-    public void run() {
+    public void run()
+    {
         _session.run();
     }
 
-    public MessageProducer createProducer(Destination destination) throws JMSException {
+    public MessageProducer createProducer(Destination destination) throws JMSException
+    {
         return _session.createProducer(destination);
     }
 
-    public MessageConsumer createConsumer(Destination destination) throws JMSException {
+    public MessageConsumer createConsumer(Destination destination) throws JMSException
+    {
         return _session.createConsumer(destination);
     }
 
-    public MessageConsumer createConsumer(Destination destination, String string) throws JMSException {
+    public MessageConsumer createConsumer(Destination destination, String string) throws JMSException
+    {
         return _session.createConsumer(destination, string);
     }
 
-    public MessageConsumer createConsumer(Destination destination, String string, boolean b) throws JMSException {
+    public MessageConsumer createConsumer(Destination destination, String string, boolean b) throws JMSException
+    {
         return _session.createConsumer(destination, string, b);
     }
 
     //The following methods cannot be called from a TopicSession as per JMS spec
-    public Queue createQueue(String string) throws JMSException {
+    public Queue createQueue(String string) throws JMSException
+    {
         throw new IllegalStateException("Cannot call createQueue from TopicSession");
     }
 
-    public QueueBrowser createBrowser(Queue queue) throws JMSException {
+    public QueueBrowser createBrowser(Queue queue) throws JMSException
+    {
         throw new IllegalStateException("Cannot call createBrowser from TopicSession");
     }
 
-    public QueueBrowser createBrowser(Queue queue, String string) throws JMSException {
+    public QueueBrowser createBrowser(Queue queue, String string) throws JMSException
+    {
         throw new IllegalStateException("Cannot call createBrowser from TopicSession");
     }
 
-    public TemporaryQueue createTemporaryQueue() throws JMSException {
+    public TemporaryQueue createTemporaryQueue() throws JMSException
+    {
         throw new IllegalStateException("Cannot call createTemporaryQueue from TopicSession");
     }
 

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java Mon Dec 18 05:02:27 2006
@@ -7,9 +7,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -159,11 +159,13 @@
 
     public String getMessageSelector() throws JMSException
     {
+    	checkPreConditions();
         return _messageSelector;
     }
 
     public MessageListener getMessageListener() throws JMSException
     {
+    	checkPreConditions();
         return (MessageListener) _messageListener.get();
     }
 
@@ -179,7 +181,7 @@
 
     public void setMessageListener(MessageListener messageListener) throws JMSException
     {
-        checkNotClosed();
+    	checkPreConditions();
 
         //if the current listener is non-null and the session is not stopped, then
         //it is an error to call this method.
@@ -212,10 +214,10 @@
             {
                 //handle case where connection has already been started, and the dispatcher is blocked
                 //doing a put on the _synchronousQueue
-                Object msg = _synchronousQueue.poll();
-                if (msg != null)
+                AbstractJMSMessage jmsMsg = (AbstractJMSMessage)_synchronousQueue.poll();
+                if (jmsMsg != null)
                 {
-                    AbstractJMSMessage jmsMsg = (AbstractJMSMessage) msg;
+                    _session.setLastDeliveredMessage(jmsMsg);
                     messageListener.onMessage(jmsMsg);
                     postDeliver(jmsMsg);
                 }
@@ -277,8 +279,8 @@
 
     public Message receive(long l) throws JMSException
     {
-        checkNotClosed();
-
+    	checkPreConditions();
+        
         acquireReceiving();
 
         try
@@ -295,12 +297,15 @@
             final AbstractJMSMessage m = returnMessageOrThrow(o);
             if (m != null)
             {
+                _session.setLastDeliveredMessage(m);
                 postDeliver(m);
             }
+            
             return m;
         }
         catch (InterruptedException e)
         {
+            _logger.warn("Interrupted: " + e, e);
             return null;
         }
         finally
@@ -311,7 +316,7 @@
 
     public Message receiveNoWait() throws JMSException
     {
-        checkNotClosed();
+    	checkPreConditions();
 
         acquireReceiving();
 
@@ -321,8 +326,10 @@
             final AbstractJMSMessage m = returnMessageOrThrow(o);
             if (m != null)
             {
+                _session.setLastDeliveredMessage(m);
                 postDeliver(m);
             }
+
             return m;
         }
         finally
@@ -421,6 +428,7 @@
             {
                 //we do not need a lock around the test above, and the dispatch below as it is invalid
                 //for an application to alter an installed listener while the session is started
+                _session.setLastDeliveredMessage(jmsMessage);
                 getMessageListener().onMessage(jmsMessage);
                 postDeliver(jmsMessage);
             }
@@ -457,8 +465,9 @@
         }
     }
 
-    private void postDeliver(AbstractJMSMessage msg)
+    private void postDeliver(AbstractJMSMessage msg) throws JMSException
     {
+    	msg.setJMSDestination(_destination);
         switch (_acknowledgeMode)
         {
             case Session.DUPS_OK_ACKNOWLEDGE:
@@ -520,7 +529,7 @@
      */
     private void deregisterConsumer()
     {
-        _session.deregisterConsumer(_consumerTag);
+    	_session.deregisterConsumer(this);
     }
 
     public String getConsumerTag()
@@ -532,4 +541,17 @@
     {
         _consumerTag = consumerTag;
     }
+
+	public AMQSession getSession() {
+		return _session;
+	}
+
+	private void checkPreConditions() throws JMSException{
+
+		this.checkNotClosed();
+
+		if(_session == null || _session.isClosed()){
+			throw new javax.jms.IllegalStateException("Invalid Session");
+		}
+	}
 }

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java Mon Dec 18 05:02:27 2006
@@ -7,9 +7,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -28,11 +28,9 @@
 import org.apache.qpid.client.protocol.AMQProtocolHandler;
 import org.apache.qpid.framing.*;
 
-import javax.jms.DeliveryMode;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
+import javax.jms.*;
 import java.io.UnsupportedEncodingException;
+import java.util.Enumeration;
 
 public class BasicMessageProducer extends Closeable implements org.apache.qpid.jms.MessageProducer
 {
@@ -102,6 +100,7 @@
     private final boolean _mandatory;
 
     private final boolean _waitUntilSent;
+    private static final ContentBody[] NO_CONTENT_BODIES = new ContentBody[0];
 
     protected BasicMessageProducer(AMQConnection connection, AMQDestination destination, boolean transacted,
                                    int channelId, AMQSession session, AMQProtocolHandler protocolHandler,
@@ -143,6 +142,7 @@
 
     public void setDisableMessageID(boolean b) throws JMSException
     {
+        checkPreConditions();
         checkNotClosed();
         // IGNORED
     }
@@ -156,7 +156,7 @@
 
     public void setDisableMessageTimestamp(boolean b) throws JMSException
     {
-        checkNotClosed();
+        checkPreConditions();
         _disableTimestamps = b;
     }
 
@@ -168,11 +168,11 @@
 
     public void setDeliveryMode(int i) throws JMSException
     {
-        checkNotClosed();
+        checkPreConditions();
         if (i != DeliveryMode.NON_PERSISTENT && i != DeliveryMode.PERSISTENT)
         {
             throw new JMSException("DeliveryMode must be either NON_PERSISTENT or PERSISTENT. Value of " + i +
-                                   " is illegal");
+                    " is illegal");
         }
         _deliveryMode = i;
     }
@@ -185,7 +185,7 @@
 
     public void setPriority(int i) throws JMSException
     {
-        checkNotClosed();
+        checkPreConditions();
         if (i < 0 || i > 9)
         {
             throw new IllegalArgumentException("Priority of " + i + " is illegal. Value must be in range 0 to 9");
@@ -201,7 +201,7 @@
 
     public void setTimeToLive(long l) throws JMSException
     {
-        checkNotClosed();
+        checkPreConditions();
         if (l < 0)
         {
             throw new IllegalArgumentException("Time to live must be non-negative - supplied value was " + l);
@@ -229,27 +229,36 @@
 
     public void send(Message message) throws JMSException
     {
+        checkPreConditions();
+        checkInitialDestination();
+
+
         synchronized (_connection.getFailoverMutex())
         {
-            sendImpl(_destination, (AbstractJMSMessage) message, _deliveryMode, _messagePriority, _timeToLive,
+            sendImpl(_destination, message, _deliveryMode, _messagePriority, _timeToLive,
                      _mandatory, _immediate);
         }
     }
 
     public void send(Message message, int deliveryMode) throws JMSException
     {
+        checkPreConditions();
+        checkInitialDestination();
+
         synchronized (_connection.getFailoverMutex())
         {
-            sendImpl(_destination, (AbstractJMSMessage) message, deliveryMode, _messagePriority, _timeToLive,
+            sendImpl(_destination, message, deliveryMode, _messagePriority, _timeToLive,
                      _mandatory, _immediate);
         }
     }
 
     public void send(Message message, int deliveryMode, boolean immediate) throws JMSException
     {
+        checkPreConditions();
+        checkInitialDestination();
         synchronized (_connection.getFailoverMutex())
         {
-            sendImpl(_destination, (AbstractJMSMessage) message, deliveryMode, _messagePriority, _timeToLive,
+            sendImpl(_destination, message, deliveryMode, _messagePriority, _timeToLive,
                      _mandatory, immediate);
         }
     }
@@ -257,20 +266,23 @@
     public void send(Message message, int deliveryMode, int priority,
                      long timeToLive) throws JMSException
     {
+        checkPreConditions();
+        checkInitialDestination();
         synchronized (_connection.getFailoverMutex())
         {
-            sendImpl(_destination, (AbstractJMSMessage)message, deliveryMode, priority, timeToLive, _mandatory,
+            sendImpl(_destination, message, deliveryMode, priority, timeToLive, _mandatory,
                      _immediate);
         }
     }
 
     public void send(Destination destination, Message message) throws JMSException
     {
-        checkNotClosed();
+        checkPreConditions();
+        checkDestination(destination);
         synchronized (_connection.getFailoverMutex())
         {
             validateDestination(destination);
-            sendImpl((AMQDestination) destination, (AbstractJMSMessage) message, _deliveryMode, _messagePriority, _timeToLive,
+            sendImpl((AMQDestination) destination, message, _deliveryMode, _messagePriority, _timeToLive,
                      _mandatory, _immediate);
         }
     }
@@ -279,11 +291,12 @@
                      int priority, long timeToLive)
             throws JMSException
     {
-        checkNotClosed();
+        checkPreConditions();
+        checkDestination(destination);
         synchronized (_connection.getFailoverMutex())
         {
             validateDestination(destination);
-            sendImpl((AMQDestination) destination, (AbstractJMSMessage) message, deliveryMode, priority, timeToLive,
+            sendImpl((AMQDestination) destination, message, deliveryMode, priority, timeToLive,
                      _mandatory, _immediate);
         }
     }
@@ -292,11 +305,12 @@
                      int priority, long timeToLive, boolean mandatory)
             throws JMSException
     {
-        checkNotClosed();
+        checkPreConditions();
+        checkDestination(destination);
         synchronized (_connection.getFailoverMutex())
         {
             validateDestination(destination);
-            sendImpl((AMQDestination) destination, (AbstractJMSMessage) message, deliveryMode, priority, timeToLive,
+            sendImpl((AMQDestination) destination, message, deliveryMode, priority, timeToLive,
                      mandatory, _immediate);
         }
     }
@@ -305,11 +319,12 @@
                      int priority, long timeToLive, boolean mandatory, boolean immediate)
             throws JMSException
     {
-        checkNotClosed();
+        checkPreConditions();
+        checkDestination(destination);
         synchronized (_connection.getFailoverMutex())
         {
             validateDestination(destination);
-            sendImpl((AMQDestination) destination, (AbstractJMSMessage) message, deliveryMode, priority, timeToLive,
+            sendImpl((AMQDestination) destination, message, deliveryMode, priority, timeToLive,
                      mandatory, immediate);
         }
     }
@@ -319,26 +334,158 @@
                      boolean immediate, boolean waitUntilSent)
             throws JMSException
     {
-        checkNotClosed();
+        checkPreConditions();
+        checkDestination(destination);
         synchronized (_connection.getFailoverMutex())
         {
             validateDestination(destination);
-            sendImpl((AMQDestination) destination, (AbstractJMSMessage) message, deliveryMode, priority, timeToLive,
+            sendImpl((AMQDestination) destination, message, deliveryMode, priority, timeToLive,
                      mandatory, immediate, waitUntilSent);
         }
     }
 
+
+    private AbstractJMSMessage convertToNativeMessage(Message message) throws JMSException
+    {
+        if (message instanceof AbstractJMSMessage)
+        {
+            return (AbstractJMSMessage) message;
+        }
+        else
+        {
+            AbstractJMSMessage newMessage;
+
+            if (message instanceof BytesMessage)
+            {
+                BytesMessage bytesMessage = (BytesMessage) message;
+                bytesMessage.reset();
+
+                JMSBytesMessage nativeMsg = (JMSBytesMessage) _session.createBytesMessage();
+
+
+                byte[] buf = new byte[1024];
+
+                int len;
+
+                while ((len = bytesMessage.readBytes(buf)) != -1)
+                {
+                    nativeMsg.writeBytes(buf, 0, len);
+                }
+
+                newMessage = nativeMsg;
+            }
+            else if (message instanceof MapMessage)
+            {
+                MapMessage origMessage = (MapMessage) message;
+                MapMessage nativeMessage = _session.createMapMessage();
+
+                Enumeration mapNames = origMessage.getMapNames();
+                while (mapNames.hasMoreElements())
+                {
+                    String name = (String) mapNames.nextElement();
+                    nativeMessage.setObject(name, origMessage.getObject(name));
+                }
+                newMessage = (AbstractJMSMessage) nativeMessage;
+            }
+            else if (message instanceof ObjectMessage)
+            {
+                ObjectMessage origMessage = (ObjectMessage) message;
+                ObjectMessage nativeMessage = _session.createObjectMessage();
+
+                nativeMessage.setObject(origMessage.getObject());
+
+                newMessage = (AbstractJMSMessage) nativeMessage;
+            }
+            else if (message instanceof TextMessage)
+            {
+                TextMessage origMessage = (TextMessage) message;
+                TextMessage nativeMessage = _session.createTextMessage();
+
+                nativeMessage.setText(origMessage.getText());
+
+                newMessage = (AbstractJMSMessage) nativeMessage;
+            }
+            else if (message instanceof StreamMessage)
+            {
+                StreamMessage origMessage = (StreamMessage) message;
+                StreamMessage nativeMessage = _session.createStreamMessage();
+
+
+                try
+                {
+                    origMessage.reset();
+                    while (true)
+                    {
+                        nativeMessage.writeObject(origMessage.readObject());
+                    }
+                }
+                catch (MessageEOFException e)
+                {
+                    ;//
+                }
+                newMessage = (AbstractJMSMessage) nativeMessage;
+            }
+            else
+            {
+                newMessage = (AbstractJMSMessage) _session.createMessage();
+
+            }
+
+            Enumeration propertyNames = message.getPropertyNames();
+            while (propertyNames.hasMoreElements())
+            {
+                String propertyName = String.valueOf(propertyNames.nextElement());
+                if (!propertyName.startsWith("JMSX_"))
+                {
+                    Object value = message.getObjectProperty(propertyName);
+                    newMessage.setObjectProperty(propertyName, value);
+                }
+            }
+
+            newMessage.setJMSDeliveryMode(message.getJMSDeliveryMode());
+
+
+            int priority = message.getJMSPriority();
+            if (priority < 0)
+            {
+                priority = 0;
+            }
+            else if (priority > 9)
+            {
+                priority = 9;
+            }
+
+            newMessage.setJMSPriority(priority);
+            if (message.getJMSReplyTo() != null)
+            {
+                newMessage.setJMSReplyTo(message.getJMSReplyTo());
+            }
+            newMessage.setJMSType(message.getJMSType());
+
+
+            if (newMessage != null)
+            {
+                return newMessage;
+            }
+            else
+            {
+                throw new JMSException("Unable to send message, due to class conversion error: " + message.getClass().getName());
+            }
+        }
+    }
+
+
     private void validateDestination(Destination destination) throws JMSException
     {
         if (!(destination instanceof AMQDestination))
         {
             throw new JMSException("Unsupported destination class: " +
-                                   (destination != null ? destination.getClass() : null));
+                    (destination != null ? destination.getClass() : null));
         }
-        declareDestination((AMQDestination)destination);
+        declareDestination((AMQDestination) destination);
     }
 
-    protected void sendImpl(AMQDestination destination, AbstractJMSMessage message, int deliveryMode, int priority,
+    protected void sendImpl(AMQDestination destination, Message message, int deliveryMode, int priority,
                             long timeToLive, boolean mandatory, boolean immediate) throws JMSException
     {
         sendImpl(destination, message, deliveryMode, priority, timeToLive, mandatory, immediate, _waitUntilSent);
@@ -346,8 +493,9 @@
 
     /**
      * The caller of this method must hold the failover mutex.
+     *
      * @param destination
-     * @param message
+     * @param origMessage
      * @param deliveryMode
      * @param priority
      * @param timeToLive
@@ -355,9 +503,12 @@
      * @param immediate
      * @throws JMSException
      */
-    protected void sendImpl(AMQDestination destination, AbstractJMSMessage message, int deliveryMode, int priority,
+    protected void sendImpl(AMQDestination destination, Message origMessage, int deliveryMode, int priority,
                             long timeToLive, boolean mandatory, boolean immediate, boolean wait) throws JMSException
     {
+        checkTemporaryDestination(destination);
+
+        AbstractJMSMessage message = convertToNativeMessage(origMessage);
         AMQFrame publishFrame = BasicPublishBody.createAMQFrame(_channelId, 0, destination.getExchangeName(),
                                                                 destination.getRoutingKey(), mandatory, immediate);
 
@@ -367,17 +518,7 @@
             currentTime = System.currentTimeMillis();
             message.setJMSTimestamp(currentTime);
         }
-        //
-        // Very nasty temporary hack for GRM-206. Will be altered ASAP.
-        //
-        if (message instanceof JMSBytesMessage)
-        {
-            JMSBytesMessage msg = (JMSBytesMessage) message;
-            if (!msg.isReadable())
-            {
-                msg.reset();
-            }
-        }
+        message.prepareForSending();
         ByteBuffer payload = message.getData();
         BasicContentHeaderProperties contentHeaderProperties = message.getJmsContentHeaderProperties();
 
@@ -398,7 +539,7 @@
         contentHeaderProperties.setDeliveryMode((byte) deliveryMode);
         contentHeaderProperties.setPriority((byte) priority);
 
-        int size = payload.limit();
+        int size = (payload != null) ? payload.limit() : 0;
         ContentBody[] contentBodies = createContentBodies(payload);
         AMQFrame[] frames = new AMQFrame[2 + contentBodies.length];
         for (int i = 0; i < contentBodies.length; i++)
@@ -423,24 +564,52 @@
         frames[1] = contentHeaderFrame;
         CompositeAMQDataBlock compositeFrame = new CompositeAMQDataBlock(frames);
         _protocolHandler.writeFrame(compositeFrame, wait);
+
+
+        if (message != origMessage)
+        {
+            _logger.warn("Updating original message");
+            origMessage.setJMSPriority(message.getJMSPriority());
+            origMessage.setJMSTimestamp(message.getJMSTimestamp());
+            _logger.warn("Setting JMSExpiration:" + message.getJMSExpiration());
+            origMessage.setJMSExpiration(message.getJMSExpiration());
+            origMessage.setJMSMessageID(message.getJMSMessageID());
+        }
+    }
+
+    private void checkTemporaryDestination(AMQDestination destination) throws JMSException
+    {
+        if(destination instanceof TemporaryDestination)
+        {
+            _logger.debug("destination is temporary destination");
+            TemporaryDestination tempDest = (TemporaryDestination) destination;
+            if(tempDest.getSession().isClosed())
+            {
+                _logger.debug("session is closed");
+                throw new JMSException("Session for temporary destination has been closed");
+            }
+            if(tempDest.isDeleted())
+            {
+                _logger.debug("destination is deleted");
+                throw new JMSException("Cannot send to a deleted temporary destination");
+            }
+        }
     }
 
     /**
      * Create content bodies. This will split a large message into numerous bodies depending on the negotiated
      * maximum frame size.
+     *
      * @param payload
      * @return the array of content bodies
      */
     private ContentBody[] createContentBodies(ByteBuffer payload)
     {
-        if (payload == null)
+        if (payload == null || payload.remaining() == 0)
         {
-            return null;
-        }
-        else if (payload.remaining() == 0)
-        {
-            return new ContentBody[0];
+            return NO_CONTENT_BODIES;
         }
+
         // we substract one from the total frame maximum size to account for the end of frame marker in a body frame
         // (0xCE byte).
         int dataLength = payload.remaining();
@@ -460,8 +629,8 @@
             for (int i = 0; i < bodies.length; i++)
             {
                 bodies[i] = new ContentBody();
-                payload.position((int)framePayloadMax * i);
-                int length = (remaining >= framePayloadMax) ? (int)framePayloadMax : (int)remaining;
+                payload.position((int) framePayloadMax * i);
+                int length = (remaining >= framePayloadMax) ? (int) framePayloadMax : (int) remaining;
                 payload.limit(payload.position() + length);
                 bodies[i].payload = payload.slice();
                 remaining -= length;
@@ -480,5 +649,44 @@
     {
         checkNotClosed();
         _encoding = encoding;
+    }
+
+    private void checkPreConditions() throws javax.jms.IllegalStateException, JMSException
+    {
+        checkNotClosed();
+
+        if (_session == null || _session.isClosed())
+        {
+            throw new javax.jms.IllegalStateException("Invalid Session");
+        }
+    }
+
+    private void checkInitialDestination()
+    {
+        if (_destination == null)
+        {
+            throw new UnsupportedOperationException("Destination is null");
+        }
+    }
+
+    private void checkDestination(Destination suppliedDestination) throws InvalidDestinationException
+    {
+        if (_destination != null && suppliedDestination != null)
+        {
+            throw new UnsupportedOperationException("This message producer was created with a Destination, therefore you cannot use an unidentified Destination");
+        }
+
+        if (suppliedDestination == null)
+        {
+            throw new InvalidDestinationException("Supplied Destination was invalid");
+        }
+
+
+    }
+
+
+    public AMQSession getSession()
+    {
+        return _session;
     }
 }

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/QueueReceiverAdaptor.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/QueueReceiverAdaptor.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/QueueReceiverAdaptor.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/QueueReceiverAdaptor.java Mon Dec 18 05:02:27 2006
@@ -39,31 +39,37 @@
 
     public String getMessageSelector() throws JMSException
     {
+    	checkPreConditions();
         return _consumer.getMessageSelector();
     }
 
     public MessageListener getMessageListener() throws JMSException
     {
+    	checkPreConditions();
         return _consumer.getMessageListener();
     }
 
     public void setMessageListener(MessageListener messageListener) throws JMSException
     {
+    	checkPreConditions();
        _consumer.setMessageListener(messageListener);
     }
 
     public Message receive() throws JMSException
     {
+    	checkPreConditions();
         return _consumer.receive();
     }
 
     public Message receive(long l) throws JMSException
     {
+    	checkPreConditions();
         return _consumer.receive(l);
     }
 
     public Message receiveNoWait() throws JMSException
     {
+    	checkPreConditions();
         return _consumer.receiveNoWait();
     }
 
@@ -79,8 +85,26 @@
      */
     public Queue getQueue() throws JMSException
     {
+    	checkPreConditions();
        return _queue;
     }
 
+    private void checkPreConditions() throws javax.jms.IllegalStateException {
+    	BasicMessageConsumer msgConsumer = (BasicMessageConsumer)_consumer;
+    	
+    	if (msgConsumer.isClosed() ){
+			throw new javax.jms.IllegalStateException("Consumer is closed");
+		}
+		
+		if(_queue == null){
+			throw new UnsupportedOperationException("Queue is null");
+		}
+		
+		AMQSession session = msgConsumer.getSession();
+		
+		if(session == null || session.isClosed()){
+			throw new javax.jms.IllegalStateException("Invalid Session");
+		}
+	}
 
 }

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/QueueSenderAdapter.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/QueueSenderAdapter.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/QueueSenderAdapter.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/QueueSenderAdapter.java Mon Dec 18 05:02:27 2006
@@ -1,6 +1,7 @@
 package org.apache.qpid.client;
 
 import javax.jms.Destination;
+import javax.jms.IllegalStateException;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageProducer;
@@ -9,96 +10,136 @@
 
 public class QueueSenderAdapter implements QueueSender {
 
-	private MessageProducer delegate;
-	private Queue queue;
+	private MessageProducer _delegate;
+	private Queue _queue;
+	private boolean closed = false;
 	
 	public QueueSenderAdapter(MessageProducer msgProducer, Queue queue){
-		delegate = msgProducer;
-		this.queue = queue;
+		_delegate = msgProducer;
+		_queue = queue;
 	}
 	
 	public Queue getQueue() throws JMSException {
-		return queue;
+		checkPreConditions();
+		return _queue;
 	}
 
 	public void send(Message msg) throws JMSException {
-		delegate.send(msg);
+		checkPreConditions();
+		_delegate.send(msg);
 	}
 
 	public void send(Queue queue, Message msg) throws JMSException {
-		delegate.send(queue, msg);
+		checkPreConditions(queue);
+		_delegate.send(queue, msg);
 	}
 
 	public void publish(Message msg, int deliveryMode, int priority, long timeToLive)
 	throws JMSException {
-		
-		delegate.send(msg, deliveryMode,priority,timeToLive);
+		checkPreConditions();
+		_delegate.send(msg, deliveryMode,priority,timeToLive);
 	}
 
 	public void send(Queue queue,Message msg, int deliveryMode, int priority, long timeToLive)
 			throws JMSException {
-		
-		delegate.send(queue,msg, deliveryMode,priority,timeToLive);
+		checkPreConditions(queue);
+		_delegate.send(queue,msg, deliveryMode,priority,timeToLive);
 	}
 	
 	public void close() throws JMSException {
-		delegate.close();
+		_delegate.close();
+		closed = true;
 	}
 
 	public int getDeliveryMode() throws JMSException {
-		return delegate.getDeliveryMode();
+		checkPreConditions();
+		return _delegate.getDeliveryMode();
 	}
 
 	public Destination getDestination() throws JMSException {
-		return delegate.getDestination();
+		checkPreConditions();
+		return _delegate.getDestination();
 	}
 
 	public boolean getDisableMessageID() throws JMSException {
-		return delegate.getDisableMessageID();
+		checkPreConditions();
+		return _delegate.getDisableMessageID();
 	}
 
 	public boolean getDisableMessageTimestamp() throws JMSException {
-		return delegate.getDisableMessageTimestamp();
+		checkPreConditions();
+		return _delegate.getDisableMessageTimestamp();
 	}
 
 	public int getPriority() throws JMSException {
-		return delegate.getPriority();
+		checkPreConditions();
+		return _delegate.getPriority();
 	}
 
 	public long getTimeToLive() throws JMSException {
-		return delegate.getTimeToLive();
+		checkPreConditions();
+		return _delegate.getTimeToLive();
 	}
 
 	public void send(Destination dest, Message msg) throws JMSException {
-		delegate.send(dest,msg);
+		checkPreConditions((Queue)dest);
+		_delegate.send(dest,msg);
 	}
 
 	public void send(Message msg, int deliveryMode, int priority, long timeToLive)
 			throws JMSException {
-		delegate.send(msg, deliveryMode,priority,timeToLive);
+		checkPreConditions();
+		_delegate.send(msg, deliveryMode,priority,timeToLive);
 	}
 
 	public void send(Destination dest, Message msg, int deliveryMode, int priority, long timeToLive) throws JMSException {
-		delegate.send(dest,msg, deliveryMode,priority,timeToLive);
+		checkPreConditions((Queue)dest);
+		_delegate.send(dest,msg, deliveryMode,priority,timeToLive);
 	}
 
 	public void setDeliveryMode(int deliveryMode) throws JMSException {
-		delegate.setDeliveryMode(deliveryMode);
+		checkPreConditions();
+		_delegate.setDeliveryMode(deliveryMode);
 	}
 
 	public void setDisableMessageID(boolean disableMessageID) throws JMSException {
-		delegate.setDisableMessageID(disableMessageID);
+		checkPreConditions();
+		_delegate.setDisableMessageID(disableMessageID);
 	}
 
 	public void setDisableMessageTimestamp(boolean disableMessageTimestamp) throws JMSException {
-		delegate.setDisableMessageTimestamp(disableMessageTimestamp);
+		checkPreConditions();
+		_delegate.setDisableMessageTimestamp(disableMessageTimestamp);
 	}
 
 	public void setPriority(int priority) throws JMSException {
-		delegate.setPriority(priority);
+		checkPreConditions();
+		_delegate.setPriority(priority);
 	}
 
 	public void setTimeToLive(long timeToLive) throws JMSException {
-		delegate.setTimeToLive(timeToLive);
+		checkPreConditions();
+		_delegate.setTimeToLive(timeToLive);
+	}
+
+    private void checkPreConditions() throws IllegalStateException, IllegalStateException
+    {
+        checkPreConditions(_queue);
+    }
+
+    private void checkPreConditions(Queue queue) throws IllegalStateException, IllegalStateException {
+		if (closed){
+			throw new javax.jms.IllegalStateException("Publisher is closed");
+		}
+		
+		if(queue == null){
+			throw new UnsupportedOperationException("Queue is null");
+		}
+		
+		AMQSession session = ((BasicMessageProducer) _delegate).getSession();
+		
+		if(session == null || session.isClosed()){
+			throw new javax.jms.IllegalStateException("Invalid Session");
+		}
 	}
 }

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java Mon Dec 18 05:02:27 2006
@@ -1,107 +1,174 @@
 package org.apache.qpid.client;
 
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.Topic;
-import javax.jms.TopicPublisher;
+import javax.jms.*;
+import javax.jms.IllegalStateException;
 
-public class TopicPublisherAdapter implements TopicPublisher {
+public class TopicPublisherAdapter implements TopicPublisher
+{
 
-	private MessageProducer delegate;
-	private Topic topic;
-	
-	public TopicPublisherAdapter(MessageProducer msgProducer, Topic topic){
-		delegate = msgProducer;
-		this.topic = topic;
-	}
-	
-	public Topic getTopic() throws JMSException {
-		return topic;
-	}
-
-	public void publish(Message msg) throws JMSException {
-		delegate.send(msg);
-	}
-
-	public void publish(Topic topic, Message msg) throws JMSException {
-		delegate.send(topic,msg);
-	}
-
-	public void publish(Message msg, int deliveryMode, int priority, long timeToLive)
-			throws JMSException {
-		delegate.send(msg, deliveryMode,priority,timeToLive);
-	}
+    private BasicMessageProducer _delegate;
+    private Topic _topic;
 
-	public void publish(Topic topic, Message msg, int deliveryMode, int priority, long timeToLive)
-			throws JMSException {
-		delegate.send(topic,msg, deliveryMode,priority,timeToLive);
-	}
-
-	public void close() throws JMSException {
-		delegate.close();
-	}
+    public TopicPublisherAdapter(BasicMessageProducer msgProducer, Topic topic)
+    {
+        _delegate = msgProducer;
+        _topic = topic;
+    }
+
+    public Topic getTopic() throws JMSException
+    {
+        checkPreConditions();
+        return _topic;
+    }
+
+    public void publish(Message msg) throws JMSException
+    {
+        checkPreConditions();
+        checkTopic(_topic);
+        _delegate.send(msg);
+    }
+
+    public void publish(Topic topic, Message msg) throws JMSException
+    {
+        checkPreConditions();
+        checkTopic(topic);
+        _delegate.send(topic, msg);
+    }
+
+    public void publish(Message msg, int deliveryMode, int priority, long timeToLive)
+            throws JMSException
+    {
+        checkPreConditions();
+        checkTopic(_topic);
+        _delegate.send(msg, deliveryMode, priority, timeToLive);
+    }
 
 	public int getDeliveryMode() throws JMSException {
-		return delegate.getDeliveryMode();
+		checkPreConditions();
+		return _delegate.getDeliveryMode();
 	}
 
-	public Destination getDestination() throws JMSException {
-		return delegate.getDestination();
-	}
+	public void publish(Topic topic, Message msg, int deliveryMode, int priority, long timeToLive)
+            throws JMSException
+    {
+        checkPreConditions();
+        checkTopic(topic);
+        _delegate.send(topic, msg, deliveryMode, priority, timeToLive);
+    }
+
+	public void close() throws JMSException
+    {
+        _delegate.close();
+    }
 
 	public boolean getDisableMessageID() throws JMSException {
-		return delegate.getDisableMessageID();
+		checkPreConditions();
+		return _delegate.getDisableMessageID();
 	}
 
 	public boolean getDisableMessageTimestamp() throws JMSException {
-		return delegate.getDisableMessageTimestamp();
-	}
-
-	public int getPriority() throws JMSException {
-		return delegate.getPriority();
-	}
-
-	public long getTimeToLive() throws JMSException {
-		return delegate.getTimeToLive();
+		checkPreConditions();
+		return _delegate.getDisableMessageTimestamp();
 	}
-
-	public void send(Message msg) throws JMSException {
-		delegate.send(msg);
-	}
-
-	public void send(Destination dest, Message msg) throws JMSException {
-		delegate.send(dest,msg);
-	}
-
-	public void send(Message msg, int deliveryMode, int priority, long timeToLive)
-			throws JMSException {
-		delegate.send(msg, deliveryMode,priority,timeToLive);
-	}
-
-	public void send(Destination dest, Message msg, int deliveryMode, int priority, long timeToLive) throws JMSException {
-		delegate.send(dest,msg, deliveryMode,priority,timeToLive);
-	}
-
-	public void setDeliveryMode(int deliveryMode) throws JMSException {
-		delegate.setDeliveryMode(deliveryMode);
-	}
-
-	public void setDisableMessageID(boolean disableMessageID) throws JMSException {
-		delegate.setDisableMessageID(disableMessageID);
-	}
-
-	public void setDisableMessageTimestamp(boolean disableMessageTimestamp) throws JMSException {
-		delegate.setDisableMessageTimestamp(disableMessageTimestamp);
-	}
-
-	public void setPriority(int priority) throws JMSException {
-		delegate.setPriority(priority);
-	}
-
-	public void setTimeToLive(long timeToLive) throws JMSException {
-		delegate.setTimeToLive(timeToLive);
-	}
-
+	
+    public Destination getDestination() throws JMSException
+    {
+		checkPreConditions();
+        return _delegate.getDestination();
+    }
+
+    public int getPriority() throws JMSException {
+		checkPreConditions();
+		return _delegate.getPriority();
+	}
+
+    public long getTimeToLive() throws JMSException {
+		checkPreConditions();
+		return _delegate.getTimeToLive();
+	}
+    
+    public void send(Message msg) throws JMSException
+    {
+        checkPreConditions();
+        checkTopic(_topic);
+        _delegate.send(msg);
+    }
+
+    public void send(Destination dest, Message msg) throws JMSException
+    {
+        checkPreConditions();
+        checkTopic(_topic);
+        _delegate.send(dest, msg);
+    }
+
+    public void send(Message msg, int deliveryMode, int priority, long timeToLive)
+            throws JMSException
+    {
+        checkPreConditions();
+        checkTopic(_topic);
+        _delegate.send(msg, deliveryMode, priority, timeToLive);
+    }
+
+    public void send(Destination dest, Message msg, int deliveryMode, int priority, long timeToLive) throws JMSException
+    {
+        checkPreConditions();
+        checkTopic(dest);
+        _delegate.send(dest, msg, deliveryMode, priority, timeToLive);
+    }
+
+    public void setDeliveryMode(int deliveryMode) throws JMSException
+    {
+        checkPreConditions();
+        _delegate.setDeliveryMode(deliveryMode);
+    }
+
+    public void setDisableMessageID(boolean disableMessageID) throws JMSException
+    {
+        checkPreConditions();
+        _delegate.setDisableMessageID(disableMessageID);
+    }
+
+    public void setDisableMessageTimestamp(boolean disableMessageTimestamp) throws JMSException
+    {
+        checkPreConditions();
+        _delegate.setDisableMessageTimestamp(disableMessageTimestamp);
+    }
+
+    public void setPriority(int priority) throws JMSException
+    {
+        checkPreConditions();
+        _delegate.setPriority(priority);
+    }
+
+    public void setTimeToLive(long timeToLive) throws JMSException
+    {
+        checkPreConditions();
+        _delegate.setTimeToLive(timeToLive);
+    }
+
+    private void checkPreConditions() throws IllegalStateException
+    {
+        if (_delegate.isClosed())
+        {
+            throw new javax.jms.IllegalStateException("Publisher is _closed");
+        }
+
+        AMQSession session = _delegate.getSession();
+        if (session == null || session.isClosed())
+        {
+            throw new javax.jms.IllegalStateException("Invalid Session");
+        }
+    }
+
+    private void checkTopic(Destination topic) throws InvalidDestinationException
+    {
+        if (topic == null)
+        {
+            throw new UnsupportedOperationException("Topic is null");
+        }
+        if (!(topic instanceof Topic))
+        {
+            throw new InvalidDestinationException("Destination " + topic + " is not a topic");
+        }
+    }
 }

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/TopicSubscriberAdaptor.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/TopicSubscriberAdaptor.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/TopicSubscriberAdaptor.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/TopicSubscriberAdaptor.java Mon Dec 18 05:02:27 2006
@@ -20,6 +20,7 @@
  */
 package org.apache.qpid.client;
 
+import javax.jms.IllegalStateException;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
@@ -34,46 +35,54 @@
 class TopicSubscriberAdaptor implements TopicSubscriber
 {
     private final Topic _topic;
-    private final MessageConsumer _consumer;
+    private final BasicMessageConsumer _consumer;
     private final boolean _noLocal;
 
-    TopicSubscriberAdaptor(Topic topic, MessageConsumer consumer, boolean noLocal)
+    TopicSubscriberAdaptor(Topic topic, BasicMessageConsumer consumer, boolean noLocal)
     {
         _topic = topic;
         _consumer = consumer;
         _noLocal = noLocal;
     }
+    
     TopicSubscriberAdaptor(Topic topic, BasicMessageConsumer consumer)
     {
         this(topic, consumer, consumer.isNoLocal());
     }
+    
     public Topic getTopic() throws JMSException
     {
+    	checkPreConditions();
         return _topic;
     }
 
     public boolean getNoLocal() throws JMSException
     {
+    	checkPreConditions();
         return _noLocal;
     }
 
     public String getMessageSelector() throws JMSException
     {
+    	checkPreConditions();
         return _consumer.getMessageSelector();
     }
 
     public MessageListener getMessageListener() throws JMSException
     {
+    	checkPreConditions();
         return _consumer.getMessageListener();
     }
 
     public void setMessageListener(MessageListener messageListener) throws JMSException
     {
+    	checkPreConditions();
         _consumer.setMessageListener(messageListener);
     }
 
     public Message receive() throws JMSException
     {
+    	checkPreConditions();
         return _consumer.receive();
     }
 
@@ -84,6 +93,7 @@
 
     public Message receiveNoWait() throws JMSException
     {
+    	checkPreConditions();
         return _consumer.receiveNoWait();
     }
 
@@ -91,4 +101,28 @@
     {
         _consumer.close();
     }
+    
+    private void checkPreConditions() throws javax.jms.IllegalStateException{
+    	BasicMessageConsumer msgConsumer = (BasicMessageConsumer)_consumer;
+    	
+    	if (msgConsumer.isClosed() ){
+			throw new javax.jms.IllegalStateException("Consumer is closed");
+		}
+		
+		if(_topic == null){
+			throw new UnsupportedOperationException("Topic is null");
+		}
+		
+		AMQSession session = msgConsumer.getSession();
+		
+		if(session == null || session.isClosed()){
+			throw new javax.jms.IllegalStateException("Invalid Session");
+		}
+	}
+
+    BasicMessageConsumer getMessageConsumer()
+    {
+        return _consumer;
+    }
+
 }

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java Mon Dec 18 05:02:27 2006
@@ -23,6 +23,7 @@
 import org.apache.log4j.Logger;
 import org.apache.qpid.AMQChannelClosedException;
 import org.apache.qpid.AMQException;
+import org.apache.qpid.AMQInvalidSelectorException;
 import org.apache.qpid.client.AMQNoConsumersException;
 import org.apache.qpid.client.AMQNoRouteException;
 import org.apache.qpid.protocol.AMQConstant;
@@ -46,7 +47,7 @@
 
     public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
     {
-         _logger.debug("ChannelClose method received");
+        _logger.debug("ChannelClose method received");
         ChannelCloseBody method = (ChannelCloseBody) evt.getMethod();
 
         int errorCode = method.replyCode;
@@ -65,17 +66,21 @@
             {
                 throw new AMQNoConsumersException("Error: " + reason, null);
             }
+            else if (errorCode == AMQConstant.NO_ROUTE.getCode())
+            {
+                throw new AMQNoRouteException("Error: " + reason, null);
+            }
+            else if (errorCode == AMQConstant.INVALID_SELECTOR.getCode())
+            {
+                _logger.info("Broker responded with Invalid Selector.");
+
+                throw new AMQInvalidSelectorException(reason);
+            }
             else
             {
-                if (errorCode == AMQConstant.NO_ROUTE.getCode())
-                {
-                   throw new AMQNoRouteException("Error: " + reason, null);
-                }
-                else
-                {
-                    throw new AMQChannelClosedException(errorCode, "Error: " + reason);
-                }
+                throw new AMQChannelClosedException(errorCode, "Error: " + reason);
             }
+
         }
         evt.getProtocolSession().channelClosed(evt.getChannelId(), errorCode, reason);
     }

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java Mon Dec 18 05:02:27 2006
@@ -23,6 +23,7 @@
 import org.apache.log4j.Logger;
 import org.apache.qpid.AMQException;
 import org.apache.qpid.AMQConnectionClosedException;
+import org.apache.qpid.AMQInvalidSelectorException;
 import org.apache.qpid.protocol.AMQConstant;
 import org.apache.qpid.client.protocol.AMQMethodEvent;
 import org.apache.qpid.client.state.AMQState;

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/message/AMQMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/message/AMQMessage.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/message/AMQMessage.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/message/AMQMessage.java Mon Dec 18 05:02:27 2006
@@ -7,9 +7,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -23,6 +23,8 @@
 import org.apache.qpid.framing.ContentHeaderProperties;
 import org.apache.qpid.client.AMQSession;
 
+import javax.jms.JMSException;
+
 public class AMQMessage
 {
     protected ContentHeaderProperties _contentHeaderProperties;
@@ -67,5 +69,13 @@
     public long getDeliveryTag()
     {
         return _deliveryTag;
-    }       
+    }
+
+    /**
+     * Invoked prior to sending the message. Allows the message to be modified if necessary before
+     * sending.
+     */
+    public void prepareForSending() throws JMSException
+    {
+    }
 }

Modified: incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java?view=diff&rev=488262&r1=488261&r2=488262
==============================================================================
--- incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java (original)
+++ incubator/qpid/branches/jmsselectors/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java Mon Dec 18 05:02:27 2006
@@ -7,9 +7,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -23,24 +23,27 @@
 import org.apache.commons.collections.map.ReferenceMap;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.qpid.AMQException;
+import org.apache.qpid.url.BindingURL;
+import org.apache.qpid.url.AMQBindingURL;
+import org.apache.qpid.url.URLSyntaxException;
 import org.apache.qpid.client.AMQDestination;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQTopic;
 import org.apache.qpid.client.JmsNotImplementedException;
 import org.apache.qpid.framing.BasicContentHeaderProperties;
 import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.framing.FieldTableFactory;
+import org.apache.qpid.framing.JMSPropertyFieldTable;
 
 import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.MessageNotReadableException;
 import javax.jms.MessageNotWriteableException;
+import javax.jms.MessageFormatException;
 import java.util.Collections;
 import java.util.Enumeration;
-import java.util.Iterator;
 import java.util.Map;
 
-public abstract class AbstractJMSMessage extends AMQMessage implements javax.jms.Message
+public abstract class AbstractJMSMessage extends AMQMessage implements org.apache.qpid.jms.Message
 {
     private static final Map _destinationCache = Collections.synchronizedMap(new ReferenceMap());
 
@@ -49,7 +52,8 @@
     protected ByteBuffer _data;
     private boolean _readableProperties = false;
     private boolean _readableMessage = false;
-
+    private Destination _destination;
+    
     protected AbstractJMSMessage(ByteBuffer data)
     {
         super(new BasicContentHeaderProperties());
@@ -58,8 +62,7 @@
         {
             _data.acquire();
         }
-        // ContentHeaderProperties are just created and so are empty
-        //_readableProperties = (_contentHeaderProperties != null);
+        _readableProperties = false;
         _readableMessage = (data != null);
     }
 
@@ -137,19 +140,16 @@
             Destination dest = (Destination) _destinationCache.get(replyToEncoding);
             if (dest == null)
             {
-                char destType = replyToEncoding.charAt(0);
-                if (destType == 'Q')
-                {
-                    dest = new AMQQueue(replyToEncoding.substring(1));
-                }
-                else if (destType == 'T')
+                try
                 {
-                    dest = new AMQTopic(replyToEncoding.substring(1));
+                    BindingURL binding = new AMQBindingURL(replyToEncoding);
+                    dest = AMQDestination.createDestination(binding);
                 }
-                else
+                catch (URLSyntaxException e)
                 {
                     throw new JMSException("Illegal value in JMS_ReplyTo property: " + replyToEncoding);
                 }
+
                 _destinationCache.put(replyToEncoding, dest);
             }
             return dest;
@@ -164,7 +164,7 @@
         }
         if (!(destination instanceof AMQDestination))
         {
-            throw new IllegalArgumentException("ReplyTo destination my be an AMQ destination - passed argument was type " +
+            throw new IllegalArgumentException("ReplyTo destination may only be an AMQDestination - passed argument was type " +
                                                destination.getClass());
         }
         final AMQDestination amqd = (AMQDestination) destination;
@@ -177,12 +177,12 @@
     public Destination getJMSDestination() throws JMSException
     {
         // TODO: implement this once we have sorted out how to figure out the exchange class
-        throw new JmsNotImplementedException();
+    	return _destination;
     }
 
     public void setJMSDestination(Destination destination) throws JMSException
     {
-        throw new JmsNotImplementedException();
+    	_destination = destination;
     }
 
     public int getJMSDeliveryMode() throws JMSException
@@ -207,14 +207,12 @@
 
     public String getJMSType() throws JMSException
     {
-        //fixme wrong QPID-152
-        return getMimeType();
+        return getJmsContentHeaderProperties().getType();
     }
 
     public void setJMSType(String string) throws JMSException
     {
-        //throw new JMSException("Cannot set JMS Type - it is implicitly defined based on message type");
-        // this is not spec comliant, should not throw the message
+        getJmsContentHeaderProperties().setType(string);
     }
 
     public long getJMSExpiration() throws JMSException
@@ -239,7 +237,7 @@
 
     public void clearProperties() throws JMSException
     {
-        getJmsContentHeaderProperties().getHeaders().clear();
+        getJmsContentHeaderProperties().getJMSHeaders().clear();
 
         _readableProperties = false;
     }
@@ -254,150 +252,163 @@
     public boolean propertyExists(String propertyName) throws JMSException
     {
         checkPropertyName(propertyName);
-        return getJmsContentHeaderProperties().getHeaders().propertyExists(propertyName);
+        return getJmsContentHeaderProperties().getJMSHeaders().propertyExists(propertyName);
     }
 
     public boolean getBooleanProperty(String propertyName) throws JMSException
     {
         checkPropertyName(propertyName);
 
-        if (getJmsContentHeaderProperties() == null)
-        {
-            System.out.println("HEADERS ARE NULL");
-        }
-
-
-        return getJmsContentHeaderProperties().getHeaders().getBoolean(propertyName);
+        return getJmsContentHeaderProperties().getJMSHeaders().getBoolean(propertyName);
     }
 
     public byte getByteProperty(String propertyName) throws JMSException
     {
         checkPropertyName(propertyName);
-        return getJmsContentHeaderProperties().getHeaders().getByte(propertyName);
+        return getJmsContentHeaderProperties().getJMSHeaders().getByte(propertyName);
     }
 
     public short getShortProperty(String propertyName) throws JMSException
     {
         checkPropertyName(propertyName);
-        return getJmsContentHeaderProperties().getHeaders().getShort(propertyName);
+        return getJmsContentHeaderProperties().getJMSHeaders().getShort(propertyName);
     }
 
     public int getIntProperty(String propertyName) throws JMSException
     {
         checkPropertyName(propertyName);
-        return getJmsContentHeaderProperties().getHeaders().getInteger(propertyName);
+        return getJmsContentHeaderProperties().getJMSHeaders().getInteger(propertyName);
     }
 
     public long getLongProperty(String propertyName) throws JMSException
     {
         checkPropertyName(propertyName);
-        return getJmsContentHeaderProperties().getHeaders().getLong(propertyName);
+        return getJmsContentHeaderProperties().getJMSHeaders().getLong(propertyName);
     }
 
     public float getFloatProperty(String propertyName) throws JMSException
     {
         checkPropertyName(propertyName);
-        return getJmsContentHeaderProperties().getHeaders().getFloat(propertyName);
+        return getJmsContentHeaderProperties().getJMSHeaders().getFloat(propertyName);
     }
 
     public double getDoubleProperty(String propertyName) throws JMSException
     {
         checkPropertyName(propertyName);
-        return getJmsContentHeaderProperties().getHeaders().getDouble(propertyName);
+        return getJmsContentHeaderProperties().getJMSHeaders().getDouble(propertyName);
     }
 
     public String getStringProperty(String propertyName) throws JMSException
     {
         checkPropertyName(propertyName);
-        return getJmsContentHeaderProperties().getHeaders().getString(propertyName);
+        return getJmsContentHeaderProperties().getJMSHeaders().getString(propertyName);
     }
 
     public Object getObjectProperty(String propertyName) throws JMSException
     {
         checkPropertyName(propertyName);
-        return getJmsContentHeaderProperties().getHeaders().getObject(propertyName);
+        return getJmsContentHeaderProperties().getJMSHeaders().getObject(propertyName);
     }
 
     public Enumeration getPropertyNames() throws JMSException
     {
-        return getJmsContentHeaderProperties().getHeaders().getPropertyNames();
+        return getJmsContentHeaderProperties().getJMSHeaders().getPropertyNames();
     }
 
     public void setBooleanProperty(String propertyName, boolean b) throws JMSException
     {
         checkWritableProperties();
         checkPropertyName(propertyName);
-        getJmsContentHeaderProperties().getHeaders().setBoolean(propertyName, b);
+        getJmsContentHeaderProperties().getJMSHeaders().setBoolean(propertyName, b);
     }
 
     public void setByteProperty(String propertyName, byte b) throws JMSException
     {
         checkWritableProperties();
         checkPropertyName(propertyName);
-        getJmsContentHeaderProperties().getHeaders().setByte(propertyName, new Byte(b));
+        getJmsContentHeaderProperties().getJMSHeaders().setByte(propertyName, new Byte(b));
     }
 
     public void setShortProperty(String propertyName, short i) throws JMSException
     {
         checkWritableProperties();
         checkPropertyName(propertyName);
-        getJmsContentHeaderProperties().getHeaders().setShort(propertyName, new Short(i));
+        getJmsContentHeaderProperties().getJMSHeaders().setShort(propertyName, new Short(i));
     }
 
     public void setIntProperty(String propertyName, int i) throws JMSException
     {
         checkWritableProperties();
         checkPropertyName(propertyName);
-        getJmsContentHeaderProperties().getHeaders().setInteger(propertyName, new Integer(i));
+        getJmsContentHeaderProperties().getJMSHeaders().setInteger(propertyName, new Integer(i));
     }
 
     public void setLongProperty(String propertyName, long l) throws JMSException
     {
         checkWritableProperties();
         checkPropertyName(propertyName);
-        getJmsContentHeaderProperties().getHeaders().setLong(propertyName, new Long(l));
+        getJmsContentHeaderProperties().getJMSHeaders().setLong(propertyName, new Long(l));
     }
 
     public void setFloatProperty(String propertyName, float f) throws JMSException
     {
         checkWritableProperties();
         checkPropertyName(propertyName);
-        getJmsContentHeaderProperties().getHeaders().setFloat(propertyName, new Float(f));
+        getJmsContentHeaderProperties().getJMSHeaders().setFloat(propertyName, new Float(f));
     }
 
     public void setDoubleProperty(String propertyName, double v) throws JMSException
     {
         checkWritableProperties();
         checkPropertyName(propertyName);
-        getJmsContentHeaderProperties().getHeaders().setDouble(propertyName, new Double(v));
+        getJmsContentHeaderProperties().getJMSHeaders().setDouble(propertyName, new Double(v));
     }
 
     public void setStringProperty(String propertyName, String value) throws JMSException
     {
         checkWritableProperties();
         checkPropertyName(propertyName);
-        getJmsContentHeaderProperties().getHeaders().setString(propertyName, value);
+        getJmsContentHeaderProperties().getJMSHeaders().setString(propertyName, value);
     }
 
     public void setObjectProperty(String propertyName, Object object) throws JMSException
     {
         checkWritableProperties();
         checkPropertyName(propertyName);
-        getJmsContentHeaderProperties().getHeaders().setObject(propertyName, object);
+        getJmsContentHeaderProperties().getJMSHeaders().setObject(propertyName, object);
     }
 
-    public void acknowledge() throws JMSException
+    protected void removeProperty(String propertyName) throws JMSException
+    {
+        checkPropertyName(propertyName);
+        getJmsContentHeaderProperties().getJMSHeaders().remove(propertyName);
+    }
+
+    public void acknowledgeThis() throws JMSException
     {
         // the JMS 1.1 spec says in section 3.6 that calls to acknowledge are ignored when client acknowledge
         // is not specified. In our case, we only set the session field where client acknowledge mode is specified.
         if (_session != null)
         {
+            if (_session.getAMQConnection().isClosed())
+            {
+                throw new javax.jms.IllegalStateException("Connection is already closed");
+            }
+
             // we set multiple to true here since acknowledgement implies acknowledge of all previous messages
             // received on the session
             _session.acknowledgeMessage(_deliveryTag, true);
         }
     }
 
+    public void acknowledge() throws JMSException
+    {
+        if(_session != null)
+        {
+            _session.acknowledge();
+        }
+    }
+
 
     /**
      * This forces concrete classes to implement clearBody()
@@ -425,23 +436,15 @@
             buf.append("\nJMS priority: ").append(getJMSPriority());
             buf.append("\nJMS delivery mode: ").append(getJMSDeliveryMode());
             buf.append("\nJMS reply to: ").append(String.valueOf(getJMSReplyTo()));
-            buf.append("\nJMS Type: ").append(String.valueOf(getJMSType()));
-            buf.append("\nJMS CorrelationID: ").append(String.valueOf(getJMSCorrelationID()));
-            buf.append("\nJMS Destination: NOT IMPLEMENTED");//.append(String.valueOf(getJMSDestination()));
-            buf.append("\nJMS MessageID: ").append(String.valueOf(getJMSMessageID()));
-            buf.append("\nJMS Redelivered: ").append(String.valueOf(getJMSRedelivered()));
-            buf.append("\nProperty Names: ").append(String.valueOf(getPropertyNames()));
-
             buf.append("\nAMQ message number: ").append(_deliveryTag);
-
             buf.append("\nProperties:");
-            if (getJmsContentHeaderProperties().getHeaders().isEmpty())
+            if (getJmsContentHeaderProperties().getJMSHeaders().isEmpty())
             {
                 buf.append("<NONE>");
             }
             else
             {
-                buf.append('\n').append(getJmsContentHeaderProperties().getHeaders());
+                buf.append('\n').append(getJmsContentHeaderProperties().getJMSHeaders());
             }
             return buf.toString();
         }
@@ -471,34 +474,6 @@
         {
             throw new IllegalArgumentException("Property name must not be the empty string");
         }
-
-        // Call to ensure that the it has been set.
-        getJmsContentHeaderProperties().getHeaders();
-    }
-
-    public FieldTable populateHeadersFromMessageProperties()
-    {
-        //
-        // We need to convert every property into a String representation
-        // Note that type information is preserved in the property name
-        //
-        final FieldTable table = FieldTableFactory.newFieldTable();
-        final Iterator entries = getJmsContentHeaderProperties().getHeaders().entrySet().iterator();
-        while (entries.hasNext())
-        {
-            final Map.Entry entry = (Map.Entry) entries.next();
-            final String propertyName = (String) entry.getKey();
-            if (propertyName == null)
-            {
-                continue;
-            }
-            else
-            {
-                table.put(propertyName, entry.getValue().toString());
-            }
-        }
-        return table;
-
     }
 
     public BasicContentHeaderProperties getJmsContentHeaderProperties()
@@ -512,7 +487,7 @@
         // position beyond the start
         if (_data != null)
         {
-            _data.rewind();
+            reset();
         }
         return _data;
     }
@@ -551,9 +526,16 @@
         return !_readableMessage;
     }
 
-    public void reset() throws JMSException
+    public void reset() 
     {
-        _readableMessage = true;
+        if (_readableMessage)
+        {
+            _data.rewind();
+        }
+        else
+        {
+            _data.flip();
+            _readableMessage = true;
+        }
     }
-
 }