camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/4] camel git commit: CAMEL-10531 Aligned XML DSL attribute names to Java DSL, fromType and toType instead of from and to
Date Thu, 19 Jan 2017 12:21:13 GMT
Repository: camel
Updated Branches:
  refs/heads/master 388b787bb -> a2d3dd7c4


CAMEL-10531 Aligned XML DSL attribute names to Java DSL, fromType and toType instead of from
and to


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a2d3dd7c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a2d3dd7c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a2d3dd7c

Branch: refs/heads/master
Commit: a2d3dd7c4407619c09a42cd3d10614feba268880
Parents: 82733d1
Author: Tomohisa Igarashi <tm.igarashi@gmail.com>
Authored: Thu Jan 19 13:08:29 2017 +0900
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jan 19 13:20:55 2017 +0100

----------------------------------------------------------------------
 camel-core/src/main/docs/transformer.adoc       | 14 +++---
 .../camel/builder/TransformerBuilder.java       |  4 +-
 .../camel/impl/transformer/TransformerKey.java  |  6 +--
 .../CustomTransformerDefinition.java            |  4 +-
 .../DataFormatTransformerDefinition.java        |  4 +-
 .../EndpointTransformerDefinition.java          |  4 +-
 .../transformer/TransformerDefinition.java      | 48 ++++++++++++--------
 .../transformer/SpringTransformerRouteTest.xml  |  8 ++--
 .../OSGI-INF/blueprint/camel-context.xml        |  2 +-
 .../resources/META-INF/spring/camel-context.xml |  2 +-
 .../AbstractLocalCamelControllerTest.java       | 11 ++---
 .../commands/TransformerListCommandTest.java    |  8 ++--
 12 files changed, 61 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/camel-core/src/main/docs/transformer.adoc
----------------------------------------------------------------------
diff --git a/camel-core/src/main/docs/transformer.adoc b/camel-core/src/main/docs/transformer.adoc
index 543c58c..abe57b3 100644
--- a/camel-core/src/main/docs/transformer.adoc
+++ b/camel-core/src/main/docs/transformer.adoc
@@ -50,15 +50,15 @@ Supported Transformers
 [[Transformer-CommonOptions]]
 Common Options
 ^^^^^^^^^^^^^
-All transformers have following common options to specify which data type is supported by
the transformer. `scheme` or both of `from` and `to` must be specified.
+All transformers have following common options to specify which data type is supported by
the transformer. `scheme` or both of `fromType` and `toType` must be specified.
 |=======================================================================
 | Name | Description
 
 | scheme | Type of data model like `xml` or `json`. For example if `xml` is specified, the
transformer is applied for all java -&gt; xml and xml -&gt; java transformation.
  
-| from | <<Transformer-DataTypeFormat,Data type>> to transform from.
+| fromType | <<Transformer-DataTypeFormat,Data type>> to transform from.
  
-| to | <<Transformer-DataTypeFormat,Data type>> to transform to.
+| toType | <<Transformer-DataTypeFormat,Data type>> to transform to.
 |=======================================================================
 
 
@@ -90,7 +90,7 @@ transformer()
 XML DSL:
 [source,xml]
 -------------------------------------------------------------------
-<dataFormatTransformer from="java:com.example.Order" to="csv:CSVOrder">
+<dataFormatTransformer fromType="java:com.example.Order" toType="csv:CSVOrder">
     <bindy id="csvdf" type="Csv" classType="com.example.Order"/>
 </dataFormatTransformer>
 -------------------------------------------------------------------
@@ -119,7 +119,7 @@ transformer()
 And here is an example to specify endpoint ref in XML DSL:
 [source,xml]
 -------------------------------------------------------------------
-<endpointTransformer ref="myDozerEndpoint" from="xml" to="json"/>
+<endpointTransformer ref="myDozerEndpoint" fromType="xml" toType="json"/>
 -------------------------------------------------------------------
 
 
@@ -148,7 +148,7 @@ transformer()
 XML DSL:
 [source,xml]
 -------------------------------------------------------------------
-<customTransformer type="com.example.MyCustomTransformer" from="xml" to="json"/>
+<customTransformer type="com.example.MyCustomTransformer" fromType="xml" toType="json"/>
 -------------------------------------------------------------------
 
 
@@ -174,7 +174,7 @@ XML DSL:
 -------------------------------------------------------------------
 <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
     <transformers>
-        <endpointTransformer uri="xslt:transform.xsl" from="xml:ABCOrder" to="xml:XYZOrder"/>
+        <endpointTransformer uri="xslt:transform.xsl" fromType="xml:ABCOrder" toType="xml:XYZOrder"/>
     </transformers>
     ....
 </camelContext>

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/camel-core/src/main/java/org/apache/camel/builder/TransformerBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/TransformerBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/TransformerBuilder.java
index 5bb0243..9f5f2ec 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/TransformerBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/TransformerBuilder.java
@@ -186,8 +186,8 @@ public class TransformerBuilder {
         if (scheme != null) {
             transformer.setScheme(scheme);
         } else {
-            transformer.setFrom(from);
-            transformer.setTo(to);
+            transformer.setFromType(from);
+            transformer.setToType(to);
         }
         
         camelContext.getTransformers().add(transformer);

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/camel-core/src/main/java/org/apache/camel/impl/transformer/TransformerKey.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/transformer/TransformerKey.java
b/camel-core/src/main/java/org/apache/camel/impl/transformer/TransformerKey.java
index d5034d2..f75f9b5 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/transformer/TransformerKey.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/transformer/TransformerKey.java
@@ -58,12 +58,12 @@ public final class TransformerKey extends ValueHolder<String> {
             return scheme.equals(def.getScheme());
         }
         if (from == null) {
-            return to.toString().equals(def.getTo());
+            return to.toString().equals(def.getToType());
         }
         if (to == null) {
-            return from.toString().equals(def.getFrom());
+            return from.toString().equals(def.getFromType());
         }
-        return from.toString().equals(def.getFrom()) && to.toString().equals(def.getTo());
+        return from.toString().equals(def.getFromType()) && to.toString().equals(def.getToType());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
index b66f601..bce6a22 100644
--- a/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
@@ -65,8 +65,8 @@ public class CustomTransformerDefinition extends TransformerDefinition {
         }
         transformer.setCamelContext(context);
         return transformer.setModel(getScheme())
-                          .setFrom(getFrom())
-                          .setTo(getTo());
+                          .setFrom(getFromType())
+                          .setTo(getToType());
     }
 
     public String getRef() {

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
index db1c98b..97c3496 100644
--- a/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
@@ -137,8 +137,8 @@ public class DataFormatTransformerDefinition extends TransformerDefinition
{
                 .setDataFormatType(dataFormatType)
                 .setDataFormatRef(ref)
                 .setModel(getScheme())
-                .setFrom(getFrom())
-                .setTo(getTo());
+                .setFrom(getFromType())
+                .setTo(getToType());
     }
 
     public String getRef() {

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
index 7c0dc32..e799f88 100644
--- a/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
@@ -55,8 +55,8 @@ public class EndpointTransformerDefinition extends TransformerDefinition
{
         return new ProcessorTransformer(context)
             .setProcessor(processor)
             .setModel(getScheme())
-            .setFrom(getFrom())
-            .setTo(getTo());
+            .setFrom(getFromType())
+            .setTo(getToType());
     }
 
     public String getRef() {

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
index 590bb5a..d321a11 100644
--- a/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
@@ -23,6 +23,7 @@ import javax.xml.bind.annotation.XmlType;
 import org.apache.camel.CamelContext;
 import org.apache.camel.model.InputTypeDefinition;
 import org.apache.camel.model.OutputTypeDefinition;
+import org.apache.camel.spi.DataType;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.Transformer;
 
@@ -50,9 +51,9 @@ public abstract class TransformerDefinition {
     @XmlAttribute
     private String scheme;
     @XmlAttribute
-    private String from;
+    private String fromType;
     @XmlAttribute
-    private String to;
+    private String toType;
 
     public Transformer createTransformer(CamelContext context) throws Exception {
         return doCreateTransformer(context);
@@ -66,6 +67,9 @@ public abstract class TransformerDefinition {
 
     /**
      * Set a scheme name supported by the transformer.
+     * If you specify 'csv', the transformer will be picked up for all of 'csv' from/to
+     * Java transformation. Note that the scheme matching is performed only when
+     * no exactly matched transformer exists.
      *
      * @param scheme scheme name
      */
@@ -73,17 +77,20 @@ public abstract class TransformerDefinition {
         this.scheme = scheme;
     }
 
-    public String getFrom() {
-        return from;
+    public String getFromType() {
+        return fromType;
     }
 
     /**
-     * Set the 'from' data type .
-     *
-     * @param from 'from' data type
+     * Set the 'from' data type name.
+     * If you specify 'xml:XYZ', the transformer will be picked up if source type is
+     * 'xml:XYZ'. If you specify just 'xml', the transformer matches with all of
+     * 'xml' source type like 'xml:ABC' or 'xml:DEF'.
+     * 
+     * @param from 'from' data type name
      */
-    public void setFrom(String from) {
-        this.from = from;
+    public void setFromType(String from) {
+        this.fromType = from;
     }
 
     /**
@@ -91,21 +98,24 @@ public abstract class TransformerDefinition {
      *
      * @param clazz 'from' Java class
      */
-    public void setFrom(Class<?> clazz) {
-        this.from = "java:" + clazz.getName();
+    public void setFromType(Class<?> clazz) {
+        this.fromType = new DataType(clazz).toString();
     }
 
-    public String getTo() {
-        return to;
+    public String getToType() {
+        return toType;
     }
 
     /**
-     * Set the 'to' data type.
+     * Set the 'to' data type name.
+     * If you specify 'json:XYZ', the transformer will be picked up if destination type is
+     * 'json:XYZ'. If you specify just 'json', the transformer matches with all of
+     * 'json' destination type like 'json:ABC' or 'json:DEF'.
      *
-     * @param to 'to' data type 
+     * @param to 'to' data type name
      */
-    public void setTo(String to) {
-        this.to = to;
+    public void setToType(String to) {
+        this.toType = to;
     }
 
     /**
@@ -113,8 +123,8 @@ public abstract class TransformerDefinition {
      *
      * @param clazz 'to' Java class
      */
-    public void setTo(Class<?> clazz) {
-        this.to = "java:" + clazz.getName();
+    public void setToType(Class<?> clazz) {
+        this.toType = new DataType(clazz).toString();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.xml
b/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.xml
index d8b4f72..1687c6e 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.xml
@@ -36,10 +36,10 @@
             <dataFormatTransformer scheme="json">
                 <custom ref="myJsonDataFormatDef"/>
             </dataFormatTransformer>
-            <endpointTransformer ref="myXmlEndpoint" from="xml:XmlXOrder" to="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrder"/>
-            <endpointTransformer ref="myXmlEndpoint" from="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrderResponse"
to="xml:XmlXOrderResponse"/>
-            <customTransformer ref="otherToXOrder" from="other:OtherXOrder" to="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrder"/>
-            <customTransformer ref="xOrderResponseToOther" from="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrderResponse"
to="other:OtherXOrderResponse"/>
+            <endpointTransformer ref="myXmlEndpoint" fromType="xml:XmlXOrder" toType="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrder"/>
+            <endpointTransformer ref="myXmlEndpoint" fromType="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrderResponse"
toType="xml:XmlXOrderResponse"/>
+            <customTransformer ref="otherToXOrder" fromType="other:OtherXOrder" toType="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrder"/>
+            <customTransformer ref="xOrderResponseToOther" fromType="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrderResponse"
toType="other:OtherXOrderResponse"/>
         </transformers>
         
         <route>

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/examples/camel-example-transformer-blueprint/src/main/resources/OSGI-INF/blueprint/camel-context.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-blueprint/src/main/resources/OSGI-INF/blueprint/camel-context.xml
b/examples/camel-example-transformer-blueprint/src/main/resources/OSGI-INF/blueprint/camel-context.xml
index 67e3373..a0fea6f 100644
--- a/examples/camel-example-transformer-blueprint/src/main/resources/OSGI-INF/blueprint/camel-context.xml
+++ b/examples/camel-example-transformer-blueprint/src/main/resources/OSGI-INF/blueprint/camel-context.xml
@@ -23,7 +23,7 @@
 
     <!-- START SNIPPET: e1 -->
     <transformers>
-        <endpointTransformer uri="xslt:transform.xsl" from="xml:MyRequest" to="xml:MyResponse"/>
+        <endpointTransformer uri="xslt:transform.xsl" fromType="xml:MyRequest" toType="xml:MyResponse"/>
     </transformers>
     <!-- END SNIPPET: e1 -->
 

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/examples/camel-example-transformer-demo/src/main/resources/META-INF/spring/camel-context.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/resources/META-INF/spring/camel-context.xml
b/examples/camel-example-transformer-demo/src/main/resources/META-INF/spring/camel-context.xml
index f8fa92f..09c3b72 100644
--- a/examples/camel-example-transformer-demo/src/main/resources/META-INF/spring/camel-context.xml
+++ b/examples/camel-example-transformer-demo/src/main/resources/META-INF/spring/camel-context.xml
@@ -40,7 +40,7 @@
         <!-- START SNIPPET: e3 -->
         <camel:transformers>
             <!-- specifying from&to data type for the Java-CSV transformation -->
-            <camel:dataFormatTransformer from="java:org.apache.camel.example.transformer.demo.Order"
to="csv:CSVOrder">
+            <camel:dataFormatTransformer fromType="java:org.apache.camel.example.transformer.demo.Order"
toType="csv:CSVOrder">
                 <camel:bindy id="csvdf" type="Csv" classType="org.apache.camel.example.transformer.demo.Order"/>
             </camel:dataFormatTransformer>
             <!-- instead of exact from&to type, scheme name can be specified to apply
for all the Java-XML transformation -->

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/AbstractLocalCamelControllerTest.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/AbstractLocalCamelControllerTest.java
b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/AbstractLocalCamelControllerTest.java
index 0a24e2c..682ac0d 100644
--- a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/AbstractLocalCamelControllerTest.java
+++ b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/AbstractLocalCamelControllerTest.java
@@ -24,7 +24,6 @@ import org.apache.camel.Message;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.ExplicitCamelContextNameStrategy;
-import org.apache.camel.model.transformer.CustomTransformerDefinition;
 import org.apache.camel.spi.DataType;
 import org.apache.camel.spi.Transformer;
 import org.junit.After;
@@ -47,17 +46,15 @@ public class AbstractLocalCamelControllerTest {
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
+                transformer()
+                    .fromType("xml:foo")
+                    .toType("json:bar")
+                    .withJava(DummyTransformer.class);
                 from("direct:start1").id("route1").delay(100).to("mock:result1");
                 from("direct:start2").id("route2").delay(100).to("mock:result2");
                 from("direct:start3").id("route3").delay(100).to("mock:result3");
             }
         });
-
-        CustomTransformerDefinition def = new CustomTransformerDefinition();
-        def.setType(DummyTransformer.class.getName());
-        def.setFrom("xml:foo");
-        def.setTo("json:bar");
-        context.getTransformers().add(def);
         localCamelController = new DummyCamelController(context);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/a2d3dd7c/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/TransformerListCommandTest.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/TransformerListCommandTest.java
b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/TransformerListCommandTest.java
index a826f5d..5f71849 100644
--- a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/TransformerListCommandTest.java
+++ b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/TransformerListCommandTest.java
@@ -74,14 +74,14 @@ public class TransformerListCommandTest {
     private String doTest(boolean verbose) throws Exception {
         CamelContext context = new DefaultCamelContext();
         EndpointTransformerDefinition etd = new EndpointTransformerDefinition();
-        etd.setFrom("xml:foo");
-        etd.setTo("json:bar");
+        etd.setFromType("xml:foo");
+        etd.setToType("json:bar");
         etd.setUri("direct:transformer");
         context.getTransformers().add(etd);
         context.resolveTransformer(new DataType("xml:foo"), new DataType("json:bar"));
         DataFormatTransformerDefinition dftd = new DataFormatTransformerDefinition();
-        dftd.setFrom(this.getClass());
-        dftd.setTo("xml:test");
+        dftd.setFromType(this.getClass());
+        dftd.setToType("xml:test");
         dftd.setDataFormatType(new StringDataFormat());
         context.getTransformers().add(dftd);
         context.resolveTransformer(new DataType(this.getClass()), new DataType("xml:test"));


Mime
View raw message