servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r463723 - in /incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix: components/util/MessageHelper.java components/util/PojoSupport.java jbi/messaging/NormalizedMessageImpl.java
Date Fri, 13 Oct 2006 16:03:59 GMT
Author: jstrachan
Date: Fri Oct 13 09:03:58 2006
New Revision: 463723

URL: http://svn.apache.org/viewvc?view=rev&rev=463723
Log:
Added a couple of helper classes to make it a little easier to extract the body of a message
as a POJO

Added:
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/components/util/MessageHelper.java
Modified:
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/components/util/PojoSupport.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/NormalizedMessageImpl.java

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/components/util/MessageHelper.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/components/util/MessageHelper.java?view=auto&rev=463723
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/components/util/MessageHelper.java
(added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/components/util/MessageHelper.java
Fri Oct 13 09:03:58 2006
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.components.util;
+
+import org.apache.servicemix.JavaSource;
+import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
+import org.apache.servicemix.jbi.messaging.PojoMarshaler;
+
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+
+/**
+ * Some helper methods for working with messages
+ *
+ * @version $Revision: $
+ */
+public class MessageHelper {
+
+    /**
+     * A helper method to return the body of the message as a POJO which could be a
+     * bean or some DOMish model of the body.
+     *
+     * @param message the message on which to extract the body
+     * @return the body of the message as a POJO or DOM object
+     * @throws javax.jbi.messaging.MessagingException
+     *
+     */
+    public static Object getBody(NormalizedMessage message) throws MessagingException {
+        Source content = message.getContent();
+        if (content instanceof JavaSource) {
+            JavaSource source = (JavaSource) content;
+            return source.getObject();
+        }
+        if (message instanceof NormalizedMessageImpl) {
+            return ((NormalizedMessageImpl) message).getBody();
+        }
+        return message.getProperty(PojoMarshaler.BODY);
+    }
+
+    /**
+     * A helper method to return the body of the message as a POJO which could be a
+     * bean or some DOMish model of the body.
+     *
+     * @param message    the message on which to extract the body
+     * @param marshaller the marshaller used to map from the XML representation to the POJO
+     * @return the body of the message as a POJO or DOM object
+     * @throws javax.jbi.messaging.MessagingException
+     *
+     */
+    public static Object getBody(NormalizedMessage message, PojoMarshaler marshaller) throws
MessagingException {
+        Source content = message.getContent();
+        if (content instanceof JavaSource) {
+            JavaSource source = (JavaSource) content;
+            return source.getObject();
+        }
+        if (message instanceof NormalizedMessageImpl) {
+            return ((NormalizedMessageImpl) message).getBody(marshaller);
+        }
+        return message.getProperty(PojoMarshaler.BODY);
+    }
+
+    /**
+     * Sets the body of the message as a POJO
+     *
+     * @param message the message on which to set the body
+     * @param body    the POJO or DOMish model to set
+     * @throws MessagingException
+     */
+    public static void setBody(NormalizedMessage message, Object body) throws MessagingException
{
+        Source content = message.getContent();
+        if (content instanceof JavaSource) {
+            JavaSource source = (JavaSource) content;
+            source.setObject(body);
+        }
+        else if (message instanceof NormalizedMessageImpl) {
+            ((NormalizedMessageImpl) message).setBody(body);
+        }
+        else {
+            message.setProperty(PojoMarshaler.BODY, body);
+        }
+    }
+
+}

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/components/util/PojoSupport.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/components/util/PojoSupport.java?view=diff&rev=463723&r1=463722&r2=463723
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/components/util/PojoSupport.java
(original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/components/util/PojoSupport.java
Fri Oct 13 09:03:58 2006
@@ -16,32 +16,19 @@
  */
 package org.apache.servicemix.components.util;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.FaultException;
+import org.apache.servicemix.jbi.NotInitialisedYetException;
+import org.apache.servicemix.jbi.management.BaseLifeCycle;
+
 import javax.jbi.JBIException;
 import javax.jbi.component.ComponentContext;
 import javax.jbi.component.ComponentLifeCycle;
-import javax.jbi.messaging.DeliveryChannel;
-import javax.jbi.messaging.ExchangeStatus;
-import javax.jbi.messaging.Fault;
-import javax.jbi.messaging.InOnly;
-import javax.jbi.messaging.InOptionalOut;
-import javax.jbi.messaging.InOut;
-import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.MessageExchangeFactory;
-import javax.jbi.messaging.MessagingException;
-import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.*;
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.management.ObjectName;
 import javax.xml.namespace.QName;
-import javax.xml.transform.Source;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.JavaSource;
-import org.apache.servicemix.jbi.FaultException;
-import org.apache.servicemix.jbi.NotInitialisedYetException;
-import org.apache.servicemix.jbi.management.BaseLifeCycle;
-import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
-import org.apache.servicemix.jbi.messaging.PojoMarshaler;
 
 /**
  * A useful base class for a POJO based JBI component which contains most of the basic plumbing
@@ -118,15 +105,7 @@
      * @throws MessagingException
      */
     public Object getBody(NormalizedMessage message) throws MessagingException {
-        Source content = message.getContent();
-        if (content instanceof JavaSource) {
-            JavaSource source = (JavaSource) content;
-            return source.getObject();
-        }
-        if (message instanceof NormalizedMessageImpl) {
-            return ((NormalizedMessageImpl) message).getBody();
-        }
-        return message.getProperty(PojoMarshaler.BODY);
+        return MessageHelper.getBody(message);
     }
 
     /**
@@ -137,17 +116,7 @@
      * @throws MessagingException
      */
     public void setBody(NormalizedMessage message, Object body) throws MessagingException
{
-        Source content = message.getContent();
-        if (content instanceof JavaSource) {
-            JavaSource source = (JavaSource) content;
-            source.setObject(body);
-        }
-        else if (message instanceof NormalizedMessageImpl) {
-            ((NormalizedMessageImpl) message).setBody(body);
-        }
-        else {
-            message.setProperty(PojoMarshaler.BODY, body);
-        }
+        MessageHelper.setBody(message, body);
     }
 
 

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/NormalizedMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/NormalizedMessageImpl.java?view=diff&rev=463723&r1=463722&r2=463723
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/NormalizedMessageImpl.java
(original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/NormalizedMessageImpl.java
Fri Oct 13 09:03:58 2006
@@ -16,16 +16,14 @@
  */
 package org.apache.servicemix.jbi.messaging;
 
-import java.io.ByteArrayOutputStream;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
+import org.apache.servicemix.client.Message;
+import org.apache.servicemix.jbi.RuntimeJBIException;
+import org.apache.servicemix.jbi.jaxp.BytesSource;
+import org.apache.servicemix.jbi.jaxp.ResourceSource;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.util.ByteArrayDataSource;
+import org.apache.servicemix.jbi.util.FileUtil;
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
@@ -38,15 +36,8 @@
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamSource;
-
-import org.apache.servicemix.client.Message;
-import org.apache.servicemix.jbi.RuntimeJBIException;
-import org.apache.servicemix.jbi.jaxp.BytesSource;
-import org.apache.servicemix.jbi.jaxp.ResourceSource;
-import org.apache.servicemix.jbi.jaxp.SourceTransformer;
-import org.apache.servicemix.jbi.jaxp.StringSource;
-import org.apache.servicemix.jbi.util.ByteArrayDataSource;
-import org.apache.servicemix.jbi.util.FileUtil;
+import java.io.*;
+import java.util.*;
 
 /**
  * Represents a JBI NormalizedMessage.
@@ -232,6 +223,10 @@
             body = getMarshaler().unmarshal(exchange, this);
         }
         return body;
+    }
+
+    public Object getBody(PojoMarshaler marshaler) throws MessagingException {
+        return marshaler.unmarshal(exchange, this);
     }
 
     public void setBody(Object body) throws MessagingException {



Mime
View raw message