camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-7375 Add XML DSL for the camel-barcode dataformat
Date Thu, 29 May 2014 11:27:54 GMT
Repository: camel
Updated Branches:
  refs/heads/master a0b969944 -> 1ec2395bb


CAMEL-7375 Add XML DSL for the camel-barcode dataformat


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

Branch: refs/heads/master
Commit: 1ec2395bb694938d12fae8bdbafb809cbb5b5009
Parents: a0b9699
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Thu May 29 19:27:15 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Thu May 29 19:27:15 2014 +0800

----------------------------------------------------------------------
 .../model/dataformat/BarcodeDataFormat.java     | 111 +++++++++++++++++++
 .../model/dataformat/DataFormatsDefinition.java |   1 +
 .../dataformat/barcode/BarcodeDataFormat.java   |  18 +++
 .../barcode/BarcodeDataFormatCamelTest.java     |   4 +-
 .../barcode/BarcodeDataFormatSpringTest.java    |  42 +++++++
 .../barcode/barcodeDataformatSpring.xml         |  78 +++++++++++++
 6 files changed, 252 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1ec2395b/camel-core/src/main/java/org/apache/camel/model/dataformat/BarcodeDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/BarcodeDataFormat.java
b/camel-core/src/main/java/org/apache/camel/model/dataformat/BarcodeDataFormat.java
new file mode 100644
index 0000000..1358b47
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/BarcodeDataFormat.java
@@ -0,0 +1,111 @@
+/**
+ * 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.model.dataformat;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.RouteContext;
+
+
+/**
+ * Represents a Barcode DataFormat {@link org.apache.camel.spi.DataFormat}
+ *
+ * @version 
+ */
+@XmlRootElement(name = "barcode")
+@XmlAccessorType(XmlAccessType.FIELD)
+
+public class BarcodeDataFormat extends DataFormatDefinition {
+    @XmlAttribute
+    private Integer width;
+    @XmlAttribute
+    private Integer height;
+    @XmlAttribute
+    private String imageType;
+    @XmlAttribute
+    private String barcodeFormat;
+    
+    public BarcodeDataFormat() {
+        super("barcode");
+    }
+    
+    @Override
+    protected DataFormat createDataFormat(RouteContext routeContext) {
+        DataFormat barcodeFormat = super.createDataFormat(routeContext);
+
+        return barcodeFormat;
+    }
+
+    @Override
+    protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext)
{
+        if (width != null) {
+            setProperty(camelContext, dataFormat, "width", width);
+        }
+
+        if (height != null) {
+            setProperty(camelContext, dataFormat, "height", height);
+        } 
+        
+        if (imageType != null) {
+            setProperty(camelContext, dataFormat, "barcodeImageType", imageType);
+        }
+
+        if (barcodeFormat != null) {
+            setProperty(camelContext, dataFormat, "barcodeDataFormat", barcodeFormat);
+        }
+       
+    }
+    
+    public Integer getWidth() {
+        return width;
+    }
+
+    public void setWidth(Integer width) {
+        this.width = width;
+    }
+
+    public Integer getHeight() {
+        return height;
+    }
+
+    public void setHeight(Integer height) {
+        this.height = height;
+    }
+
+    public String getImageType() {
+        return imageType;
+    }
+
+    public void setImageType(String imageType) {
+        this.imageType = imageType;
+    }
+
+    public String getBarcodeFormat() {
+        return barcodeFormat;
+    }
+
+    public void setBarcodeFormat(String barcodeFormat) {
+        this.barcodeFormat = barcodeFormat;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1ec2395b/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
index 2ac9c48..3b09d76 100644
--- a/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
@@ -38,6 +38,7 @@ public class DataFormatsDefinition {
     // cannot use @XmlElementRef as it doesn't allow optional properties
     @XmlElements({
         @XmlElement(required = false, name = "avro", type = AvroDataFormat.class),
+        @XmlElement(required = false, name = "barcode", type = BarcodeDataFormat.class),
         @XmlElement(required = false, name = "base64", type = Base64DataFormat.class),
         @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class),
         @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),

http://git-wip-us.apache.org/repos/asf/camel/blob/1ec2395b/components/camel-barcode/src/main/java/org/apache/camel/dataformat/barcode/BarcodeDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-barcode/src/main/java/org/apache/camel/dataformat/barcode/BarcodeDataFormat.java
b/components/camel-barcode/src/main/java/org/apache/camel/dataformat/barcode/BarcodeDataFormat.java
index 7e69787..fe347ec 100644
--- a/components/camel-barcode/src/main/java/org/apache/camel/dataformat/barcode/BarcodeDataFormat.java
+++ b/components/camel-barcode/src/main/java/org/apache/camel/dataformat/barcode/BarcodeDataFormat.java
@@ -348,4 +348,22 @@ public class BarcodeDataFormat implements DataFormat {
     public final Map<DecodeHintType, Object> getReaderHintMap() {
         return readerHintMap;
     }
+    
+    // these set method is used for BarcodeDataFormat XML DSL
+    public void setBarcodeImageType(BarcodeImageType type) {
+        this.params.setType(type);
+        this.optimizeHints();
+    }
+    
+    public void setBarcodeFormat(BarcodeFormat format) {
+        this.params.setFormat(format);
+    }
+    
+    public void setWidth(Integer width) {
+        this.params.setWidth(width);
+    }
+    
+    public void setHeight(Integer height) {
+        this.params.setHeight(height);
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1ec2395b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java
----------------------------------------------------------------------
diff --git a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java
b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java
index 0c4ba56..d747fbb 100644
--- a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java
+++ b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java
@@ -159,10 +159,10 @@ public class BarcodeDataFormatCamelTest extends BarcodeTestBase {
                 // 
                 // read file and route it
                 from(FILE_ENDPOINT + "?noop=true")
-                        .multicast().to("direct:marshall", "mock:image");
+                        .multicast().to("direct:unmarshall", "mock:image");
 
                 // get the message from code
-                from("direct:marshall")
+                from("direct:unmarshall")
                         .unmarshal(code1) // for unmarshalling, the instance doesn't matter
                         .to("log:OUT")
                         .to("mock:out");

http://git-wip-us.apache.org/repos/asf/camel/blob/1ec2395b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatSpringTest.java
b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatSpringTest.java
new file mode 100644
index 0000000..4fe967b
--- /dev/null
+++ b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatSpringTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.barcode;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.SpringCamelContext;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class BarcodeDataFormatSpringTest extends BarcodeDataFormatCamelTest {
+    
+    public boolean isCreateCamelContextPerClass() {
+        return true;
+    }
+    
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+    
+    
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/dataformat/barcode/barcodeDataformatSpring.xml");
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1ec2395b/components/camel-barcode/src/test/resources/org/apache/camel/dataformat/barcode/barcodeDataformatSpring.xml
----------------------------------------------------------------------
diff --git a/components/camel-barcode/src/test/resources/org/apache/camel/dataformat/barcode/barcodeDataformatSpring.xml
b/components/camel-barcode/src/test/resources/org/apache/camel/dataformat/barcode/barcodeDataformatSpring.xml
new file mode 100644
index 0000000..1c12d9b
--- /dev/null
+++ b/components/camel-barcode/src/test/resources/org/apache/camel/dataformat/barcode/barcodeDataformatSpring.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+     http://www.springframework.org/schema/beans
+     http://www.springframework.org/schema/beans/spring-beans.xsd
+     http://camel.apache.org/schema/spring
+     http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+<!-- START SNIPPET: e1 -->
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+    <!-- setup beanio data format -->
+    <dataFormats>
+      <barcode id="code1"/>
+      <barcode id="code2" width="200" height="200" />
+      <barcode id="code3" imageType="JPG" />
+      <barcode id="code4" width="200" height="200" imageType="JPG" barcodeFormat="PDF_417"/>
+      
+    </dataFormats>
+
+    <route>
+      <from uri="direct:code1"/>
+      <marshal ref="code1"/>
+      <to uri="file:target/out"/>
+    </route>
+    
+    <route>
+      <from uri="direct:code2"/>
+      <marshal ref="code2"/>
+      <to uri="file:target/out"/>
+    </route>
+    
+     <route>
+      <from uri="direct:code3"/>
+      <marshal ref="code3"/>
+      <to uri="file:target/out"/>
+    </route>
+    
+     <route>
+      <from uri="direct:code4"/>
+      <marshal ref="code4"/>
+      <to uri="file:target/out"/>
+    </route>
+    
+    <route>
+      <from uri="file:target/out?noop=true"/>
+      <multicast>
+         <to uri="direct:unmarshal"/>
+         <to uri="mock:image" />
+      </multicast>   
+    </route>
+    
+    <route>
+      <from uri="direct:unmarshal"/>
+      <unmarshal ref="code1"/>
+      <to uri="log:Out"/>
+      <to uri="mock:out"/>
+    </route>
+    
+  </camelContext>
+  
+</beans>


Mime
View raw message