Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6027F106A0 for ; Thu, 29 May 2014 11:27:55 +0000 (UTC) Received: (qmail 99742 invoked by uid 500); 29 May 2014 11:27:55 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 99690 invoked by uid 500); 29 May 2014 11:27:55 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 99682 invoked by uid 99); 29 May 2014 11:27:55 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 May 2014 11:27:55 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id BA0254F440; Thu, 29 May 2014 11:27:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ningjiang@apache.org To: commits@camel.apache.org Message-Id: <0bd371c4a07e4ad38f122db783ac1743@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: CAMEL-7375 Add XML DSL for the camel-barcode dataformat Date: Thu, 29 May 2014 11:27:54 +0000 (UTC) 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 Authored: Thu May 29 19:27:15 2014 +0800 Committer: Willem Jiang 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 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +