activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r521186 - in /activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms: DefaultJmsExchange.java DefaultJmsMessage.java JmsEndpoint.java JmsExchange.java JmsMessage.java
Date Thu, 22 Mar 2007 10:17:08 GMT
Author: jstrachan
Date: Thu Mar 22 03:16:55 2007
New Revision: 521186

URL: http://svn.apache.org/viewvc?view=rev&rev=521186
Log:
tidied up the JMS component to avoid unnecessary interfaces

Removed:
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultJmsExchange.java
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultJmsMessage.java
Modified:
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java?view=diff&rev=521186&r1=521185&r2=521186
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
(original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
Thu Mar 22 03:16:55 2007
@@ -31,7 +31,7 @@
 import javax.jms.Session;
 
 /**
- * @version $Revision$
+ * @version $Revision:520964 $
  */
 public class JmsEndpoint extends DefaultEndpoint<JmsExchange> implements MessageListener
{
     private static final Log log = LogFactory.getLog(JmsEndpoint.class);
@@ -80,12 +80,12 @@
     }
 
     public JmsExchange createExchange() {
-        return new DefaultJmsExchange(getContext());
+        return new JmsExchange(getContext());
     }
 
 
     public JmsExchange createExchange(Message message) {
-        return new DefaultJmsExchange(getContext(), message);
+        return new JmsExchange(getContext(), message);
     }
 
 

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java?view=diff&rev=521186&r1=521185&r2=521186
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java
(original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java
Thu Mar 22 03:16:55 2007
@@ -16,20 +16,67 @@
  */
 package org.apache.camel.component.jms;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
 
-import javax.jms.Session;
-import javax.jms.Message;
 import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
 
 /**
- * @version $Revision$
+ * Represents an {@ilnk Exchange} for working with JMS
+ * 
+ * @version $Revision:520964 $
  */
-public interface JmsExchange extends Exchange {
+public class JmsExchange extends DefaultExchange {
+
+    public JmsExchange(CamelContext container) {
+        super(container);
+    }
+
+    public JmsExchange(CamelContext container, Message message) {
+        super(container);
+        setIn(new JmsMessage(message));
+    }
+
+    @Override
+    public Exchange newInstance() {
+        return new JmsExchange(getContext());
+    }
+
+    public Message createMessage(Session session) throws JMSException {
+        Message request = getInMessage();
+        if (request == null) {
+            request = session.createMessage();
+
+            /** TODO
+            if (lazyHeaders != null) {
+                // lets add any lazy headers
+                for (Map.Entry<String, Object> entry : lazyHeaders.entrySet()) {
+                    request.setObjectProperty(entry.getKey(), entry.getValue());
+                }
+            }
+             */
+        }
+        return request;
+    }
+
+    public Message getInMessage() {
+        JmsMessage jmsMessage = (JmsMessage) getIn();
+        if (jmsMessage != null) {
+            return jmsMessage.getJmsMessage();
+        }
+        return null;
+    }
+
+    @Override
+    protected org.apache.camel.Message createInMessage() {
+        return new JmsMessage();
+    }
 
-    /**
-     * Creates the JMS message for this exchange so that it can be sent to
-     * a JMS endpoint.
-     */
-    Message createMessage(Session session) throws JMSException;
+    @Override
+    protected org.apache.camel.Message createOutMessage() {
+        return new JmsMessage();
+    }
 }

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java?view=diff&rev=521186&r1=521185&r2=521186
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
(original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
Thu Mar 22 03:16:55 2007
@@ -17,17 +17,103 @@
  */
 package org.apache.camel.component.jms;
 
-import org.apache.camel.Message;
+import org.apache.camel.InvalidHeaderTypeException;
+import org.apache.camel.impl.MessageSupport;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
- * @version $Revision$
+ * Represents a {@link org.apache.camel.Message} for working with JMS
+ * 
+ * @version $Revision:520964 $
  */
-public interface JmsMessage extends Message {
+public class JmsMessage extends MessageSupport {
+    private Message jmsMessage;
+    private Map<String, Object> lazyHeaders;
+
+    public JmsMessage() {
+    }
+
+    public JmsMessage(Message jmsMessage) {
+        this.jmsMessage = jmsMessage;
+    }
+
+    public Message getJmsMessage() {
+        return jmsMessage;
+    }
+
+    public void setJmsMessage(Message jmsMessage) {
+        this.jmsMessage = jmsMessage;
+    }
+
+    public Object getHeader(String name) {
+        if (jmsMessage != null) {
+            try {
+                Object value = jmsMessage.getObjectProperty(name);
+                try {
+                    return value;
+                }
+                catch (ClassCastException e) {
+                    throw new InvalidHeaderTypeException(e.getMessage(), value);
+                }
+            }
+            catch (JMSException e) {
+                throw new MessagePropertyAcessException(name, e);
+            }
+        }
+        return null;
+    }
+
+    public void setHeader(String name, Object value) {
+        if (jmsMessage != null) {
+            try {
+                jmsMessage.setObjectProperty(name, value);
+            }
+            catch (JMSException e) {
+                throw new MessagePropertyAcessException(name, e);
+            }
+        }
+        else {
+            if (lazyHeaders == null) {
+                lazyHeaders = new HashMap<String, Object>();
+            }
+            lazyHeaders.put(name, value);
+        }
+    }
 
-    /**
-     * Accesses the underlying JMS message
-     */
-    public javax.jms.Message getJmsMessage();
+    public Map<String, Object> getHeaders() {
+        if (jmsMessage != null) {
+            Map<String, Object> answer = new HashMap<String, Object>();
+            Enumeration names;
+            try {
+                names = jmsMessage.getPropertyNames();
+            }
+            catch (JMSException e) {
+                throw new MessagePropertyNamesAcessException(e);
+            }
+            while (names.hasMoreElements()) {
+                String name = names.nextElement().toString();
+                try {
+                    Object value = jmsMessage.getObjectProperty(name);
+                    answer.put(name, value);
+                }
+                catch (JMSException e) {
+                    throw new MessagePropertyAcessException(name, e);
+                }
+            }
+            return answer;
+        }
+        else {
+            return lazyHeaders;
+        }
+    }
 
-    void setJmsMessage(javax.jms.Message jmsMessage);
+    @Override
+    public JmsMessage newInstance() {
+        return new JmsMessage();
+    }
 }



Mime
View raw message