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 2014/07/11 11:04:07 UTC
git commit: CAMEL-7592 Support setMode in XStreamDataFormat
Repository: camel
Updated Branches:
refs/heads/master 1a5f700d7 -> 8d633b077
CAMEL-7592 Support setMode in XStreamDataFormat
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8d633b07
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8d633b07
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8d633b07
Branch: refs/heads/master
Commit: 8d633b077f2afab81140b7c65476d09e18b14bb9
Parents: 1a5f700
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Jul 11 17:02:33 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Jul 11 17:03:48 2014 +0800
----------------------------------------------------------------------
.../model/dataformat/XStreamDataFormat.java | 17 +++++++++
.../xstream/AbstractXStreamWrapper.java | 36 ++++++++++++++++++--
.../xstream/SpringXStreamConfigurationTest.xml | 4 +--
3 files changed, 53 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8d633b07/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java
index 6ea2ab8..95ad895 100644
--- a/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java
@@ -54,6 +54,9 @@ public class XStreamDataFormat extends DataFormatDefinition {
private String driver;
@XmlAttribute
private String driverRef;
+ @XmlAttribute
+ private String mode;
+
@XmlJavaTypeAdapter(ConvertersAdapter.class)
@XmlElement(name = "converters")
private List<String> converters;
@@ -66,6 +69,7 @@ public class XStreamDataFormat extends DataFormatDefinition {
@XmlJavaTypeAdapter(ImplicitCollectionsAdapter.class)
@XmlElement(name = "implicitCollections")
private Map<String, String[]> implicitCollections;
+
public XStreamDataFormat() {
super("xstream");
@@ -99,6 +103,14 @@ public class XStreamDataFormat extends DataFormatDefinition {
public void setDriverRef(String driverRef) {
this.driverRef = driverRef;
}
+
+ public String getMode() {
+ return mode;
+ }
+
+ public void setMode(String mode) {
+ this.mode = mode;
+ }
public List<String> getConverters() {
return converters;
@@ -162,7 +174,12 @@ public class XStreamDataFormat extends DataFormatDefinition {
if (this.implicitCollections != null) {
setProperty(camelContext, dataFormat, "implicitCollections", this.implicitCollections);
}
+ if (this.mode != null) {
+ setProperty(camelContext, dataFormat, "mode", mode);
+ }
}
+
+
@XmlTransient
public static class ConvertersAdapter extends XmlAdapter<ConverterList, List<String>> {
http://git-wip-us.apache.org/repos/asf/camel/blob/8d633b07/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
index 8fc2697..7e5a9aa 100644
--- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
+++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
@@ -31,7 +31,6 @@ import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
-
import org.apache.camel.Exchange;
import org.apache.camel.converter.jaxp.StaxConverter;
import org.apache.camel.spi.ClassResolver;
@@ -51,6 +50,7 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
private Map<String, String> aliases;
private Map<String, String[]> omitFields;
private Map<String, String[]> implicitCollections;
+ private String mode;
public AbstractXStreamWrapper() {
}
@@ -136,13 +136,37 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
xstream.registerConverter(converter);
}
+
+ if (mode != null) {
+ xstream.setMode(getModeFromString(mode));
+ }
}
} catch (Exception e) {
throw new RuntimeException("Unable to build XStream instance", e);
}
return xstream;
- }
+ }
+
+ protected int getModeFromString(String modeString) {
+ int result;
+ if ("NO_REFERENCES".equalsIgnoreCase(modeString)) {
+ result = XStream.NO_REFERENCES;
+ } else if ("ID_REFERENCES".equalsIgnoreCase(modeString)) {
+ result = XStream.ID_REFERENCES;
+ } else if ("XPATH_RELATIVE_REFERENCES".equalsIgnoreCase(modeString)) {
+ result = XStream.XPATH_RELATIVE_REFERENCES;
+ } else if ("XPATH_ABSOLUTE_REFERENCES".equalsIgnoreCase(modeString)) {
+ result = XStream.XPATH_ABSOLUTE_REFERENCES;
+ } else if ("SINGLE_NODE_XPATH_RELATIVE_REFERENCES".equalsIgnoreCase(modeString)) {
+ result = XStream.SINGLE_NODE_XPATH_RELATIVE_REFERENCES;
+ } else if ("SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES".equalsIgnoreCase(modeString)) {
+ result = XStream.SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES;
+ } else {
+ throw new IllegalArgumentException("Unknown mode : " + modeString);
+ }
+ return result;
+ }
public StaxConverter getStaxConverter() {
if (staxConverter == null) {
@@ -194,6 +218,14 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
public void setXstreamDriver(HierarchicalStreamDriver xstreamDriver) {
this.xstreamDriver = xstreamDriver;
}
+
+ public String getMode() {
+ return mode;
+ }
+
+ public void setMode(String mode) {
+ this.mode = mode;
+ }
public XStream getXstream() {
return xstream;
http://git-wip-us.apache.org/repos/asf/camel/blob/8d633b07/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml b/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
index a248cda..863b951 100644
--- a/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
+++ b/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
@@ -29,7 +29,7 @@
<!-- we define the json xstream data formats to be used (xstream is default) -->
<dataFormats>
- <xstream id="xstream-1">
+ <xstream id="xstream-1" mode="NO_REFERENCES">
<converters>
<converter class="org.apache.camel.dataformat.xstream.XStreamConfigurationTest$PurchaseOrderConverter" />
</converters>
@@ -43,7 +43,7 @@
</implicitCollections>
</xstream>
- <xstream id="xstream-json" driver="json">
+ <xstream id="xstream-json" driver="json" mode="ID_REFERENCES">
<converters>
<converter class="org.apache.camel.dataformat.xstream.XStreamConfigurationTest$PurchaseOrderConverter" />
</converters>