You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/10/10 12:33:43 UTC

svn commit: r583419 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/model/dataform...

Author: jstrachan
Date: Wed Oct 10 03:33:34 2007
New Revision: 583419

URL: http://svn.apache.org/viewvc?rev=583419&view=rev
Log:
minor refactorings and improvements in the javadoc together with an initial implementation of the XmlBeans DataFormat

Added:
    activemq/camel/trunk/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java   (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataTypeExpression.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSDataFormat.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataTypeExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataTypeExpression.java?rev=583419&r1=583418&r2=583419&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataTypeExpression.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataTypeExpression.java Wed Oct 10 03:33:34 2007
@@ -74,7 +74,7 @@
 
     /**
      * Uses the
-     * <a href="http://www.iona.com/artix/ds">Artix Data Services</a>
+     * <a href="http://activemq.apache.org/camel/artix-data-services.html">Artix Data Services</a>
      * data format for dealing with lots of different message formats such as SWIFT etc.
      */
     public T artixDS() {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java?rev=583419&r1=583418&r2=583419&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java Wed Oct 10 03:33:34 2007
@@ -28,6 +28,9 @@
 import org.apache.camel.spi.DataFormat;
 
 /**
+ * The <a href="http://activemq.apache.org/camel/data-format.html">data format</a>
+ * using Java Serialiation.
+ *
  * @version $Revision: 1.1 $
  */
 public class SerializationDataFormat implements DataFormat {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java?rev=583419&r1=583418&r2=583419&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java Wed Oct 10 03:33:34 2007
@@ -49,6 +49,10 @@
         this.dataFormatType = dataFormatType;
     }
 
+    public MarshalType(String ref) {
+        this.ref = ref;
+    }
+
     @Override
     public String toString() {
         if (dataFormatType != null) {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?rev=583419&r1=583418&r2=583419&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java Wed Oct 10 03:33:34 2007
@@ -33,11 +33,11 @@
 import org.apache.camel.Route;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.Builder;
+import org.apache.camel.builder.DataTypeExpression;
 import org.apache.camel.builder.DeadLetterChannelBuilder;
 import org.apache.camel.builder.ErrorHandlerBuilder;
 import org.apache.camel.builder.NoErrorHandlerBuilder;
 import org.apache.camel.builder.ProcessorBuilder;
-import org.apache.camel.builder.DataTypeExpression;
 import org.apache.camel.converter.ObjectConverter;
 import org.apache.camel.impl.RouteContext;
 import org.apache.camel.model.dataformat.DataFormatType;
@@ -52,6 +52,7 @@
 import org.apache.camel.processor.idempotent.MessageIdRepository;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.Policy;
+import org.apache.camel.spi.Registry;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -730,30 +731,89 @@
 
     // DataFormat support
     // -------------------------------------------------------------------------
+
+    /**
+     * Unmarshals the in body using a {@link DataFormat} expression to define
+     * the format of the input message and the output will be set on the out message body.
+     *
+     * @return the expression to create the {@link DataFormat}
+     */
     public DataTypeExpression<Type> unmarshal() {
         return new DataTypeExpression<Type>(this, DataTypeExpression.Operation.Unmarshal);
     }
 
+    /**
+     * Unmarshals the in body using the specified {@link DataFormat}
+     * and sets the output on the out message body.
+     *
+     * @return this object
+     */
     public Type unmarshal(DataFormatType dataFormatType) {
         addOutput(new UnmarshalType(dataFormatType));
         return (Type) this;
     }
 
+    /**
+     * Unmarshals the in body using the specified {@link DataFormat}
+     * and sets the output on the out message body.
+     *
+     * @return this object
+     */
     public Type unmarshal(DataFormat dataFormat) {
         return unmarshal(new DataFormatType(dataFormat));
     }
 
+    /**
+     * Unmarshals the in body using the specified {@link DataFormat}
+     * reference in the {@link Registry} and sets the output on the out message body.
+     *
+     * @return this object
+     */
+    public Type unmarshal(String dataTypeRef) {
+        addOutput(new UnmarshalType(dataTypeRef));
+        return (Type) this;
+    }
+
+    /**
+     * Marshals the in body using a {@link DataFormat} expression to define
+     * the format of the output which will be added to the out body.
+     *
+     * @return the expression to create the {@link DataFormat}
+     */
     public DataTypeExpression<Type> marshal() {
         return new DataTypeExpression<Type>(this, DataTypeExpression.Operation.Marshal);
     }
 
+    /**
+     * Marshals the in body using the specified {@link DataFormat}
+     * and sets the output on the out message body.
+     *
+     * @return this object
+     */
     public Type marshal(DataFormatType dataFormatType) {
         addOutput(new MarshalType(dataFormatType));
         return (Type) this;
     }
 
+    /**
+     * Marshals the in body using the specified {@link DataFormat}
+     * and sets the output on the out message body.
+     *
+     * @return this object
+     */
     public Type marshal(DataFormat dataFormat) {
         return marshal(new DataFormatType(dataFormat));
+    }
+
+    /**
+     * Marshals the in body the specified {@link DataFormat}
+     * reference in the {@link Registry} and sets the output on the out message body.
+     *
+     * @return this object
+     */
+    public Type marshal(String dataTypeRef) {
+        addOutput(new MarshalType(dataTypeRef));
+        return (Type) this;
     }
 
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java?rev=583419&r1=583418&r2=583419&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java Wed Oct 10 03:33:34 2007
@@ -49,6 +49,10 @@
         this.dataFormatType = dataFormatType;
     }
 
+    public UnmarshalType(String ref) {
+        this.ref = ref;
+    }
+
     @Override
     public String toString() {
         if (dataFormatType != null) {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSDataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSDataFormat.java?rev=583419&r1=583418&r2=583419&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSDataFormat.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSDataFormat.java Wed Oct 10 03:33:34 2007
@@ -25,7 +25,7 @@
 import org.apache.camel.spi.DataFormat;
 
 /**
- * Represents the <a href="http://www.iona.com/artix/ds">Artix Data Services</a>
+ * Represents the <a href="http://activemq.apache.org/camel/artix-data-services.html">Artix Data Services</a>
  * {@link DataFormat}
  *
  * @version $Revision: 1.1 $

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java?rev=583419&r1=583418&r2=583419&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java Wed Oct 10 03:33:34 2007
@@ -25,7 +25,8 @@
 import org.apache.camel.spi.DataFormat;
 
 /**
- * Marshals the body of the incoming message using the given data format
+ * Marshals the body of the incoming message using the given
+ * <a href="http://activemq.apache.org/camel/data-format.html">data format</a>
  *
  * @version $Revision: 1.1 $
  */
@@ -40,10 +41,14 @@
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         Message in = exchange.getIn();
         Object body = in.getBody();
-        dataFormat.marshal(exchange, body, buffer);
-        byte[] data = buffer.toByteArray();
+
+        // lets setup the out message before we invoke the dataFormat
+        // so that it can mutate it if necessary
         Message out = exchange.getOut(true);
         out.copyFrom(in);
+
+        dataFormat.marshal(exchange, body, buffer);
+        byte[] data = buffer.toByteArray();
         out.setBody(data);
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java?rev=583419&r1=583418&r2=583419&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java Wed Oct 10 03:33:34 2007
@@ -26,7 +26,8 @@
 import org.apache.camel.util.ExchangeHelper;
 
 /**
- * Unmarshals the body of the incoming message using the given data format
+ * Unmarshals the body of the incoming message using the given
+ * <a href="http://activemq.apache.org/camel/data-format.html">data format</a>
  *
  * @version $Revision: 1.1 $
  */
@@ -39,9 +40,13 @@
 
     public void process(Exchange exchange) throws Exception {
         InputStream stream = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
-        Object result = dataFormat.unmarshal(exchange, stream);
+
+        // lets setup the out message before we invoke the dataFormat
+        // so that it can mutate it if necessary
         Message out = exchange.getOut(true);
         out.copyFrom(exchange.getIn());
+
+        Object result = dataFormat.unmarshal(exchange, stream);
         out.setBody(result);
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java?rev=583419&r1=583418&r2=583419&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java Wed Oct 10 03:33:34 2007
@@ -24,7 +24,9 @@
 import org.apache.camel.Exchange;
 
 /**
- * Represents a data format used to marshal objects to and from streams
+ * Represents a
+ * <a href="http://activemq.apache.org/camel/data-format.html">data format</a>
+ * used to marshal objects to and from streams
  * such as Java Serialization or using JAXB2 to encode/decode objects using XML
  * or using SOAP encoding.
  *

Modified: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java?rev=583419&r1=583418&r2=583419&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java (original)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java Wed Oct 10 03:33:34 2007
@@ -31,7 +31,8 @@
 import org.apache.camel.util.IOHelper;
 
 /**
- * A {@link DataFormat} using JAXB2 to marshal to and from XML
+ * A <a href="http://activemq.apache.org/camel/data-format.html">data format</a>
+ * ({@link DataFormat}) using JAXB2 to marshal to and from XML
  *
  * @version $Revision: 1.1 $
  */

Added: activemq/camel/trunk/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java?rev=583419&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java (added)
+++ activemq/camel/trunk/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java Wed Oct 10 03:33:34 2007
@@ -0,0 +1,44 @@
+/**
+ *
+ * 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.camel.converter.xmlbeans;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.xmlbeans.XmlObject;
+
+/**
+ * A <a href="http://activemq.apache.org/camel/data-format.html">data format</a>
+ * ({@link DataFormat}) using XmlBeans to marshal to and from XML
+ *
+ * @version $Revision: 1.1 $
+ */
+public class XmlBeansDataFormat implements DataFormat{
+
+    public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception {
+        XmlObject object = ExchangeHelper.convertToMandatoryType(exchange, XmlObject.class, body);
+        object.save(stream);
+    }
+
+    public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
+        return XmlObject.Factory.parse(stream);
+    }
+}

Propchange: activemq/camel/trunk/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native