You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/09/25 04:51:54 UTC

svn commit: r1001128 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/model/dataformat/ components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/ components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/

Author: ningjiang
Date: Sat Sep 25 02:51:53 2010
New Revision: 1001128

URL: http://svn.apache.org/viewvc?rev=1001128&view=rev
Log:
CAMEL-3154 Support to set the customer xstream dirver

Added:
    camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamDataFormatDriverConfigTest.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java
    camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java?rev=1001128&r1=1001127&r2=1001128&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java Sat Sep 25 02:51:53 2010
@@ -49,6 +49,9 @@ public class XStreamDataFormat extends D
     @XmlAttribute
     private String driver = "xml";
 
+    @XmlAttribute
+    private String driverRef;
+
     @XmlJavaTypeAdapter(ConvertersAdapter.class)
     @XmlElement(name = "converters")
     private List<String> converters;
@@ -91,6 +94,14 @@ public class XStreamDataFormat extends D
         this.driver = driver;
     }
 
+    public String getDriverRef() {
+        return driverRef;
+    }
+
+    public void setDriverRef(String driverRef) {
+        this.driverRef = driverRef;
+    }
+
     public List<String> getConverters() {
         return converters;
     }
@@ -148,9 +159,11 @@ public class XStreamDataFormat extends D
         if (this.implicitCollections != null) {
             setProperty(dataFormat, "implicitCollections", this.implicitCollections);
         }
+        if (this.driverRef != null) {
+            setProperty(dataFormat, "xstreamDriver", this.driverRef);
+        }
     }
 
-
     @XmlTransient
     public static class ConvertersAdapter extends XmlAdapter<ConverterList, List<String>> {
         @Override

Modified: camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java?rev=1001128&r1=1001127&r2=1001128&view=diff
==============================================================================
--- camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java (original)
+++ camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java Sat Sep 25 02:51:53 2010
@@ -28,6 +28,7 @@ import javax.xml.stream.XMLStreamExcepti
 
 import com.thoughtworks.xstream.XStream;
 import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
 
@@ -46,6 +47,7 @@ import org.apache.camel.util.ObjectHelpe
 public abstract class AbstractXStreamWrapper implements DataFormat {
     
     private XStream xstream;
+    private HierarchicalStreamDriver xstreamDriver;
     private StaxConverter staxConverter;
     private List<String> converters;
     private Map<String, String> aliases;
@@ -71,7 +73,11 @@ public abstract class AbstractXStreamWra
     }
 
     protected XStream createXStream(ClassResolver resolver) {
-        xstream = new XStream();
+        if(xstreamDriver != null) {
+            xstream = new XStream(xstreamDriver);
+        } else {
+            xstream = new XStream();
+        }
 
         try {
             if (this.implicitCollections != null) {
@@ -174,6 +180,14 @@ public abstract class AbstractXStreamWra
         this.omitFields = omitFields;
     }
 
+    public HierarchicalStreamDriver getXstreamDriver() {
+        return xstreamDriver;
+    }
+
+    public void setXstreamDriver(HierarchicalStreamDriver xstreamDriver) {
+        this.xstreamDriver = xstreamDriver;
+    }
+
     public XStream getXstream() {
         return xstream;
     }

Added: camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamDataFormatDriverConfigTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamDataFormatDriverConfigTest.java?rev=1001128&view=auto
==============================================================================
--- camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamDataFormatDriverConfigTest.java (added)
+++ camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamDataFormatDriverConfigTest.java Sat Sep 25 02:51:53 2010
@@ -0,0 +1,41 @@
+/**
+ * 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.dataformat.xstream;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
+import org.apache.camel.impl.DefaultClassResolver;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class XStreamDataFormatDriverConfigTest extends CamelTestSupport {
+
+    @Test
+    public void testJson() {
+        PurchaseOrder purchaseOrder = new PurchaseOrder();
+        purchaseOrder.setName("foo");
+
+        XStreamDataFormat xStreamDataFormat = new XStreamDataFormat();
+        xStreamDataFormat.setXstreamDriver(new JsonHierarchicalStreamDriver());
+
+        XStream xStream = xStreamDataFormat.createXStream(new DefaultClassResolver());
+        String marshalledOrder = xStream.toXML(purchaseOrder);
+
+        assertEquals("{", marshalledOrder.substring(0, 1));
+    }
+
+}

Propchange: camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamDataFormatDriverConfigTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamDataFormatDriverConfigTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date