You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/05/21 10:39:02 UTC
[1/4] camel git commit: CAMEL-9954: OSGi ready,
FactoryRegistry via Registry,
Annotation for class to provide additional factories
Repository: camel
Updated Branches:
refs/heads/master b8a9afc28 -> 76a10b773
CAMEL-9954: OSGi ready, FactoryRegistry via Registry, Annotation for class to provide additional factories
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/76a10b77
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/76a10b77
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/76a10b77
Branch: refs/heads/master
Commit: 76a10b773bb5cc387886f70cee53a87415d1af6a
Parents: 311d429
Author: Arno Noordover <ar...@noordover.net>
Authored: Fri May 20 23:10:32 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat May 21 12:37:16 2016 +0200
----------------------------------------------------------------------
.../bindy/BindyAbstractDataFormat.java | 93 +++++++++++--
.../dataformat/bindy/BindyAbstractFactory.java | 6 +-
.../bindy/BindyFixedLengthFactory.java | 2 -
.../bindy/BindyKeyValuePairFactory.java | 1 -
.../camel/dataformat/bindy/FormatFactory.java | 70 ++--------
.../bindy/annotation/FormatFactories.java | 32 +++++
.../bindy/csv/BindyCsvDataFormat.java | 7 +-
.../bindy/fixed/BindyFixedLengthDataFormat.java | 6 +-
.../factories/BigIntegerFormatFactory.java | 4 +-
.../format/factories/BooleanFormatFactory.java | 4 +-
.../format/factories/ByteFormatFactory.java | 4 +-
.../factories/CharacterFormatFactory.java | 4 +-
.../factories/DefaultFactoryRegistry.java | 134 +++++++++++++++++++
.../bindy/format/factories/FactoryRegistry.java | 25 ++++
.../bindy/format/factories/FormatFactories.java | 99 --------------
.../format/factories/IntegerFormatFactory.java | 4 +-
.../format/factories/LongFormatFactory.java | 4 +-
.../format/factories/ShortFormatFactory.java | 4 +-
.../format/factories/StringFormatFactory.java | 4 +-
.../bindy/kvp/BindyKeyValuePairDataFormat.java | 7 +-
.../csv/BindyCarQuoteAndCommaDelimiterTest.java | 12 ++
.../BindyComplexKeyValuePairStandaloneTest.java | 7 +-
.../date/BindyDatePatternCsvUnmarshallTest.java | 45 ++++++-
.../bindy/util/AnnotationModuleLoaderTest.java | 2 +-
24 files changed, 383 insertions(+), 197 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java
index f34a06e..9099a46 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java
@@ -17,21 +17,37 @@
package org.apache.camel.dataformat.bindy;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.dataformat.bindy.annotation.FormatFactories;
+import org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry;
+import org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry;
+import org.apache.camel.dataformat.bindy.format.factories.FormatFactoryInterface;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.spi.DataFormatName;
+import org.apache.camel.spi.Registry;
import org.apache.camel.support.ServiceSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public abstract class BindyAbstractDataFormat extends ServiceSupport implements DataFormat, DataFormatName {
+public abstract class BindyAbstractDataFormat extends ServiceSupport implements DataFormat, DataFormatName, CamelContextAware {
+ private static final Logger LOGGER = LoggerFactory.getLogger(BindyAbstractDataFormat.class);
private String locale;
private BindyAbstractFactory modelFactory;
private Class<?> classType;
+ private CamelContext camelContext;
public BindyAbstractDataFormat() {
}
-
+
protected BindyAbstractDataFormat(Class<?> classType) {
this.classType = classType;
}
@@ -51,25 +67,74 @@ public abstract class BindyAbstractDataFormat extends ServiceSupport implements
public void setLocale(String locale) {
this.locale = locale;
}
-
+
public BindyAbstractFactory getFactory() throws Exception {
if (modelFactory == null) {
- modelFactory = createModelFactory();
+ FormatFactory formatFactory = createFormatFactory();
+ registerAdditionalConverter(formatFactory);
+ modelFactory = createModelFactory(formatFactory);
modelFactory.setLocale(locale);
}
return modelFactory;
}
-
+
+ private void registerAdditionalConverter(FormatFactory formatFactory) throws IllegalAccessException, InstantiationException {
+ Function<Class<?>, FormatFactories> g = aClass -> aClass.getAnnotation(FormatFactories.class);
+ Function<FormatFactories, List<Class<? extends FormatFactoryInterface>>> h = formatFactories -> Arrays.asList(formatFactories.value());
+ List<Class<? extends FormatFactoryInterface>> array = Optional
+ .ofNullable(classType)
+ .map(g)
+ .map(h)
+ .orElse(Collections.emptyList());
+ for (Class<? extends FormatFactoryInterface> l : array) {
+ formatFactory.getFactoryRegistry().register(l.newInstance());
+ }
+ }
+
+ private FormatFactory createFormatFactory() {
+ FormatFactory formatFactory = new FormatFactory();
+ FactoryRegistry factoryRegistry = createFactoryRegistry();
+ formatFactory.setFactoryRegistry(factoryRegistry);
+ return formatFactory;
+ }
+
+ private FactoryRegistry createFactoryRegistry() {
+ return tryToGetFactoryRegistry();
+ }
+
+ private FactoryRegistry tryToGetFactoryRegistry() {
+ Function<CamelContext, Registry> f = CamelContext::getRegistry;
+ Function<Registry, Set<FactoryRegistry>> g = r -> r.findByType(FactoryRegistry.class);
+ Function<Set<FactoryRegistry>, FactoryRegistry> h = factoryRegistries -> {
+ if (factoryRegistries.size() > 1) {
+ LOGGER.warn("Number of registered {}: {}",
+ FactoryRegistry.class.getCanonicalName(),
+ factoryRegistries.size());
+ }
+ if (factoryRegistries.iterator().hasNext()) {
+ return factoryRegistries.iterator().next();
+ } else {
+ return new DefaultFactoryRegistry();
+ }
+ };
+
+ return Optional.ofNullable(camelContext)
+ .map(f)
+ .map(g)
+ .map(h)
+ .orElse(new DefaultFactoryRegistry());
+ }
+
public void setModelFactory(BindyAbstractFactory modelFactory) {
this.modelFactory = modelFactory;
}
-
- protected abstract BindyAbstractFactory createModelFactory() throws Exception;
+
+ protected abstract BindyAbstractFactory createModelFactory(FormatFactory formatFactory) throws Exception;
protected Object extractUnmarshalResult(List<Map<String, Object>> models) {
if (getClassType() != null) {
- // we expect to find this type in the models, and grab only that type
- List<Object> answer = new ArrayList<Object>();
+ // we expect to findForFormattingOptions this type in the models, and grab only that type
+ List<Object> answer = new ArrayList<>();
for (Map<String, Object> entry : models) {
Object data = entry.get(getClassType().getName());
if (data != null) {
@@ -96,4 +161,14 @@ public abstract class BindyAbstractDataFormat extends ServiceSupport implements
protected void doStop() throws Exception {
// noop
}
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
index d3e96b9..1108a68 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
@@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
public abstract class BindyAbstractFactory implements BindyFactory {
private static final Logger LOG = LoggerFactory.getLogger(BindyAbstractFactory.class);
protected final Map<String, List<Field>> annotatedLinkFields = new LinkedHashMap<String, List<Field>>();
- protected final FormatFactory formatFactory = FormatFactory.getInstance();
+ protected FormatFactory formatFactory;
protected Set<Class<?>> models;
protected Set<String> modelClassNames;
protected String crlf;
@@ -246,4 +246,8 @@ public abstract class BindyAbstractFactory implements BindyFactory {
public void setLocale(String locale) {
this.locale = locale;
}
+
+ public void setFormatFactory(FormatFactory formatFactory) {
+ this.formatFactory = formatFactory;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
index 4efddf4..c517852 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
@@ -48,8 +48,6 @@ public class BindyFixedLengthFactory extends BindyAbstractFactory implements Bin
boolean isOneToMany;
- private final FormatFactory formatFactory = FormatFactory.getInstance();
-
private Map<Integer, DataField> dataFields = new TreeMap<Integer, DataField>();
private Map<Integer, Field> annotatedFields = new TreeMap<Integer, Field>();
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
index 5985939..453e8fb 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
@@ -47,7 +47,6 @@ import org.slf4j.LoggerFactory;
public class BindyKeyValuePairFactory extends BindyAbstractFactory implements BindyFactory {
private static final Logger LOG = LoggerFactory.getLogger(BindyKeyValuePairFactory.class);
- private final FormatFactory formatFactory = FormatFactory.getInstance();
private Map<Integer, KeyValuePairField> keyValuePairFields = new LinkedHashMap<Integer, KeyValuePairField>();
private Map<Integer, Field> annotatedFields = new LinkedHashMap<Integer, Field>();
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
index b9e374a..7055d79 100755
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
@@ -17,30 +17,7 @@
package org.apache.camel.dataformat.bindy;
-import org.apache.camel.dataformat.bindy.format.factories.BigDecimalFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.BigDecimalPatternFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.BigIntegerFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.BooleanFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.ByteFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.BytePatternFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.CharacterFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.DateFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.DoubleFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.DoublePatternFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.EnumFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.FloatFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.FloatPatternFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.FormatFactories;
-import org.apache.camel.dataformat.bindy.format.factories.IntegerFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.IntegerPatternFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.LocalDateFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.LocalDateTimeFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.LocalTimeFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.LongFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.LongPatternFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.ShortFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.ShortPatternFormatFactory;
-import org.apache.camel.dataformat.bindy.format.factories.StringFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry;
/**
@@ -48,44 +25,14 @@ import org.apache.camel.dataformat.bindy.format.factories.StringFormatFactory;
*/
public final class FormatFactory {
- private static final FormatFactory INSTANCE = new FormatFactory();
+ private FactoryRegistry factoryRegistry;
- static {
- FormatFactories.getInstance()
- .register(new StringFormatFactory())
- .register(new DateFormatFactory())
- .register(new BooleanFormatFactory())
- .register(new BigIntegerFormatFactory())
- .register(new LocalTimeFormatFactory())
- .register(new LocalDateTimeFormatFactory())
- .register(new LocalDateFormatFactory())
- .register(new CharacterFormatFactory())
- .register(new EnumFormatFactory())
- .register(new BigDecimalFormatFactory())
- .register(new BigDecimalPatternFormatFactory())
- .register(new DoubleFormatFactory())
- .register(new DoublePatternFormatFactory())
- .register(new FloatFormatFactory())
- .register(new FloatPatternFormatFactory())
- .register(new LongFormatFactory())
- .register(new LongPatternFormatFactory())
- .register(new IntegerFormatFactory())
- .register(new IntegerPatternFormatFactory())
- .register(new ShortFormatFactory())
- .register(new ShortPatternFormatFactory())
- .register(new ByteFormatFactory())
- .register(new BytePatternFormatFactory());
- }
-
- private FormatFactory() {
- }
-
- public static FormatFactory getInstance() {
- return INSTANCE;
+ public FormatFactory() {
}
private Format<?> doGetFormat(FormattingOptions formattingOptions) {
- return FormatFactories.getInstance().build(formattingOptions);
+ return factoryRegistry.findForFormattingOptions(formattingOptions)
+ .build(formattingOptions);
}
/**
@@ -99,4 +46,11 @@ public final class FormatFactory {
return doGetFormat(formattingOptions);
}
+ public void setFactoryRegistry(FactoryRegistry factoryRegistry) {
+ this.factoryRegistry = factoryRegistry;
+ }
+
+ public FactoryRegistry getFactoryRegistry() {
+ return factoryRegistry;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/FormatFactories.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/FormatFactories.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/FormatFactories.java
new file mode 100644
index 0000000..d31a24f
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/FormatFactories.java
@@ -0,0 +1,32 @@
+/**
+ * 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.bindy.annotation;
+
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.camel.dataformat.bindy.format.factories.FormatFactoryInterface;
+
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface FormatFactories {
+ Class<? extends FormatFactoryInterface>[] value();
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
index 1622064..500afe3 100755
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
@@ -32,6 +32,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.dataformat.bindy.BindyAbstractDataFormat;
import org.apache.camel.dataformat.bindy.BindyAbstractFactory;
import org.apache.camel.dataformat.bindy.BindyCsvFactory;
+import org.apache.camel.dataformat.bindy.FormatFactory;
import org.apache.camel.dataformat.bindy.annotation.Link;
import org.apache.camel.dataformat.bindy.util.ConverterUtils;
import org.apache.camel.spi.DataFormat;
@@ -277,7 +278,9 @@ public class BindyCsvDataFormat extends BindyAbstractDataFormat {
}
@Override
- protected BindyAbstractFactory createModelFactory() throws Exception {
- return new BindyCsvFactory(getClassType());
+ protected BindyAbstractFactory createModelFactory(FormatFactory formatFactory) throws Exception {
+ BindyCsvFactory bindyCsvFactory = new BindyCsvFactory(getClassType());
+ bindyCsvFactory.setFormatFactory(formatFactory);
+ return bindyCsvFactory;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
index ffbed62..317c659 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
@@ -32,6 +32,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.dataformat.bindy.BindyAbstractDataFormat;
import org.apache.camel.dataformat.bindy.BindyAbstractFactory;
import org.apache.camel.dataformat.bindy.BindyFixedLengthFactory;
+import org.apache.camel.dataformat.bindy.FormatFactory;
import org.apache.camel.dataformat.bindy.util.ConverterUtils;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.util.IOHelper;
@@ -290,18 +291,21 @@ public class BindyFixedLengthDataFormat extends BindyAbstractDataFormat {
}
@Override
- protected BindyAbstractFactory createModelFactory() throws Exception {
+ protected BindyAbstractFactory createModelFactory(FormatFactory formatFactory) throws Exception {
BindyFixedLengthFactory factory = new BindyFixedLengthFactory(getClassType());
+ factory.setFormatFactory(formatFactory);
// Optionally initialize the header factory... using header model classes
if (factory.hasHeader()) {
this.headerFactory = new BindyFixedLengthFactory(factory.header());
+ this.headerFactory.setFormatFactory(formatFactory);
}
// Optionally initialize the footer factory... using footer model classes
if (factory.hasFooter()) {
this.footerFactory = new BindyFixedLengthFactory(factory.footer());
+ this.footerFactory.setFormatFactory(formatFactory);
}
return factory;
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigIntegerFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigIntegerFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigIntegerFormatFactory.java
index a8a72fb..9612317 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigIntegerFormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigIntegerFormatFactory.java
@@ -23,7 +23,7 @@ import org.apache.camel.dataformat.bindy.format.AbstractNumberFormat;
public class BigIntegerFormatFactory extends AbstractFormatFactory {
- private static final BigIntegerFormat BIG_INTEGER_FORMAT = new BigIntegerFormat();
+ private final BigIntegerFormat bigIntegerFormat = new BigIntegerFormat();
{
supportedClasses.add(BigInteger.class);
@@ -36,7 +36,7 @@ public class BigIntegerFormatFactory extends AbstractFormatFactory {
@Override
public Format<?> build(FormattingOptions formattingOptions) {
- return BIG_INTEGER_FORMAT;
+ return bigIntegerFormat;
}
private static class BigIntegerFormat extends AbstractNumberFormat<BigInteger> {
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java
index bc150e8..2d2a8c6 100755
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java
@@ -21,7 +21,7 @@ import org.apache.camel.dataformat.bindy.FormattingOptions;
public class BooleanFormatFactory extends AbstractFormatFactory {
- private static final BooleanFormat BOOLEAN_FORMAT = new BooleanFormat();
+ private final BooleanFormat booleanFormat = new BooleanFormat();
{
supportedClasses.add(boolean.class);
@@ -30,7 +30,7 @@ public class BooleanFormatFactory extends AbstractFormatFactory {
@Override
public Format<?> build(FormattingOptions formattingOptions) {
- return BOOLEAN_FORMAT;
+ return booleanFormat;
}
private static class BooleanFormat implements Format<Boolean> {
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ByteFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ByteFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ByteFormatFactory.java
index 457270f..f8ca4d8 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ByteFormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ByteFormatFactory.java
@@ -22,7 +22,7 @@ import org.apache.camel.util.ObjectHelper;
public class ByteFormatFactory extends AbstractFormatFactory {
- private static final ByteFormat BYTE_FORMAT = new ByteFormat();
+ private final ByteFormat byteFormat = new ByteFormat();
{
supportedClasses.add(byte.class);
@@ -36,7 +36,7 @@ public class ByteFormatFactory extends AbstractFormatFactory {
@Override
public Format<?> build(FormattingOptions formattingOptions) {
- return BYTE_FORMAT;
+ return byteFormat;
}
private static class ByteFormat implements Format<Byte> {
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/CharacterFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/CharacterFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/CharacterFormatFactory.java
index 83786c7..e0dba01 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/CharacterFormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/CharacterFormatFactory.java
@@ -22,7 +22,7 @@ import org.apache.camel.dataformat.bindy.FormattingOptions;
public class CharacterFormatFactory extends AbstractFormatFactory {
- private static final CharacterFormat CHARACTER_FORMAT = new CharacterFormat();
+ private final CharacterFormat characterFormat = new CharacterFormat();
{
supportedClasses.add(char.class);
@@ -31,7 +31,7 @@ public class CharacterFormatFactory extends AbstractFormatFactory {
@Override
public Format<?> build(FormattingOptions formattingOptions) {
- return CHARACTER_FORMAT;
+ return characterFormat;
}
private static class CharacterFormat implements Format<Character> {
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
new file mode 100644
index 0000000..9b52b6a
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
@@ -0,0 +1,134 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+
+/**
+ * This class manages all FormatFactoryInterfaces.
+ * FormatFactoryInterfaces can declare to support one or more classes or
+ * can declare to be generic (e.g. {@link EnumFormatFactory}).
+ * The factories that support one or more classes are stored in a Map.
+ * The generic factories are stored in a list.
+ * The build method first tries to findForFormattingOptions a factory using the map.
+ * If it doesn't findForFormattingOptions one it uses the generic list.
+ * If it can't findForFormattingOptions a factory it throws an IllegalArgumentException.
+ */
+public final class DefaultFactoryRegistry implements FactoryRegistry {
+
+ private final Map<Class<?>, List<FormatFactoryInterface>> classBasedFactories = new HashMap<>();
+ private final List<FormatFactoryInterface> otherFactories = new ArrayList<>();
+
+ public DefaultFactoryRegistry() {
+ this.register(new StringFormatFactory())
+ .register(new DateFormatFactory())
+ .register(new BooleanFormatFactory())
+ .register(new BigIntegerFormatFactory())
+ .register(new LocalTimeFormatFactory())
+ .register(new LocalDateTimeFormatFactory())
+ .register(new LocalDateFormatFactory())
+ .register(new CharacterFormatFactory())
+ .register(new EnumFormatFactory())
+ .register(new BigDecimalFormatFactory())
+ .register(new BigDecimalPatternFormatFactory())
+ .register(new DoubleFormatFactory())
+ .register(new DoublePatternFormatFactory())
+ .register(new FloatFormatFactory())
+ .register(new FloatPatternFormatFactory())
+ .register(new LongFormatFactory())
+ .register(new LongPatternFormatFactory())
+ .register(new IntegerFormatFactory())
+ .register(new IntegerPatternFormatFactory())
+ .register(new ShortFormatFactory())
+ .register(new ShortPatternFormatFactory())
+ .register(new ByteFormatFactory())
+ .register(new BytePatternFormatFactory());
+ }
+
+ /**
+ * Registers a {@link FormatFactoryInterface}.
+ * Two types of factories exist:
+ * <ul>
+ * <li>Factories that support one or more classes</li>
+ * <li>Factories that support no specific class (e.g. {@link EnumFormatFactory})</li>
+ * </ul>
+ * @param formatFactories
+ * @return the DefaultFactoryRegistry instance
+ */
+ @Override
+ public FactoryRegistry register(FormatFactoryInterface... formatFactories) {
+ for (FormatFactoryInterface formatFactory : formatFactories) {
+ if (formatFactory.supportedClasses().isEmpty()) {
+ for (FormatFactoryInterface factory : otherFactories) {
+ if (factory.getClass() == formatFactory.getClass()) {
+ return this;
+ }
+ }
+ otherFactories.add(formatFactory);
+ } else {
+ for (Class<?> clazz : formatFactory.supportedClasses()) {
+ List<FormatFactoryInterface> factories = getByClass(clazz);
+ for (FormatFactoryInterface factory : factories) {
+ if (factory.getClass() == formatFactory.getClass()) {
+ return this;
+ }
+ }
+ factories.add(formatFactory);
+ }
+ }
+ }
+ return this;
+ }
+
+ @Override
+ public FactoryRegistry unregister(Class<? extends FormatFactoryInterface> clazz) {
+ for (Map.Entry<Class<?>, List<FormatFactoryInterface>> entry : classBasedFactories.entrySet()) {
+ entry.getValue().stream().filter(factory -> factory.getClass() == clazz).forEach(factory -> {
+ entry.getValue().remove(factory);
+ });
+ }
+ return this;
+ }
+
+ @Override
+ public FormatFactoryInterface findForFormattingOptions(FormattingOptions formattingOptions) {
+ for (FormatFactoryInterface formatFactory : getByClass(formattingOptions.getClazz())) {
+ if (formatFactory.canBuild(formattingOptions)) {
+ return formatFactory;
+ }
+ }
+ for (FormatFactoryInterface formatFactory : otherFactories) {
+ if (formatFactory.canBuild(formattingOptions)) {
+ return formatFactory;
+ }
+ }
+ throw new IllegalArgumentException("Can not findForFormattingOptions a suitable formatter for the type: " + formattingOptions.getClazz().getCanonicalName());
+ }
+
+ private List<FormatFactoryInterface> getByClass(Class<?> clazz) {
+ List<FormatFactoryInterface> result = classBasedFactories.get(clazz);
+ if (result == null) {
+ result = new ArrayList<>();
+ classBasedFactories.put(clazz, result);
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FactoryRegistry.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FactoryRegistry.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FactoryRegistry.java
new file mode 100644
index 0000000..53a3dba
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FactoryRegistry.java
@@ -0,0 +1,25 @@
+/**
+ * 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.bindy.format.factories;
+
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+
+public interface FactoryRegistry {
+ FactoryRegistry register(FormatFactoryInterface... formatFactory);
+ FactoryRegistry unregister(Class<? extends FormatFactoryInterface> clazz);
+ FormatFactoryInterface findForFormattingOptions(FormattingOptions formattingOptions);
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactories.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactories.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactories.java
deleted file mode 100644
index 2b9eec8..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactories.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * 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.bindy.format.factories;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.camel.dataformat.bindy.Format;
-import org.apache.camel.dataformat.bindy.FormattingOptions;
-
-/**
- * This class manages all FormatFactoryInterfaces.
- * This class is a singleton class.
- * FormatFactoryInterfaces can declare to support one or more classes or
- * can declare to be generic (e.g. {@link EnumFormatFactory}).
- * The factories that support one or more classes are stored in a Map.
- * The generic factories are stored in a list.
- * The build method first tries to find a factory using the map.
- * If it doesn't find one it uses the generic list.
- * If it can't find a factory it throws an IllegalArgumentException.
- */
-public final class FormatFactories extends AbstractFormatFactory {
-
- private static final FormatFactories INSTANCE = new FormatFactories();
- private static final Map<Class<?>, List<FormatFactoryInterface>> CLASS_BASED_FACTORIES = new HashMap<>();
- private static final List<FormatFactoryInterface> OTHER_FACTORIES = new ArrayList<>();
-
- private FormatFactories() {
- }
-
- public static FormatFactories getInstance() {
- return INSTANCE;
- }
-
- /**
- * Registers a {@link FormatFactoryInterface}.
- * Two types of factories exist:
- * <ul>
- * <li>Factories that support one or more classes</li>
- * <li>Factories that support no specific class (e.g. {@link EnumFormatFactory})</li>
- * </ul>
- * @param formatFactory
- * @return the FormatFactories instance
- */
- public synchronized FormatFactories register(FormatFactoryInterface formatFactory) {
- if (formatFactory.supportedClasses().isEmpty()) {
- OTHER_FACTORIES.add(formatFactory);
- } else {
- for (Class<?> clazz : formatFactory.supportedClasses()) {
- getByClass(clazz).add(formatFactory);
- }
- }
- return this;
- }
-
- @Override
- public boolean canBuild(FormattingOptions formattingOptions) {
- return true;
- }
-
- @Override
- public Format<?> build(FormattingOptions formattingOptions) {
- for (FormatFactoryInterface formatFactory : getByClass(formattingOptions.getClazz())) {
- if (formatFactory.canBuild(formattingOptions)) {
- return formatFactory.build(formattingOptions);
- }
- }
- for (FormatFactoryInterface formatFactory : OTHER_FACTORIES) {
- if (formatFactory.canBuild(formattingOptions)) {
- return formatFactory.build(formattingOptions);
- }
- }
- throw new IllegalArgumentException("Can not find a suitable formatter for the type: " + formattingOptions.getClazz().getCanonicalName());
- }
-
- private List<FormatFactoryInterface> getByClass(Class<?> clazz) {
- List<FormatFactoryInterface> result = CLASS_BASED_FACTORIES.get(clazz);
- if (result == null) {
- result = new ArrayList<>();
- CLASS_BASED_FACTORIES.put(clazz, result);
- }
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerFormatFactory.java
index 5335dbf..24892c6 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerFormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerFormatFactory.java
@@ -23,7 +23,7 @@ import org.apache.camel.util.ObjectHelper;
public class IntegerFormatFactory extends AbstractFormatFactory {
- private static final IntegerFormat INTEGER_FORMAT = new IntegerFormat();
+ private final IntegerFormat integerFormat = new IntegerFormat();
{
supportedClasses.add(int.class);
@@ -38,7 +38,7 @@ public class IntegerFormatFactory extends AbstractFormatFactory {
@Override
public Format<?> build(FormattingOptions formattingOptions) {
- return INTEGER_FORMAT;
+ return integerFormat;
}
private static class IntegerFormat extends AbstractNumberFormat<Integer> {
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongFormatFactory.java
index 0b3a192..c4a4f93 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongFormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongFormatFactory.java
@@ -23,7 +23,7 @@ import org.apache.camel.util.ObjectHelper;
public class LongFormatFactory extends AbstractFormatFactory {
- private static final LongFormat LONG_FORMAT = new LongFormat();
+ private final LongFormat longFormat = new LongFormat();
{
supportedClasses.add(long.class);
@@ -37,7 +37,7 @@ public class LongFormatFactory extends AbstractFormatFactory {
@Override
public Format<?> build(FormattingOptions formattingOptions) {
- return LONG_FORMAT;
+ return longFormat;
}
private static class LongFormat extends AbstractNumberFormat<Long> {
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortFormatFactory.java
index 1475dd3..fd1965e 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortFormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortFormatFactory.java
@@ -23,7 +23,7 @@ import org.apache.camel.util.ObjectHelper;
public class ShortFormatFactory extends AbstractFormatFactory {
- private static final ShortFormat SHORT_FORMAT = new ShortFormat();
+ private final ShortFormat shortFormat = new ShortFormat();
{
supportedClasses.add(short.class);
@@ -38,7 +38,7 @@ public class ShortFormatFactory extends AbstractFormatFactory {
@Override
public Format<?> build(FormattingOptions formattingOptions) {
- return SHORT_FORMAT;
+ return shortFormat;
}
private static class ShortFormat extends AbstractNumberFormat<Short> {
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/StringFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/StringFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/StringFormatFactory.java
index 670440e..d6644f4 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/StringFormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/StringFormatFactory.java
@@ -21,7 +21,7 @@ import org.apache.camel.dataformat.bindy.FormattingOptions;
public class StringFormatFactory extends AbstractFormatFactory {
- private static final StringFormat STRING_FORMAT = new StringFormat();
+ private final StringFormat stringFormat = new StringFormat();
{
supportedClasses.add(String.class);
@@ -29,7 +29,7 @@ public class StringFormatFactory extends AbstractFormatFactory {
@Override
public Format<?> build(FormattingOptions formattingOptions) {
- return STRING_FORMAT;
+ return stringFormat;
}
private static class StringFormat implements Format<String> {
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
index 65bc353..6fb8a76 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
@@ -30,6 +30,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.dataformat.bindy.BindyAbstractDataFormat;
import org.apache.camel.dataformat.bindy.BindyAbstractFactory;
import org.apache.camel.dataformat.bindy.BindyKeyValuePairFactory;
+import org.apache.camel.dataformat.bindy.FormatFactory;
import org.apache.camel.dataformat.bindy.util.ConverterUtils;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.util.IOHelper;
@@ -151,7 +152,9 @@ public class BindyKeyValuePairDataFormat extends BindyAbstractDataFormat {
}
}
- protected BindyAbstractFactory createModelFactory() throws Exception {
- return new BindyKeyValuePairFactory(getClassType());
+ protected BindyAbstractFactory createModelFactory(FormatFactory formatFactory) throws Exception {
+ BindyKeyValuePairFactory bindyKeyValuePairFactory = new BindyKeyValuePairFactory(getClassType());
+ bindyKeyValuePairFactory.setFormatFactory(formatFactory);
+ return bindyKeyValuePairFactory;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyCarQuoteAndCommaDelimiterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyCarQuoteAndCommaDelimiterTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyCarQuoteAndCommaDelimiterTest.java
index f06874e..a73d906 100644
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyCarQuoteAndCommaDelimiterTest.java
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyCarQuoteAndCommaDelimiterTest.java
@@ -18,10 +18,15 @@ package org.apache.camel.dataformat.bindy.csv;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry;
import org.apache.camel.dataformat.bindy.model.car.Car;
import org.apache.camel.dataformat.bindy.model.car.Car.Colour;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.impl.PropertyPlaceholderDelegateRegistry;
import org.apache.camel.model.dataformat.BindyType;
+import org.apache.camel.spi.Registry;
import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
import org.junit.Test;
/**
@@ -40,6 +45,13 @@ public class BindyCarQuoteAndCommaDelimiterTest extends CamelTestSupport {
+ " Engine Immobiliser, Limited Slip Differential, Power Mirrors, Power Steering, Power Windows, Radio CD with 6 Speakers"
+ " CV GOOD KLMS AUTO POWER OPTIONS GOOD KLMS \";\"Used\";\"0.0\";\"EZR05I\"\n";
+ @Before
+ public void setup() {
+ PropertyPlaceholderDelegateRegistry registry = (PropertyPlaceholderDelegateRegistry)context.getRegistry();
+ JndiRegistry reg = (JndiRegistry)registry.getRegistry();
+ reg.bind("defaultFactoryRegistry", new DefaultFactoryRegistry());
+ }
+
@Test
public void testBindyUnmarshalQuoteAndCommaDelimiter() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:out");
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java
index a6f826a..79a5ffd 100644
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java
@@ -23,7 +23,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.camel.dataformat.bindy.BindyAbstractFactory;
import org.apache.camel.dataformat.bindy.BindyKeyValuePairFactory;
+import org.apache.camel.dataformat.bindy.kvp.BindyKeyValuePairDataFormat;
import org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Header;
import org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Order;
import org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Trailer;
@@ -39,14 +41,15 @@ public class BindyComplexKeyValuePairStandaloneTest {
protected Map<String, Object> model = new HashMap<String, Object>();
protected Set<Class<?>> models = new HashSet<Class<?>>();
- BindyKeyValuePairFactory factory;
+ BindyAbstractFactory factory;
int counter;
@Before
public void init() throws Exception {
// Set factory
- factory = new BindyKeyValuePairFactory(org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Order.class);
+ BindyKeyValuePairDataFormat dataFormat = new BindyKeyValuePairDataFormat(org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Order.class);
+ factory = dataFormat.getFactory();
// Set model class
models.add(org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Order.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
index b3dc526..11d796f 100644
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.dataformat.bindy.model.date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.util.Collection;
import java.util.Date;
import org.apache.camel.EndpointInject;
@@ -26,9 +27,14 @@ import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.FormatFactories;
import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat;
+import org.apache.camel.dataformat.bindy.format.factories.AbstractFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.FormatFactoryInterface;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
@@ -74,10 +80,11 @@ public class BindyDatePatternCsvUnmarshallTest extends AbstractJUnit4SpringConte
}
@CsvRecord(separator = ",")
+ @FormatFactories({OrderNumberFormatFactory.class})
public static class Order {
@DataField(pos = 1)
- private int orderNr;
+ private OrderNumber orderNr;
@DataField(pos = 2)
private String firstName;
@@ -100,11 +107,11 @@ public class BindyDatePatternCsvUnmarshallTest extends AbstractJUnit4SpringConte
@DataField(pos = 8)
private ReturnReason returnReason;
- public int getOrderNr() {
+ public OrderNumber getOrderNr() {
return orderNr;
}
- public void setOrderNr(int orderNr) {
+ public void setOrderNr(OrderNumber orderNr) {
this.orderNr = orderNr;
}
@@ -174,4 +181,36 @@ public class BindyDatePatternCsvUnmarshallTest extends AbstractJUnit4SpringConte
broken,
other
}
+
+ public static class OrderNumber {
+ private int orderNr;
+
+ public static OrderNumber ofString(String orderNumber) {
+ OrderNumber result = new OrderNumber();
+ result.orderNr = Integer.valueOf(orderNumber);
+ return result;
+ }
+ }
+
+ public static class OrderNumberFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(OrderNumber.class);
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new Format<OrderNumber>() {
+ @Override
+ public String format(OrderNumber object) throws Exception {
+ return String.valueOf(object.orderNr);
+ }
+
+ @Override
+ public OrderNumber parse(String string) throws Exception {
+ return OrderNumber.ofString(string);
+ }
+ };
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/76a10b77/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/util/AnnotationModuleLoaderTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/util/AnnotationModuleLoaderTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/util/AnnotationModuleLoaderTest.java
index b6a3b4e..8aa7405 100644
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/util/AnnotationModuleLoaderTest.java
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/util/AnnotationModuleLoaderTest.java
@@ -31,7 +31,7 @@ public class AnnotationModuleLoaderTest extends Assert {
public void testLoadModels() throws Exception {
AnnotationModelLoader loader = new AnnotationModelLoader(new DefaultPackageScanClassResolver());
Set<Class<?>> classes = loader.loadModels("org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink");
- assertNotNull("The find classes should not be null ", classes);
+ assertNotNull("The findForFormattingOptions classes should not be null ", classes);
assertEquals("There should have 3 classes", 3, classes.size());
assertTrue(classes.contains(Client.class));
assertTrue(classes.contains(Order.class));
[4/4] camel git commit: CAMEL-9954: FormatFactory should be real
Factory-pattern
Posted by da...@apache.org.
CAMEL-9954: FormatFactory should be real Factory-pattern
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/311d429c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/311d429c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/311d429c
Branch: refs/heads/master
Commit: 311d429c0dc8a10424858a68505ce4105a22afdf
Parents: b8a9afc
Author: Arno Noordover <ar...@noordover.net>
Authored: Sun May 8 11:46:17 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat May 21 12:37:16 2016 +0200
----------------------------------------------------------------------
.../dataformat/bindy/BindyAbstractFactory.java | 3 +-
.../camel/dataformat/bindy/BindyCsvFactory.java | 20 +-
.../bindy/BindyFixedLengthFactory.java | 15 +-
.../bindy/BindyKeyValuePairFactory.java | 25 ++-
.../camel/dataformat/bindy/FormatFactory.java | 217 ++++++-------------
.../dataformat/bindy/FormattingOptions.java | 139 ++++++++++++
.../bindy/csv/BindyCsvDataFormat.java | 2 +-
.../bindy/fixed/BindyFixedLengthDataFormat.java | 2 +-
.../bindy/format/BigDecimalFormat.java | 47 ----
.../bindy/format/BigDecimalPatternFormat.java | 47 ----
.../bindy/format/BigIntegerFormat.java | 31 ---
.../dataformat/bindy/format/BooleanFormat.java | 31 ---
.../dataformat/bindy/format/ByteFormat.java | 31 ---
.../bindy/format/BytePatternFormat.java | 39 ----
.../bindy/format/CharacterFormat.java | 36 ---
.../bindy/format/DatePatternFormat.java | 106 ---------
.../dataformat/bindy/format/DoubleFormat.java | 46 ----
.../bindy/format/DoublePatternFormat.java | 39 ----
.../dataformat/bindy/format/EnumFormat.java | 36 ---
.../dataformat/bindy/format/FloatFormat.java | 46 ----
.../bindy/format/FloatPatternFormat.java | 39 ----
.../dataformat/bindy/format/IntegerFormat.java | 30 ---
.../bindy/format/IntegerPatternFormat.java | 39 ----
.../bindy/format/LocalDatePatternFormat.java | 85 --------
.../format/LocalDateTimePatternFormat.java | 94 --------
.../bindy/format/LocalTimePatternFormat.java | 95 --------
.../dataformat/bindy/format/LongFormat.java | 30 ---
.../bindy/format/LongPatternFormat.java | 39 ----
.../dataformat/bindy/format/ShortFormat.java | 30 ---
.../bindy/format/ShortPatternFormat.java | 38 ----
.../dataformat/bindy/format/StringFormat.java | 31 ---
.../format/factories/AbstractFormatFactory.java | 37 ++++
.../factories/BigDecimalFormatFactory.java | 70 ++++++
.../BigDecimalPatternFormatFactory.java | 71 ++++++
.../factories/BigIntegerFormatFactory.java | 53 +++++
.../format/factories/BooleanFormatFactory.java | 47 ++++
.../format/factories/ByteFormatFactory.java | 54 +++++
.../factories/BytePatternFormatFactory.java | 60 +++++
.../factories/CharacterFormatFactory.java | 51 +++++
.../format/factories/DateFormatFactory.java | 114 ++++++++++
.../format/factories/DoubleFormatFactory.java | 71 ++++++
.../factories/DoublePatternFormatFactory.java | 61 ++++++
.../format/factories/EnumFormatFactory.java | 53 +++++
.../format/factories/FloatFormatFactory.java | 72 ++++++
.../factories/FloatPatternFormatFactory.java | 61 ++++++
.../bindy/format/factories/FormatFactories.java | 99 +++++++++
.../factories/FormatFactoryInterface.java | 48 ++++
.../format/factories/IntegerFormatFactory.java | 56 +++++
.../factories/IntegerPatternFormatFactory.java | 61 ++++++
.../factories/LocalDateFormatFactory.java | 98 +++++++++
.../factories/LocalDateTimeFormatFactory.java | 109 ++++++++++
.../factories/LocalTimeFormatFactory.java | 109 ++++++++++
.../format/factories/LongFormatFactory.java | 55 +++++
.../factories/LongPatternFormatFactory.java | 61 ++++++
.../format/factories/ShortFormatFactory.java | 56 +++++
.../factories/ShortPatternFormatFactory.java | 60 +++++
.../format/factories/StringFormatFactory.java | 47 ++++
.../bindy/kvp/BindyKeyValuePairDataFormat.java | 2 +-
.../dataformat/bindy/util/ConverterUtils.java | 30 +++
.../factories/BigDecimalFormatFactoryTest.java | 48 ++++
.../date/BindyDatePatternCsvUnmarshallTest.java | 18 +-
61 files changed, 2083 insertions(+), 1257 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
index 959e40c..d3e96b9 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
@@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
public abstract class BindyAbstractFactory implements BindyFactory {
private static final Logger LOG = LoggerFactory.getLogger(BindyAbstractFactory.class);
protected final Map<String, List<Field>> annotatedLinkFields = new LinkedHashMap<String, List<Field>>();
+ protected final FormatFactory formatFactory = FormatFactory.getInstance();
protected Set<Class<?>> models;
protected Set<String> modelClassNames;
protected String crlf;
@@ -168,7 +169,7 @@ public abstract class BindyAbstractFactory implements BindyFactory {
String key2Formatted;
String keyGenerated;
- // Test added for ticket - camel-2773
+ // BigIntegerFormatFactory added for ticket - camel-2773
if ((key1 != null) && (key2 != null)) {
key2Formatted = getNumberFormat().format((long) key2);
keyGenerated = String.valueOf(key1) + key2Formatted;
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
index 045970d..e92bdc5 100755
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
@@ -192,7 +192,11 @@ public class BindyCsvFactory extends BindyAbstractFactory implements BindyFactor
}
// Create format object to format the field
- Format<?> format = FormatFactory.getFormat(field.getType(), getLocale(), dataField, field.getAnnotation(BindyConverter.class));
+ FormattingOptions formattingOptions = ConverterUtils.convert(dataField,
+ field.getType(),
+ field.getAnnotation(BindyConverter.class),
+ getLocale());
+ Format<?> format = formatFactory.getFormat(formattingOptions);
// field object to be set
Object modelField = model.get(field.getDeclaringClass().getName());
@@ -396,7 +400,11 @@ public class BindyCsvFactory extends BindyAbstractFactory implements BindyFactor
Class<?> type = field.getType();
// Create format
- Format<?> format = FormatFactory.getFormat(type, getLocale(), datafield, field.getAnnotation(BindyConverter.class));
+ FormattingOptions formattingOptions = ConverterUtils.convert(datafield,
+ field.getType(),
+ field.getAnnotation(BindyConverter.class),
+ getLocale());
+ Format<?> format = formatFactory.getFormat(formattingOptions);
// Get field value
Object value = field.get(obj);
@@ -565,7 +573,7 @@ public class BindyCsvFactory extends BindyAbstractFactory implements BindyFactor
}
if (section != null) {
- // Test if section number is not null
+ // BigIntegerFormatFactory if section number is not null
ObjectHelper.notNull(section.number(), "No number has been defined for the section");
// Get section number and add it to the sections
@@ -589,7 +597,11 @@ public class BindyCsvFactory extends BindyAbstractFactory implements BindyFactor
DataField dataField = dataFields.get(i);
Object modelField = model.get(field.getDeclaringClass().getName());
if (field.get(modelField) == null && !dataField.defaultValue().isEmpty()) {
- Format<?> format = FormatFactory.getFormat(field.getType(), getLocale(), dataField, field.getAnnotation(BindyConverter.class));
+ FormattingOptions formattingOptions = ConverterUtils.convert(dataField,
+ field.getType(),
+ field.getAnnotation(BindyConverter.class),
+ getLocale());
+ Format<?> format = formatFactory.getFormat(formattingOptions);
Object value = format.parse(dataField.defaultValue());
field.set(modelField, value);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
index d6b8aed..4efddf4 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
@@ -32,6 +32,7 @@ import org.apache.camel.dataformat.bindy.annotation.DataField;
import org.apache.camel.dataformat.bindy.annotation.FixedLengthRecord;
import org.apache.camel.dataformat.bindy.annotation.Link;
import org.apache.camel.dataformat.bindy.format.FormatException;
+import org.apache.camel.dataformat.bindy.util.ConverterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,6 +48,8 @@ public class BindyFixedLengthFactory extends BindyAbstractFactory implements Bin
boolean isOneToMany;
+ private final FormatFactory formatFactory = FormatFactory.getInstance();
+
private Map<Integer, DataField> dataFields = new TreeMap<Integer, DataField>();
private Map<Integer, Field> annotatedFields = new TreeMap<Integer, Field>();
@@ -239,7 +242,11 @@ public class BindyFixedLengthFactory extends BindyAbstractFactory implements Bin
}
// Create format object to format the field
- Format<?> format = FormatFactory.getFormat(field.getType(), getLocale(), dataField, field.getAnnotation(BindyConverter.class));
+ FormattingOptions formattingOptions = ConverterUtils.convert(dataField,
+ field.getType(),
+ field.getAnnotation(BindyConverter.class),
+ getLocale());
+ Format<?> format = formatFactory.getFormat(formattingOptions);
// field object to be set
Object modelField = model.get(field.getDeclaringClass().getName());
@@ -345,7 +352,11 @@ public class BindyFixedLengthFactory extends BindyAbstractFactory implements Bin
Class<?> type = field.getType();
// Create format
- Format<?> format = FormatFactory.getFormat(type, getLocale(), datafield, field.getAnnotation(BindyConverter.class));
+ FormattingOptions formattingOptions = ConverterUtils.convert(datafield,
+ field.getType(),
+ field.getAnnotation(BindyConverter.class),
+ getLocale());
+ Format<?> format = formatFactory.getFormat(formattingOptions);
// Get field value
Object value = field.get(obj);
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
index 6625be0..5985939 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
@@ -47,6 +47,7 @@ import org.slf4j.LoggerFactory;
public class BindyKeyValuePairFactory extends BindyAbstractFactory implements BindyFactory {
private static final Logger LOG = LoggerFactory.getLogger(BindyKeyValuePairFactory.class);
+ private final FormatFactory formatFactory = FormatFactory.getInstance();
private Map<Integer, KeyValuePairField> keyValuePairFields = new LinkedHashMap<Integer, KeyValuePairField>();
private Map<Integer, Field> annotatedFields = new LinkedHashMap<Integer, Field>();
@@ -232,7 +233,7 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi
if (l != null) {
- // Test if object exist
+ // BigIntegerFormatFactory if object exist
if (!l.isEmpty()) {
obj = l.get(0);
} else {
@@ -279,7 +280,11 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi
if (value != null) {
// Create format object to format the field
- Format<?> format = FormatFactory.getFormat(field.getType(), getLocale(), keyValuePairField, field.getAnnotation(BindyConverter.class));
+ FormattingOptions formattingOptions = ConverterUtils.convert(keyValuePairField,
+ field.getType(),
+ field.getAnnotation(BindyConverter.class),
+ getLocale());
+ Format<?> format = formatFactory.getFormat(formattingOptions);
// format the value of the key received
result = formatField(format, value, key, line);
@@ -305,7 +310,7 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi
// Relation OneToMany
for (int i = 0; i < values.size(); i++) {
- // Test if object exist
+ // BigIntegerFormatFactory if object exist
if ((!l.isEmpty()) && (l.size() > i)) {
obj = l.get(i);
} else {
@@ -315,7 +320,11 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi
value = values.get(i);
// Create format object to format the field
- Format<?> format = FormatFactory.getFormat(field.getType(), getLocale(), keyValuePairField, field.getAnnotation(BindyConverter.class));
+ FormattingOptions formattingOptions = ConverterUtils.convert(keyValuePairField,
+ field.getType(),
+ field.getAnnotation(BindyConverter.class),
+ getLocale());
+ Format<?> format = formatFactory.getFormat(formattingOptions);
// format the value of the key received
Object result = formatField(format, value, key, line);
@@ -444,7 +453,11 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi
// Create format
@SuppressWarnings("unchecked")
- Format<Object> format = (Format<Object>)FormatFactory.getFormat(type, getLocale(), keyValuePairField, field.getAnnotation(BindyConverter.class));
+ FormattingOptions formattingOptions = ConverterUtils.convert(keyValuePairField,
+ field.getType(),
+ field.getAnnotation(BindyConverter.class),
+ getLocale());
+ Format<Object> format = (Format<Object>) formatFactory.getFormat(formattingOptions);
// Get object to be formatted
Object obj = model.get(field.getDeclaringClass().getName());
@@ -618,7 +631,7 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi
}
if (section != null) {
- // Test if section number is not null
+ // BigIntegerFormatFactory if section number is not null
ObjectHelper.notNull(section.number(), "No number has been defined for the section");
// Get section number and add it to the sections
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
index 1971012..b9e374a 100755
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
@@ -17,41 +17,30 @@
package org.apache.camel.dataformat.bindy;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.util.Date;
-import java.util.Locale;
-
-import org.apache.camel.dataformat.bindy.annotation.BindyConverter;
-import org.apache.camel.dataformat.bindy.annotation.DataField;
-import org.apache.camel.dataformat.bindy.annotation.KeyValuePairField;
-import org.apache.camel.dataformat.bindy.format.BigDecimalFormat;
-import org.apache.camel.dataformat.bindy.format.BigDecimalPatternFormat;
-import org.apache.camel.dataformat.bindy.format.BigIntegerFormat;
-import org.apache.camel.dataformat.bindy.format.BooleanFormat;
-import org.apache.camel.dataformat.bindy.format.ByteFormat;
-import org.apache.camel.dataformat.bindy.format.BytePatternFormat;
-import org.apache.camel.dataformat.bindy.format.CharacterFormat;
-import org.apache.camel.dataformat.bindy.format.DatePatternFormat;
-import org.apache.camel.dataformat.bindy.format.DoubleFormat;
-import org.apache.camel.dataformat.bindy.format.DoublePatternFormat;
-import org.apache.camel.dataformat.bindy.format.EnumFormat;
-import org.apache.camel.dataformat.bindy.format.FloatFormat;
-import org.apache.camel.dataformat.bindy.format.FloatPatternFormat;
-import org.apache.camel.dataformat.bindy.format.IntegerFormat;
-import org.apache.camel.dataformat.bindy.format.IntegerPatternFormat;
-import org.apache.camel.dataformat.bindy.format.LocalDatePatternFormat;
-import org.apache.camel.dataformat.bindy.format.LocalDateTimePatternFormat;
-import org.apache.camel.dataformat.bindy.format.LocalTimePatternFormat;
-import org.apache.camel.dataformat.bindy.format.LongFormat;
-import org.apache.camel.dataformat.bindy.format.LongPatternFormat;
-import org.apache.camel.dataformat.bindy.format.ShortFormat;
-import org.apache.camel.dataformat.bindy.format.ShortPatternFormat;
-import org.apache.camel.dataformat.bindy.format.StringFormat;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.dataformat.bindy.format.factories.BigDecimalFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.BigDecimalPatternFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.BigIntegerFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.BooleanFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.ByteFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.BytePatternFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.CharacterFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.DateFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.DoubleFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.DoublePatternFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.EnumFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.FloatFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.FloatPatternFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.FormatFactories;
+import org.apache.camel.dataformat.bindy.format.factories.IntegerFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.IntegerPatternFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.LocalDateFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.LocalDateTimeFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.LocalTimeFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.LongFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.LongPatternFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.ShortFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.ShortPatternFormatFactory;
+import org.apache.camel.dataformat.bindy.format.factories.StringFormatFactory;
/**
@@ -59,137 +48,55 @@ import org.apache.camel.util.ObjectHelper;
*/
public final class FormatFactory {
- private FormatFactory() {
+ private static final FormatFactory INSTANCE = new FormatFactory();
+
+ static {
+ FormatFactories.getInstance()
+ .register(new StringFormatFactory())
+ .register(new DateFormatFactory())
+ .register(new BooleanFormatFactory())
+ .register(new BigIntegerFormatFactory())
+ .register(new LocalTimeFormatFactory())
+ .register(new LocalDateTimeFormatFactory())
+ .register(new LocalDateFormatFactory())
+ .register(new CharacterFormatFactory())
+ .register(new EnumFormatFactory())
+ .register(new BigDecimalFormatFactory())
+ .register(new BigDecimalPatternFormatFactory())
+ .register(new DoubleFormatFactory())
+ .register(new DoublePatternFormatFactory())
+ .register(new FloatFormatFactory())
+ .register(new FloatPatternFormatFactory())
+ .register(new LongFormatFactory())
+ .register(new LongPatternFormatFactory())
+ .register(new IntegerFormatFactory())
+ .register(new IntegerPatternFormatFactory())
+ .register(new ShortFormatFactory())
+ .register(new ShortPatternFormatFactory())
+ .register(new ByteFormatFactory())
+ .register(new BytePatternFormatFactory());
}
- /**
- * Retrieves the format to use for the given type
- *
- * @param clazz represents the type of the format (String, Integer, Byte)
- * @param pattern is the pattern to be used during the formatting of the data
- * @param locale optional locale for NumberFormat and DateFormat parsing.
- * @param precision optional scale for BigDecimal parsing.
- * @param rounding optional rounding mode to be used to scale BigDecimal with precision value
- * @param impliedDecimalSeparator optional flag for floating-point values
- * @param decimalSeparator optional decimal separator for BigDecimal
- * @param groupingSeparator optional grouping separator for BigDecimal
- * @return Format the formatter
- * @throws IllegalArgumentException if not suitable formatter is found
- */
- private static Format<?> doGetFormat(Class<?> clazz, String pattern, String locale,
- String timezone, int precision, String rounding,
- boolean impliedDecimalSeparator, String decimalSeparator, String groupingSeparator)
- throws Exception {
- if (clazz == byte.class || clazz == Byte.class) {
- return ObjectHelper.isNotEmpty(pattern)
- ? new BytePatternFormat(pattern, getLocale(locale))
- : new ByteFormat();
- } else if (clazz == short.class || clazz == Short.class) {
- return ObjectHelper.isNotEmpty(pattern)
- ? new ShortPatternFormat(pattern, getLocale(locale))
- : new ShortFormat();
- } else if (clazz == int.class || clazz == Integer.class) {
- return ObjectHelper.isNotEmpty(pattern)
- ? new IntegerPatternFormat(pattern, getLocale(locale))
- : new IntegerFormat();
- } else if (clazz == long.class || clazz == Long.class) {
- return ObjectHelper.isNotEmpty(pattern)
- ? new LongPatternFormat(pattern, getLocale(locale))
- : new LongFormat();
- } else if (clazz == float.class || clazz == Float.class) {
- return ObjectHelper.isNotEmpty(pattern)
- ? new FloatPatternFormat(pattern, getLocale(locale))
- : new FloatFormat(impliedDecimalSeparator, precision, getLocale(locale));
- } else if (clazz == double.class || clazz == Double.class) {
- return ObjectHelper.isNotEmpty(pattern)
- ? new DoublePatternFormat(pattern, getLocale(locale))
- : new DoubleFormat(impliedDecimalSeparator, precision, getLocale(locale));
- } else if (clazz == BigDecimal.class) {
- return ObjectHelper.isNotEmpty(pattern)
- ? new BigDecimalPatternFormat(pattern, getLocale(locale), precision, rounding, decimalSeparator, groupingSeparator)
- : new BigDecimalFormat(impliedDecimalSeparator, precision, getLocale(locale));
- } else if (clazz == BigInteger.class) {
- return new BigIntegerFormat();
- } else if (clazz == String.class) {
- return new StringFormat();
- } else if (clazz == Date.class) {
- return new DatePatternFormat(pattern, timezone, getLocale(locale));
- } else if (clazz == char.class || clazz == Character.class) {
- return new CharacterFormat();
- } else if (clazz == boolean.class || clazz == Boolean.class) {
- return new BooleanFormat();
- } else if (clazz == LocalDate.class) {
- return new LocalDatePatternFormat(pattern, getLocale(locale));
- } else if (clazz == LocalDateTime.class) {
- return new LocalDateTimePatternFormat(pattern, timezone, getLocale(locale));
- } else if (clazz == LocalTime.class) {
- return new LocalTimePatternFormat(pattern, timezone, getLocale(locale));
- } else if (clazz.isEnum()) {
- @SuppressWarnings({"rawtypes", "unchecked"})
- Format<?> fmt = new EnumFormat(clazz);
- return fmt;
- } else {
- throw new IllegalArgumentException("Can not find a suitable formatter for the type: " + clazz.getCanonicalName());
- }
+ private FormatFactory() {
}
- /**
- * Retrieves the format to use for the given type
- *
- * @param clazz represents the type of the format (String, Integer, Byte)
- * @param locale optional locale for NumberFormat and DateFormat parsing.
- * @return Format the formatter
- * @throws IllegalArgumentException if not suitable formatter is found
- */
- public static Format<?> getFormat(Class<?> clazz, String locale, DataField data, BindyConverter converter) throws Exception {
- if (converter != null) {
- return converter.value().newInstance();
- }
-
- String pattern = data.pattern();
- String timezone = data.timezone();
- int precision = data.precision();
- String decimalSeparator = data.decimalSeparator();
- String groupingSeparator = data.groupingSeparator();
- String rounding = data.rounding();
+ public static FormatFactory getInstance() {
+ return INSTANCE;
+ }
- return doGetFormat(clazz, pattern, locale, timezone, precision, rounding, data.impliedDecimalSeparator(), decimalSeparator, groupingSeparator);
+ private Format<?> doGetFormat(FormattingOptions formattingOptions) {
+ return FormatFactories.getInstance().build(formattingOptions);
}
/**
- * Retrieves the format to use for the given type
- *
- * @param clazz represents the type of the format (String, Integer, Byte)
- * @param locale optional locale for NumberFormat and DateFormat parsing.
- * @return Format the formatter
- * @throws IllegalArgumentException if not suitable formatter is found
- * TODO : Check if KeyValuePair could also use decimal/groupingSeparator/rounding for BigDecimal
+ * Retrieves the format to use for the given type*
*/
- public static Format<?> getFormat(Class<?> clazz, String locale, KeyValuePairField data, BindyConverter converter) throws Exception {
- if (converter != null) {
- return converter.value().newInstance();
- }
-
- String pattern = data.pattern();
- String timezone = data.timezone();
- int precision = data.precision();
-
- return doGetFormat(clazz, pattern, locale, timezone, precision, null, data.impliedDecimalSeparator(), null, null);
- }
-
- private static Locale getLocale(String locale) {
- if ("default".equals(locale)) {
- return Locale.getDefault();
+ public Format<?> getFormat(FormattingOptions formattingOptions) throws Exception {
+ if (formattingOptions.getBindyConverter() != null) {
+ return formattingOptions.getBindyConverter().value().newInstance();
}
- Locale answer = null;
- if (ObjectHelper.isNotEmpty(locale)) {
- String[] result = locale.split("-");
- if (result.length <= 2) {
- answer = result.length == 1 ? new Locale(result[0]) : new Locale(result[0], result[1]);
- }
- }
- return answer;
+ return doGetFormat(formattingOptions);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormattingOptions.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormattingOptions.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormattingOptions.java
new file mode 100644
index 0000000..9f154a7
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormattingOptions.java
@@ -0,0 +1,139 @@
+/**
+ * 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.bindy;
+
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.annotation.BindyConverter;
+import org.apache.camel.util.ObjectHelper;
+
+public class FormattingOptions {
+ private String pattern;
+ private Locale locale;
+ private String timezone;
+ private int precision;
+ private String rounding;
+ private boolean impliedDecimalSeparator;
+ private String decimalSeparator;
+ private String groupingSeparator;
+ private Class<?> clazz;
+ private BindyConverter bindyConverter;
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ public Locale getLocale() {
+ return locale;
+ }
+
+ public String getTimezone() {
+ return timezone;
+ }
+
+ public int getPrecision() {
+ return precision;
+ }
+
+ public String getRounding() {
+ return rounding;
+ }
+
+ public boolean isImpliedDecimalSeparator() {
+ return impliedDecimalSeparator;
+ }
+
+ public String getDecimalSeparator() {
+ return decimalSeparator;
+ }
+
+ public String getGroupingSeparator() {
+ return groupingSeparator;
+ }
+
+ public FormattingOptions withPattern(String pattern) {
+ this.pattern = pattern;
+ return this;
+ }
+
+ public FormattingOptions withLocale(String locale) {
+ this.locale = getLocale(locale);
+ return this;
+ }
+
+ public FormattingOptions withTimezone(String timezone) {
+ this.timezone = timezone;
+ return this;
+ }
+
+ public FormattingOptions withPrecision(int precision) {
+ this.precision = precision;
+ return this;
+ }
+
+ public FormattingOptions withRounding(String rounding) {
+ this.rounding = rounding;
+ return this;
+ }
+
+ public FormattingOptions withImpliedDecimalSeparator(boolean impliedDecimalSeparator) {
+ this.impliedDecimalSeparator = impliedDecimalSeparator;
+ return this;
+ }
+
+ public FormattingOptions withDecimalSeparator(String decimalSeparator) {
+ this.decimalSeparator = decimalSeparator;
+ return this;
+ }
+
+ public FormattingOptions withGroupingSeparator(String groupingSeparator) {
+ this.groupingSeparator = groupingSeparator;
+ return this;
+ }
+
+ public FormattingOptions forClazz(Class<?> clazz) {
+ this.clazz = clazz;
+ return this;
+ }
+
+ public Class<?> getClazz() {
+ return clazz;
+ }
+
+ private Locale getLocale(String locale) {
+ if ("default".equals(locale)) {
+ return Locale.getDefault();
+ }
+
+ Locale answer = null;
+ if (ObjectHelper.isNotEmpty(locale)) {
+ String[] result = locale.split("-");
+ if (result.length <= 2) {
+ answer = result.length == 1 ? new Locale(result[0]) : new Locale(result[0], result[1]);
+ }
+ }
+ return answer;
+ }
+
+ public FormattingOptions withBindyConverter(BindyConverter bindyConverter) {
+ this.bindyConverter = bindyConverter;
+ return this;
+ }
+
+ public BindyConverter getBindyConverter() {
+ return bindyConverter;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
index e88e6ea..1622064 100755
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
@@ -190,7 +190,7 @@ public class BindyCsvDataFormat extends BindyAbstractDataFormat {
}
}
- // Test if models list is empty or not
+ // BigIntegerFormatFactory if models list is empty or not
// If this is the case (correspond to an empty stream, ...)
if (models.size() == 0) {
throw new java.lang.IllegalArgumentException("No records have been defined in the CSV");
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
index af8f6a3..ffbed62 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
@@ -237,7 +237,7 @@ public class BindyFixedLengthDataFormat extends BindyAbstractDataFormat {
}
}
- // Test if models list is empty or not
+ // BigIntegerFormatFactory if models list is empty or not
// If this is the case (correspond to an empty stream, ...)
if (models.size() == 0) {
throw new java.lang.IllegalArgumentException("No records have been defined in the the file");
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigDecimalFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigDecimalFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigDecimalFormat.java
deleted file mode 100755
index defba11..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigDecimalFormat.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.Locale;
-
-
-public class BigDecimalFormat extends AbstractNumberFormat<BigDecimal> {
-
- public BigDecimalFormat(boolean impliedDecimalPosition, int precision, Locale locale) {
- super(impliedDecimalPosition, precision, locale);
- }
-
- public String format(BigDecimal object) throws Exception {
- return !super.hasImpliedDecimalPosition()
- ? super.getFormat().format(object)
- : super.getFormat().format(object.multiply(new BigDecimal(super.getMultiplier())));
- }
-
- public BigDecimal parse(String string) throws Exception {
- BigDecimal result = new BigDecimal(string.trim());
- if (super.hasImpliedDecimalPosition()) {
- result = result.divide(new BigDecimal(super.getMultiplier()), super.getPrecision(), RoundingMode.HALF_EVEN);
- } else {
- if (super.getPrecision() != -1) {
- result = result.setScale(super.getPrecision());
- }
- }
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigDecimalPatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigDecimalPatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigDecimalPatternFormat.java
deleted file mode 100644
index ba208b8..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigDecimalPatternFormat.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.text.DecimalFormat;
-import java.util.Locale;
-
-public class BigDecimalPatternFormat extends NumberPatternFormat<BigDecimal> {
-
- public BigDecimalPatternFormat() {
- }
-
- public BigDecimalPatternFormat(String pattern, Locale locale, int precision, String rounding, String decimalSeparator, String groupingSeparator) {
- super(pattern, locale, precision, rounding, decimalSeparator, groupingSeparator);
- }
-
- @Override
- public BigDecimal parse(String string) throws Exception {
- if (getNumberFormat() != null) {
- DecimalFormat df = (DecimalFormat)getNumberFormat();
- df.setParseBigDecimal(true);
- BigDecimal bd = (BigDecimal)df.parse(string.trim());
- if (super.getPrecision() != -1) {
- bd = bd.setScale(super.getPrecision(), RoundingMode.valueOf(super.getRounding()));
- }
- return bd;
- } else {
- return new BigDecimal(string.trim());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigIntegerFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigIntegerFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigIntegerFormat.java
deleted file mode 100755
index 42e6ae0..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BigIntegerFormat.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.math.BigInteger;
-
-public class BigIntegerFormat extends AbstractNumberFormat<BigInteger> {
-
- public String format(BigInteger object) throws Exception {
- return object.toString();
- }
-
- public BigInteger parse(String string) throws Exception {
- return new BigInteger(string);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BooleanFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BooleanFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BooleanFormat.java
deleted file mode 100755
index ac0955f..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BooleanFormat.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.bindy.format;
-
-import org.apache.camel.dataformat.bindy.Format;
-
-public class BooleanFormat implements Format<Boolean> {
-
- public String format(Boolean object) throws Exception {
- return object.toString();
- }
-
- public Boolean parse(String string) throws Exception {
- return Boolean.valueOf(string);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ByteFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ByteFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ByteFormat.java
deleted file mode 100755
index fc87544..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ByteFormat.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.bindy.format;
-
-import org.apache.camel.dataformat.bindy.Format;
-
-public class ByteFormat implements Format<Byte> {
-
- public String format(Byte object) throws Exception {
- return object.toString();
- }
-
- public Byte parse(String string) throws Exception {
- return new Byte(string);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BytePatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BytePatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BytePatternFormat.java
deleted file mode 100755
index d04f869..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BytePatternFormat.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.util.Locale;
-
-public class BytePatternFormat extends NumberPatternFormat<Byte> {
-
- public BytePatternFormat() {
- }
-
- public BytePatternFormat(String pattern, Locale locale) {
- super(pattern, locale);
- }
-
- @Override
- public Byte parse(String string) throws Exception {
- if (getNumberFormat() != null) {
- return getNumberFormat().parse(string).byteValue();
- } else {
- return Byte.valueOf(string);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/CharacterFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/CharacterFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/CharacterFormat.java
deleted file mode 100755
index 7f37d75..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/CharacterFormat.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.text.ParseException;
-
-import org.apache.camel.dataformat.bindy.Format;
-
-public class CharacterFormat implements Format<Character> {
-
- public String format(Character object) throws Exception {
- return object.toString();
- }
-
- public Character parse(String string) throws Exception {
- if (string.length() > 1) {
- throw new ParseException("The string \"" + string + "\" cannot be parsed to a character (size > 1).", 1);
- }
- return string.charAt(0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java
deleted file mode 100755
index dbf1bb1..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import org.apache.camel.dataformat.bindy.PatternFormat;
-import org.apache.camel.util.ObjectHelper;
-
-public class DatePatternFormat implements PatternFormat<Date> {
-
- private String pattern;
- private Locale locale;
- private TimeZone timezone;
-
- public DatePatternFormat() {
- }
-
- public DatePatternFormat(String pattern, Locale locale) {
- this.pattern = pattern;
- this.locale = locale;
- }
-
- public DatePatternFormat(String pattern, String timezone, Locale locale) {
- this.pattern = pattern;
- this.locale = locale;
- if (!timezone.isEmpty()) {
- this.timezone = TimeZone.getTimeZone(timezone);
- }
- }
-
- public String format(Date object) throws Exception {
- ObjectHelper.notNull(this.pattern, "pattern");
- return this.getDateFormat().format(object);
- }
-
- public Date parse(String string) throws Exception {
-
- Date date;
- DateFormat df = this.getDateFormat();
-
- ObjectHelper.notNull(this.pattern, "pattern");
-
- // Check length of the string with date pattern
- // To avoid to parse a string date : 20090901-10:32:30 when
- // the pattern is yyyyMMdd
-
- if (string.length() <= this.pattern.length()) {
-
- // Force the parser to be strict in the syntax of the date to be
- // converted
- df.setLenient(false);
- date = df.parse(string);
-
- return date;
-
- } else {
- throw new FormatException("Date provided does not fit the pattern defined");
- }
-
- }
-
- protected java.text.DateFormat getDateFormat() {
- SimpleDateFormat result;
- if (locale != null) {
- result = new SimpleDateFormat(pattern, locale);
- } else {
- result = new SimpleDateFormat(pattern);
- }
- if (timezone != null) {
- result.setTimeZone(timezone);
- }
- return result;
- }
-
- public String getPattern() {
- return pattern;
- }
-
- /**
- * Sets the pattern
- *
- * @param pattern the pattern
- */
- public void setPattern(String pattern) {
- this.pattern = pattern;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoubleFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoubleFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoubleFormat.java
deleted file mode 100755
index 4986365..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoubleFormat.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.math.BigDecimal;
-import java.util.Locale;
-
-public class DoubleFormat extends AbstractNumberFormat<Double> {
-
- public DoubleFormat(boolean impliedDecimalPosition, int precision, Locale locale) {
- super(impliedDecimalPosition, precision, locale);
- }
-
- public String format(Double object) throws Exception {
- return !super.hasImpliedDecimalPosition()
- ? super.getFormat().format(object)
- : super.getFormat().format(object * super.getMultiplier());
- }
-
- public Double parse(String string) throws Exception {
- Double value = null;
- if (!super.hasImpliedDecimalPosition()) {
- value = Double.parseDouble(string.trim());
- } else {
- BigDecimal tmp = new BigDecimal(string.trim());
- BigDecimal div = BigDecimal.valueOf(super.getMultiplier());
- value = tmp.divide(div).doubleValue();
- }
-
- return value;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoublePatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoublePatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoublePatternFormat.java
deleted file mode 100755
index 3318934..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoublePatternFormat.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.util.Locale;
-
-public class DoublePatternFormat extends NumberPatternFormat<Double> {
-
- public DoublePatternFormat() {
- }
-
- public DoublePatternFormat(String pattern, Locale locale) {
- super(pattern, locale);
- }
-
- @Override
- public Double parse(String string) throws Exception {
- if (getNumberFormat() != null) {
- return getNumberFormat().parse(string).doubleValue();
- } else {
- return Double.valueOf(string);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/EnumFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/EnumFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/EnumFormat.java
deleted file mode 100644
index 4245222..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/EnumFormat.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.bindy.format;
-
-import org.apache.camel.dataformat.bindy.Format;
-
-public class EnumFormat<T extends Enum<T>> implements Format<T> {
-
- private final Class<T> clazz;
-
- public EnumFormat(Class<T> clazz) {
- this.clazz = clazz;
- }
-
- public String format(final T object) throws Exception {
- return object.name();
- }
-
- public T parse(final String string) throws Exception {
- return Enum.valueOf(clazz, string);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatFormat.java
deleted file mode 100755
index 6540d0e..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatFormat.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.math.BigDecimal;
-import java.util.Locale;
-
-public class FloatFormat extends AbstractNumberFormat<Float> {
-
- public FloatFormat(boolean impliedDecimalPosition, int precision, Locale locale) {
- super(impliedDecimalPosition, precision, locale);
- }
-
- public String format(Float object) throws Exception {
- return !super.hasImpliedDecimalPosition()
- ? super.getFormat().format(object)
- : super.getFormat().format(object * super.getMultiplier());
- }
-
- public Float parse(String string) throws Exception {
- Float value = null;
- if (!super.hasImpliedDecimalPosition()) {
- value = Float.parseFloat(string.trim());
- } else {
- BigDecimal tmp = new BigDecimal(string.trim());
- BigDecimal div = BigDecimal.valueOf(super.getMultiplier());
- value = tmp.divide(div).floatValue();
- }
-
- return value;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatPatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatPatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatPatternFormat.java
deleted file mode 100755
index dbe351e..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatPatternFormat.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.util.Locale;
-
-public class FloatPatternFormat extends NumberPatternFormat<Float> {
-
- public FloatPatternFormat() {
- }
-
- public FloatPatternFormat(String pattern, Locale locale) {
- super(pattern, locale);
- }
-
- @Override
- public Float parse(String string) throws Exception {
- if (getNumberFormat() != null) {
- return getNumberFormat().parse(string).floatValue();
- } else {
- return Float.valueOf(string);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerFormat.java
deleted file mode 100755
index 5d1c0b4..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerFormat.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 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.bindy.format;
-
-
-public class IntegerFormat extends AbstractNumberFormat<Integer> {
-
- public String format(Integer object) throws Exception {
- return object.toString();
- }
-
- public Integer parse(String string) throws Exception {
- return new Integer(string);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerPatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerPatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerPatternFormat.java
deleted file mode 100755
index 3963830..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerPatternFormat.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.util.Locale;
-
-public class IntegerPatternFormat extends NumberPatternFormat<Integer> {
-
- public IntegerPatternFormat() {
- }
-
- public IntegerPatternFormat(String pattern, Locale locale) {
- super(pattern, locale);
- }
-
- @Override
- public Integer parse(String string) throws Exception {
- if (getNumberFormat() != null) {
- return getNumberFormat().parse(string).intValue();
- } else {
- return Integer.valueOf(string);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalDatePatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalDatePatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalDatePatternFormat.java
deleted file mode 100644
index 0b4daee..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalDatePatternFormat.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.time.LocalDate;
-import java.time.format.DateTimeFormatter;
-import java.util.Locale;
-import org.apache.camel.dataformat.bindy.PatternFormat;
-import org.apache.camel.util.ObjectHelper;
-
-public class LocalDatePatternFormat implements PatternFormat<LocalDate> {
-
- private String pattern;
- private Locale locale;
-
- public LocalDatePatternFormat() {
- }
-
- public LocalDatePatternFormat(String pattern, Locale locale) {
- this.pattern = pattern;
- this.locale = locale;
- }
-
- public String format(LocalDate object) throws Exception {
- ObjectHelper.notNull(this.pattern, "pattern");
- return this.getDateFormat().format(object);
- }
-
- public LocalDate parse(String string) throws Exception {
-
- LocalDate date;
- DateTimeFormatter df = this.getDateFormat();
-
- ObjectHelper.notNull(this.pattern, "pattern");
-
- if (doesStringFitLengthOfPattern(string)) {
- date = LocalDate.parse(string, df);
- return date;
- } else {
- throw new FormatException("Date provided does not fit the pattern defined");
- }
-
- }
-
- private boolean doesStringFitLengthOfPattern(String string) {
- return string.length() <= this.pattern.length();
- }
-
- protected DateTimeFormatter getDateFormat() {
- DateTimeFormatter result;
- if (locale != null) {
- result = DateTimeFormatter.ofPattern(pattern, locale);
- } else {
- result = DateTimeFormatter.ofPattern(pattern);
- }
- return result;
- }
-
- public String getPattern() {
- return pattern;
- }
-
- /**
- * Sets the pattern
- *
- * @param pattern the pattern
- */
- public void setPattern(String pattern) {
- this.pattern = pattern;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalDateTimePatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalDateTimePatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalDateTimePatternFormat.java
deleted file mode 100644
index 62a0399..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalDateTimePatternFormat.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.time.format.DateTimeFormatter;
-import java.util.Locale;
-import org.apache.camel.dataformat.bindy.PatternFormat;
-import org.apache.camel.util.ObjectHelper;
-
-public class LocalDateTimePatternFormat implements PatternFormat<LocalDateTime> {
-
- private String pattern;
- private Locale locale;
- private ZoneId zone;
-
- public LocalDateTimePatternFormat() {
- }
-
- public LocalDateTimePatternFormat(String pattern, String timezone, Locale locale) {
- this.pattern = pattern;
- this.locale = locale;
- if (timezone.isEmpty()) {
- this.zone = ZoneId.systemDefault();
- } else {
- this.zone = ZoneId.of(timezone);
- }
- }
-
- public String format(LocalDateTime object) throws Exception {
- ObjectHelper.notNull(this.pattern, "pattern");
- return this.getDateFormat().format(object);
- }
-
- public LocalDateTime parse(String string) throws Exception {
-
- LocalDateTime date;
- DateTimeFormatter df = this.getDateFormat();
-
- ObjectHelper.notNull(this.pattern, "pattern");
-
- if (doesStringFitLengthOfPattern(string)) {
- date = LocalDateTime.parse(string, df);
- return date;
- } else {
- throw new FormatException("Date provided does not fit the pattern defined");
- }
-
- }
-
- private boolean doesStringFitLengthOfPattern(String string) {
- return string.length() <= this.pattern.length();
- }
-
- protected DateTimeFormatter getDateFormat() {
- DateTimeFormatter result;
- if (locale != null) {
- result = DateTimeFormatter.ofPattern(pattern, locale)
- .withZone(zone);
- } else {
- result = DateTimeFormatter.ofPattern(pattern)
- .withZone(zone);
- }
- return result;
- }
-
- public String getPattern() {
- return pattern;
- }
-
- /**
- * Sets the pattern
- *
- * @param pattern the pattern
- */
- public void setPattern(String pattern) {
- this.pattern = pattern;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalTimePatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalTimePatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalTimePatternFormat.java
deleted file mode 100644
index dbab92f..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LocalTimePatternFormat.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.time.LocalTime;
-import java.time.ZoneId;
-import java.time.format.DateTimeFormatter;
-import java.util.Locale;
-import org.apache.camel.dataformat.bindy.PatternFormat;
-import org.apache.camel.util.ObjectHelper;
-
-
-public class LocalTimePatternFormat implements PatternFormat<LocalTime> {
-
- private String pattern;
- private Locale locale;
- private ZoneId zone;
-
- public LocalTimePatternFormat() {
- }
-
- public LocalTimePatternFormat(String pattern, String timezone, Locale locale) {
- this.pattern = pattern;
- this.locale = locale;
- if (timezone.isEmpty()) {
- this.zone = ZoneId.systemDefault();
- } else {
- this.zone = ZoneId.of(timezone);
- }
- }
-
- public String format(LocalTime object) throws Exception {
- ObjectHelper.notNull(this.pattern, "pattern");
- return this.getDateFormat().format(object);
- }
-
- public LocalTime parse(String string) throws Exception {
-
- LocalTime date;
- DateTimeFormatter df = this.getDateFormat();
-
- ObjectHelper.notNull(this.pattern, "pattern");
-
- if (doesStringFitLengthOfPattern(string)) {
- date = LocalTime.parse(string, df);
- return date;
- } else {
- throw new FormatException("Date provided does not fit the pattern defined");
- }
-
- }
-
- private boolean doesStringFitLengthOfPattern(String string) {
- return string.length() <= this.pattern.length();
- }
-
- protected DateTimeFormatter getDateFormat() {
- DateTimeFormatter result;
- if (locale != null) {
- result = DateTimeFormatter.ofPattern(pattern, locale)
- .withZone(zone);
- } else {
- result = DateTimeFormatter.ofPattern(pattern)
- .withZone(zone);
- }
- return result;
- }
-
- public String getPattern() {
- return pattern;
- }
-
- /**
- * Sets the pattern
- *
- * @param pattern the pattern
- */
- public void setPattern(String pattern) {
- this.pattern = pattern;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongFormat.java
deleted file mode 100755
index 82b6fa6..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongFormat.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 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.bindy.format;
-
-
-public class LongFormat extends AbstractNumberFormat<Long> {
-
- public String format(Long object) throws Exception {
- return object.toString();
- }
-
- public Long parse(String string) throws Exception {
- return new Long(string);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongPatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongPatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongPatternFormat.java
deleted file mode 100755
index 9049e2d..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongPatternFormat.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.util.Locale;
-
-public class LongPatternFormat extends NumberPatternFormat<Long> {
-
- public LongPatternFormat() {
- }
-
- public LongPatternFormat(String pattern, Locale locale) {
- super(pattern, locale);
- }
-
- @Override
- public Long parse(String string) throws Exception {
- if (getNumberFormat() != null) {
- return getNumberFormat().parse(string).longValue();
- } else {
- return Long.valueOf(string);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortFormat.java
deleted file mode 100755
index 62bb103..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortFormat.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 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.bindy.format;
-
-
-public class ShortFormat extends AbstractNumberFormat<Short> {
-
- public String format(Short object) throws Exception {
- return object.toString();
- }
-
- public Short parse(String string) throws Exception {
- return new Short(string);
- }
-
-}
[2/4] camel git commit: CAMEL-9954: FormatFactory should be real
Factory-pattern
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactoryTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactoryTest.java
new file mode 100644
index 0000000..5dbdeb4
--- /dev/null
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactoryTest.java
@@ -0,0 +1,48 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.math.BigDecimal;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.*;
+
+public class BigDecimalFormatFactoryTest {
+
+ private FormattingOptions formattingOptions = new FormattingOptions()
+ .forClazz(BigDecimal.class);
+ private FormattingOptions wrongClass = new FormattingOptions()
+ .forClazz(Integer.class);
+ private FormattingOptions hasPattern = new FormattingOptions()
+ .forClazz(BigDecimal.class)
+ .withPattern("999.99");
+
+ @Test
+ public void canBuild() throws Exception {
+ assertThat(new BigDecimalFormatFactory().canBuild(formattingOptions), is(true));
+ assertThat(new BigDecimalFormatFactory().canBuild(wrongClass), is(false));
+ assertThat(new BigDecimalFormatFactory().canBuild(hasPattern), is(false));
+ }
+
+ @Test
+ public void build() throws Exception {
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
index 04f1857..b3dc526 100644
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
@@ -51,7 +51,7 @@ public class BindyDatePatternCsvUnmarshallTest extends AbstractJUnit4SpringConte
@Test
@DirtiesContext
public void testUnMarshallMessage() throws Exception {
- expected = "10,Christian,Mueller,12-24-2013,12-26-2015,01-06-2016 12:14:49,13:15:01";
+ expected = "10,Christian,Mueller,12-24-2013,12-26-2015,01-06-2016 12:14:49,13:15:01,broken";
result.expectedBodiesReceived(expected + "\r\n");
@@ -97,6 +97,9 @@ public class BindyDatePatternCsvUnmarshallTest extends AbstractJUnit4SpringConte
@DataField(pos = 7, pattern = "HH:mm:ss")
private LocalTime receivedTime;
+ @DataField(pos = 8)
+ private ReturnReason returnReason;
+
public int getOrderNr() {
return orderNr;
}
@@ -157,5 +160,18 @@ public class BindyDatePatternCsvUnmarshallTest extends AbstractJUnit4SpringConte
public void setReceivedTime(LocalTime receivedTime) {
this.receivedTime = receivedTime;
}
+
+ public ReturnReason getReturnReason() {
+ return returnReason;
+ }
+
+ public void setReturnReason(ReturnReason returnReason) {
+ this.returnReason = returnReason;
+ }
+ }
+
+ public enum ReturnReason {
+ broken,
+ other
}
}
[3/4] camel git commit: CAMEL-9954: FormatFactory should be real
Factory-pattern
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortPatternFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortPatternFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortPatternFormat.java
deleted file mode 100755
index 6d16bbd..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortPatternFormat.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.bindy.format;
-
-import java.util.Locale;
-
-public class ShortPatternFormat extends NumberPatternFormat<Short> {
-
- public ShortPatternFormat() {
- }
-
- public ShortPatternFormat(String pattern, Locale locale) {
- super(pattern, locale);
- }
-
- @Override
- public Short parse(String string) throws Exception {
- if (getNumberFormat() != null) {
- return getNumberFormat().parse(string).shortValue();
- } else {
- return Short.valueOf(string);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/StringFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/StringFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/StringFormat.java
deleted file mode 100755
index 7323906..0000000
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/StringFormat.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.bindy.format;
-
-import org.apache.camel.dataformat.bindy.Format;
-
-public class StringFormat implements Format<String> {
-
- public String format(String object) throws Exception {
- return object;
- }
-
- public String parse(String string) throws Exception {
- return string;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/AbstractFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/AbstractFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/AbstractFormatFactory.java
new file mode 100644
index 0000000..39c89ab
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/AbstractFormatFactory.java
@@ -0,0 +1,37 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+
+public abstract class AbstractFormatFactory implements FormatFactoryInterface {
+ protected final List<Class<?>> supportedClasses = new ArrayList<>();
+
+ @Override
+ public Collection<Class<?>> supportedClasses() {
+ return Collections.unmodifiableList(supportedClasses);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return supportedClasses.contains(formattingOptions.getClazz());
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactory.java
new file mode 100644
index 0000000..3159c36
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactory.java
@@ -0,0 +1,70 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.AbstractNumberFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class BigDecimalFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(BigDecimal.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions) && ObjectHelper.isEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new BigDecimalFormat(formattingOptions.isImpliedDecimalSeparator(),
+ formattingOptions.getPrecision(),
+ formattingOptions.getLocale());
+ }
+
+ private static class BigDecimalFormat extends AbstractNumberFormat<BigDecimal> {
+
+ BigDecimalFormat(boolean impliedDecimalPosition, int precision, Locale locale) {
+ super(impliedDecimalPosition, precision, locale);
+ }
+
+ public String format(BigDecimal object) throws Exception {
+ return !super.hasImpliedDecimalPosition()
+ ? super.getFormat().format(object)
+ : super.getFormat().format(object.multiply(new BigDecimal(super.getMultiplier())));
+ }
+
+ public BigDecimal parse(String string) throws Exception {
+ BigDecimal result = new BigDecimal(string.trim());
+ if (super.hasImpliedDecimalPosition()) {
+ result = result.divide(new BigDecimal(super.getMultiplier()), super.getPrecision(), RoundingMode.HALF_EVEN);
+ } else {
+ if (super.getPrecision() != -1) {
+ result = result.setScale(super.getPrecision());
+ }
+ }
+ return result;
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalPatternFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalPatternFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalPatternFormatFactory.java
new file mode 100644
index 0000000..c294be3
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalPatternFormatFactory.java
@@ -0,0 +1,71 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.DecimalFormat;
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.NumberPatternFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class BigDecimalPatternFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(BigDecimal.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions) && ObjectHelper.isNotEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new BigDecimalPatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getLocale(),
+ formattingOptions.getPrecision(),
+ formattingOptions.getRounding(),
+ formattingOptions.getDecimalSeparator(),
+ formattingOptions.getGroupingSeparator());
+ }
+
+ private static class BigDecimalPatternFormat extends NumberPatternFormat<BigDecimal> {
+
+ BigDecimalPatternFormat(String pattern, Locale locale, int precision, String rounding, String decimalSeparator, String groupingSeparator) {
+ super(pattern, locale, precision, rounding, decimalSeparator, groupingSeparator);
+ }
+
+ @Override
+ public BigDecimal parse(String string) throws Exception {
+ if (getNumberFormat() != null) {
+ DecimalFormat df = (DecimalFormat)getNumberFormat();
+ df.setParseBigDecimal(true);
+ BigDecimal bd = (BigDecimal)df.parse(string.trim());
+ if (super.getPrecision() != -1) {
+ bd = bd.setScale(super.getPrecision(), RoundingMode.valueOf(super.getRounding()));
+ }
+ return bd;
+ } else {
+ return new BigDecimal(string.trim());
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigIntegerFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigIntegerFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigIntegerFormatFactory.java
new file mode 100644
index 0000000..a8a72fb
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigIntegerFormatFactory.java
@@ -0,0 +1,53 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.math.BigInteger;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.AbstractNumberFormat;
+
+public class BigIntegerFormatFactory extends AbstractFormatFactory {
+
+ private static final BigIntegerFormat BIG_INTEGER_FORMAT = new BigIntegerFormat();
+
+ {
+ supportedClasses.add(BigInteger.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions);
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return BIG_INTEGER_FORMAT;
+ }
+
+ private static class BigIntegerFormat extends AbstractNumberFormat<BigInteger> {
+
+ public String format(BigInteger object) throws Exception {
+ return object.toString();
+ }
+
+ public BigInteger parse(String string) throws Exception {
+ return new BigInteger(string);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java
new file mode 100755
index 0000000..bc150e8
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java
@@ -0,0 +1,47 @@
+/**
+ * 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.bindy.format.factories;
+
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+
+public class BooleanFormatFactory extends AbstractFormatFactory {
+
+ private static final BooleanFormat BOOLEAN_FORMAT = new BooleanFormat();
+
+ {
+ supportedClasses.add(boolean.class);
+ supportedClasses.add(Boolean.class);
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return BOOLEAN_FORMAT;
+ }
+
+ private static class BooleanFormat implements Format<Boolean> {
+
+ public String format(Boolean object) throws Exception {
+ return object.toString();
+ }
+
+ public Boolean parse(String string) throws Exception {
+ return Boolean.valueOf(string);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ByteFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ByteFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ByteFormatFactory.java
new file mode 100644
index 0000000..457270f
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ByteFormatFactory.java
@@ -0,0 +1,54 @@
+/**
+ * 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.bindy.format.factories;
+
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.util.ObjectHelper;
+
+public class ByteFormatFactory extends AbstractFormatFactory {
+
+ private static final ByteFormat BYTE_FORMAT = new ByteFormat();
+
+ {
+ supportedClasses.add(byte.class);
+ supportedClasses.add(Byte.class);
+ }
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return BYTE_FORMAT;
+ }
+
+ private static class ByteFormat implements Format<Byte> {
+
+ public String format(Byte object) throws Exception {
+ return object.toString();
+ }
+
+ public Byte parse(String string) throws Exception {
+ return new Byte(string);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BytePatternFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BytePatternFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BytePatternFormatFactory.java
new file mode 100644
index 0000000..b795c35
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BytePatternFormatFactory.java
@@ -0,0 +1,60 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.NumberPatternFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class BytePatternFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(byte.class);
+ supportedClasses.add(Byte.class);
+ }
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isNotEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new BytePatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getLocale());
+ }
+
+ private static class BytePatternFormat extends NumberPatternFormat<Byte> {
+
+ BytePatternFormat(String pattern, Locale locale) {
+ super(pattern, locale);
+ }
+
+ @Override
+ public Byte parse(String string) throws Exception {
+ if (getNumberFormat() != null) {
+ return getNumberFormat().parse(string).byteValue();
+ } else {
+ return Byte.valueOf(string);
+ }
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/CharacterFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/CharacterFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/CharacterFormatFactory.java
new file mode 100644
index 0000000..83786c7
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/CharacterFormatFactory.java
@@ -0,0 +1,51 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.text.ParseException;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+
+public class CharacterFormatFactory extends AbstractFormatFactory {
+
+ private static final CharacterFormat CHARACTER_FORMAT = new CharacterFormat();
+
+ {
+ supportedClasses.add(char.class);
+ supportedClasses.add(Character.class);
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return CHARACTER_FORMAT;
+ }
+
+ private static class CharacterFormat implements Format<Character> {
+
+ public String format(Character object) throws Exception {
+ return object.toString();
+ }
+
+ public Character parse(String string) throws Exception {
+ if (string.length() > 1) {
+ throw new ParseException("The string \"" + string + "\" cannot be parsed to a character (size > 1).", 1);
+ }
+ return string.charAt(0);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DateFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DateFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DateFormatFactory.java
new file mode 100644
index 0000000..40582f3
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DateFormatFactory.java
@@ -0,0 +1,114 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.PatternFormat;
+import org.apache.camel.dataformat.bindy.format.FormatException;
+import org.apache.camel.util.ObjectHelper;
+
+public class DateFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(Date.class);
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new DatePatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getTimezone(),
+ formattingOptions.getLocale());
+ }
+
+ private static class DatePatternFormat implements PatternFormat<Date> {
+
+ private String pattern;
+ private Locale locale;
+ private TimeZone timezone;
+
+ DatePatternFormat(String pattern, String timezone, Locale locale) {
+ this.pattern = pattern;
+ this.locale = locale;
+ if (!timezone.isEmpty()) {
+ this.timezone = TimeZone.getTimeZone(timezone);
+ }
+ }
+
+ public String format(Date object) throws Exception {
+ ObjectHelper.notNull(this.pattern, "pattern");
+ return this.getDateFormat().format(object);
+ }
+
+ public Date parse(String string) throws Exception {
+
+ Date date;
+ DateFormat df = this.getDateFormat();
+
+ ObjectHelper.notNull(this.pattern, "pattern");
+
+ // Check length of the string with date pattern
+ // To avoid to parse a string date : 20090901-10:32:30 when
+ // the pattern is yyyyMMdd
+
+ if (string.length() <= this.pattern.length()) {
+
+ // Force the parser to be strict in the syntax of the date to be
+ // converted
+ df.setLenient(false);
+ date = df.parse(string);
+
+ return date;
+
+ } else {
+ throw new FormatException("Date provided does not fit the pattern defined");
+ }
+
+ }
+
+ protected java.text.DateFormat getDateFormat() {
+ SimpleDateFormat result;
+ if (locale != null) {
+ result = new SimpleDateFormat(pattern, locale);
+ } else {
+ result = new SimpleDateFormat(pattern);
+ }
+ if (timezone != null) {
+ result.setTimeZone(timezone);
+ }
+ return result;
+ }
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ /**
+ * Sets the pattern
+ *
+ * @param pattern the pattern
+ */
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DoubleFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DoubleFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DoubleFormatFactory.java
new file mode 100644
index 0000000..9cb44b1
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DoubleFormatFactory.java
@@ -0,0 +1,71 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.math.BigDecimal;
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.AbstractNumberFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class DoubleFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(double.class);
+ supportedClasses.add(Double.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new DoubleFormat(formattingOptions.isImpliedDecimalSeparator(),
+ formattingOptions.getPrecision(),
+ formattingOptions.getLocale());
+ }
+
+ private static class DoubleFormat extends AbstractNumberFormat<Double> {
+
+ DoubleFormat(boolean impliedDecimalPosition, int precision, Locale locale) {
+ super(impliedDecimalPosition, precision, locale);
+ }
+
+ public String format(Double object) throws Exception {
+ return !super.hasImpliedDecimalPosition()
+ ? super.getFormat().format(object)
+ : super.getFormat().format(object * super.getMultiplier());
+ }
+
+ public Double parse(String string) throws Exception {
+ Double value = null;
+ if (!super.hasImpliedDecimalPosition()) {
+ value = Double.parseDouble(string.trim());
+ } else {
+ BigDecimal tmp = new BigDecimal(string.trim());
+ BigDecimal div = BigDecimal.valueOf(super.getMultiplier());
+ value = tmp.divide(div).doubleValue();
+ }
+
+ return value;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DoublePatternFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DoublePatternFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DoublePatternFormatFactory.java
new file mode 100644
index 0000000..0aade73
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DoublePatternFormatFactory.java
@@ -0,0 +1,61 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.NumberPatternFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class DoublePatternFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(double.class);
+ supportedClasses.add(Double.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isNotEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new DoublePatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getLocale());
+ }
+
+ private static class DoublePatternFormat extends NumberPatternFormat<Double> {
+
+ DoublePatternFormat(String pattern, Locale locale) {
+ super(pattern, locale);
+ }
+
+ @Override
+ public Double parse(String string) throws Exception {
+ if (getNumberFormat() != null) {
+ return getNumberFormat().parse(string).doubleValue();
+ } else {
+ return Double.valueOf(string);
+ }
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/EnumFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/EnumFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/EnumFormatFactory.java
new file mode 100644
index 0000000..a5639da
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/EnumFormatFactory.java
@@ -0,0 +1,53 @@
+/**
+ * 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.bindy.format.factories;
+
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+
+public class EnumFormatFactory extends AbstractFormatFactory {
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return formattingOptions.getClazz().isEnum();
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ EnumFormat enumFormat = new EnumFormat(formattingOptions.getClazz());
+ return enumFormat;
+ }
+
+ private static class EnumFormat<T extends Enum<T>> implements Format<T> {
+
+ private final Class<T> clazz;
+
+ EnumFormat(Class<T> clazz) {
+ this.clazz = clazz;
+ }
+
+ public String format(final T object) throws Exception {
+ return object.name();
+ }
+
+ public T parse(final String string) throws Exception {
+ return Enum.valueOf(clazz, string);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FloatFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FloatFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FloatFormatFactory.java
new file mode 100644
index 0000000..f2a3031
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FloatFormatFactory.java
@@ -0,0 +1,72 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.math.BigDecimal;
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.AbstractNumberFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class FloatFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(float.class);
+ supportedClasses.add(Float.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new FloatFormat(formattingOptions.isImpliedDecimalSeparator(),
+ formattingOptions.getPrecision(),
+ formattingOptions.getLocale());
+ }
+
+ private static class FloatFormat extends AbstractNumberFormat<Float> {
+
+ FloatFormat(boolean impliedDecimalPosition, int precision, Locale locale) {
+ super(impliedDecimalPosition, precision, locale);
+ }
+
+ public String format(Float object) throws Exception {
+ return !super.hasImpliedDecimalPosition()
+ ? super.getFormat().format(object)
+ : super.getFormat().format(object * super.getMultiplier());
+ }
+
+ public Float parse(String string) throws Exception {
+ Float value;
+ if (!super.hasImpliedDecimalPosition()) {
+ value = Float.parseFloat(string.trim());
+ } else {
+ BigDecimal tmp = new BigDecimal(string.trim());
+ BigDecimal div = BigDecimal.valueOf(super.getMultiplier());
+ value = tmp.divide(div).floatValue();
+ }
+
+ return value;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FloatPatternFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FloatPatternFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FloatPatternFormatFactory.java
new file mode 100644
index 0000000..1d5bd1f
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FloatPatternFormatFactory.java
@@ -0,0 +1,61 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.NumberPatternFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class FloatPatternFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(float.class);
+ supportedClasses.add(Float.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isNotEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new FloatPatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getLocale());
+ }
+
+ private static class FloatPatternFormat extends NumberPatternFormat<Float> {
+
+ FloatPatternFormat(String pattern, Locale locale) {
+ super(pattern, locale);
+ }
+
+ @Override
+ public Float parse(String string) throws Exception {
+ if (getNumberFormat() != null) {
+ return getNumberFormat().parse(string).floatValue();
+ } else {
+ return Float.valueOf(string);
+ }
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactories.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactories.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactories.java
new file mode 100644
index 0000000..2b9eec8
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactories.java
@@ -0,0 +1,99 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+
+/**
+ * This class manages all FormatFactoryInterfaces.
+ * This class is a singleton class.
+ * FormatFactoryInterfaces can declare to support one or more classes or
+ * can declare to be generic (e.g. {@link EnumFormatFactory}).
+ * The factories that support one or more classes are stored in a Map.
+ * The generic factories are stored in a list.
+ * The build method first tries to find a factory using the map.
+ * If it doesn't find one it uses the generic list.
+ * If it can't find a factory it throws an IllegalArgumentException.
+ */
+public final class FormatFactories extends AbstractFormatFactory {
+
+ private static final FormatFactories INSTANCE = new FormatFactories();
+ private static final Map<Class<?>, List<FormatFactoryInterface>> CLASS_BASED_FACTORIES = new HashMap<>();
+ private static final List<FormatFactoryInterface> OTHER_FACTORIES = new ArrayList<>();
+
+ private FormatFactories() {
+ }
+
+ public static FormatFactories getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Registers a {@link FormatFactoryInterface}.
+ * Two types of factories exist:
+ * <ul>
+ * <li>Factories that support one or more classes</li>
+ * <li>Factories that support no specific class (e.g. {@link EnumFormatFactory})</li>
+ * </ul>
+ * @param formatFactory
+ * @return the FormatFactories instance
+ */
+ public synchronized FormatFactories register(FormatFactoryInterface formatFactory) {
+ if (formatFactory.supportedClasses().isEmpty()) {
+ OTHER_FACTORIES.add(formatFactory);
+ } else {
+ for (Class<?> clazz : formatFactory.supportedClasses()) {
+ getByClass(clazz).add(formatFactory);
+ }
+ }
+ return this;
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return true;
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ for (FormatFactoryInterface formatFactory : getByClass(formattingOptions.getClazz())) {
+ if (formatFactory.canBuild(formattingOptions)) {
+ return formatFactory.build(formattingOptions);
+ }
+ }
+ for (FormatFactoryInterface formatFactory : OTHER_FACTORIES) {
+ if (formatFactory.canBuild(formattingOptions)) {
+ return formatFactory.build(formattingOptions);
+ }
+ }
+ throw new IllegalArgumentException("Can not find a suitable formatter for the type: " + formattingOptions.getClazz().getCanonicalName());
+ }
+
+ private List<FormatFactoryInterface> getByClass(Class<?> clazz) {
+ List<FormatFactoryInterface> result = CLASS_BASED_FACTORIES.get(clazz);
+ if (result == null) {
+ result = new ArrayList<>();
+ CLASS_BASED_FACTORIES.put(clazz, result);
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactoryInterface.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactoryInterface.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactoryInterface.java
new file mode 100644
index 0000000..1e0347a
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FormatFactoryInterface.java
@@ -0,0 +1,48 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.util.Collection;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+
+public interface FormatFactoryInterface {
+ /**
+ * Returns the list of supported classes.
+ * When the list doesn't contain elements the factory is supposed
+ * to support all kinds of classes. The factory must decide on other
+ * criteria whether it can build a {@link Format}.
+ * @return the list of supported classes
+ */
+ Collection<Class<?>> supportedClasses();
+
+ /**
+ * Can it build a {@link Format}.
+ * Answers the question about whether it can
+ * build a {@link Format}.
+ * @param formattingOptions
+ * @return can build
+ */
+ boolean canBuild(FormattingOptions formattingOptions);
+
+ /**
+ * Builds the {@link Format}.
+ * @param formattingOptions
+ * @return the format
+ */
+ Format<?> build(FormattingOptions formattingOptions);
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerFormatFactory.java
new file mode 100644
index 0000000..5335dbf
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerFormatFactory.java
@@ -0,0 +1,56 @@
+/**
+ * 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.bindy.format.factories;
+
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.AbstractNumberFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class IntegerFormatFactory extends AbstractFormatFactory {
+
+ private static final IntegerFormat INTEGER_FORMAT = new IntegerFormat();
+
+ {
+ supportedClasses.add(int.class);
+ supportedClasses.add(Integer.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return INTEGER_FORMAT;
+ }
+
+ private static class IntegerFormat extends AbstractNumberFormat<Integer> {
+
+ public String format(Integer object) throws Exception {
+ return object.toString();
+ }
+
+ public Integer parse(String string) throws Exception {
+ return new Integer(string);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerPatternFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerPatternFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerPatternFormatFactory.java
new file mode 100644
index 0000000..7c81df9
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/IntegerPatternFormatFactory.java
@@ -0,0 +1,61 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.NumberPatternFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class IntegerPatternFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(int.class);
+ supportedClasses.add(Integer.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isNotEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new IntegerPatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getLocale());
+ }
+
+ private static class IntegerPatternFormat extends NumberPatternFormat<Integer> {
+
+ IntegerPatternFormat(String pattern, Locale locale) {
+ super(pattern, locale);
+ }
+
+ @Override
+ public Integer parse(String string) throws Exception {
+ if (getNumberFormat() != null) {
+ return getNumberFormat().parse(string).intValue();
+ } else {
+ return Integer.valueOf(string);
+ }
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalDateFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalDateFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalDateFormatFactory.java
new file mode 100644
index 0000000..64b8606
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalDateFormatFactory.java
@@ -0,0 +1,98 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.PatternFormat;
+import org.apache.camel.dataformat.bindy.format.FormatException;
+import org.apache.camel.util.ObjectHelper;
+
+public class LocalDateFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(LocalDate.class);
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new LocalDatePatternFormat(formattingOptions.getPattern(), formattingOptions.getLocale());
+ }
+
+ private static class LocalDatePatternFormat implements PatternFormat<LocalDate> {
+
+ private String pattern;
+ private Locale locale;
+
+ LocalDatePatternFormat(String pattern, Locale locale) {
+ this.pattern = pattern;
+ this.locale = locale;
+ }
+
+ public String format(LocalDate object) throws Exception {
+ ObjectHelper.notNull(this.pattern, "pattern");
+ return this.getDateFormat().format(object);
+ }
+
+ public LocalDate parse(String string) throws Exception {
+
+ LocalDate date;
+ DateTimeFormatter df = this.getDateFormat();
+
+ ObjectHelper.notNull(this.pattern, "pattern");
+
+ if (doesStringFitLengthOfPattern(string)) {
+ date = LocalDate.parse(string, df);
+ return date;
+ } else {
+ throw new FormatException("Date provided does not fit the pattern defined");
+ }
+
+ }
+
+ private boolean doesStringFitLengthOfPattern(String string) {
+ return string.length() <= this.pattern.length();
+ }
+
+ DateTimeFormatter getDateFormat() {
+ DateTimeFormatter result;
+ if (locale != null) {
+ result = DateTimeFormatter.ofPattern(pattern, locale);
+ } else {
+ result = DateTimeFormatter.ofPattern(pattern);
+ }
+ return result;
+ }
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ /**
+ * Sets the pattern
+ *
+ * @param pattern the pattern
+ */
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalDateTimeFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalDateTimeFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalDateTimeFormatFactory.java
new file mode 100644
index 0000000..109168b
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalDateTimeFormatFactory.java
@@ -0,0 +1,109 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.PatternFormat;
+import org.apache.camel.dataformat.bindy.format.FormatException;
+import org.apache.camel.util.ObjectHelper;
+
+public class LocalDateTimeFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(LocalDateTime.class);
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new LocalDateTimePatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getTimezone(),
+ formattingOptions.getLocale());
+ }
+
+ private static class LocalDateTimePatternFormat implements PatternFormat<LocalDateTime> {
+
+ private String pattern;
+ private Locale locale;
+ private ZoneId zone;
+
+ LocalDateTimePatternFormat(String pattern, String timezone, Locale locale) {
+ this.pattern = pattern;
+ this.locale = locale;
+ if (timezone.isEmpty()) {
+ this.zone = ZoneId.systemDefault();
+ } else {
+ this.zone = ZoneId.of(timezone);
+ }
+ }
+
+ public String format(LocalDateTime object) throws Exception {
+ ObjectHelper.notNull(this.pattern, "pattern");
+ return this.getDateFormat().format(object);
+ }
+
+ public LocalDateTime parse(String string) throws Exception {
+
+ LocalDateTime date;
+ DateTimeFormatter df = this.getDateFormat();
+
+ ObjectHelper.notNull(this.pattern, "pattern");
+
+ if (doesStringFitLengthOfPattern(string)) {
+ date = LocalDateTime.parse(string, df);
+ return date;
+ } else {
+ throw new FormatException("Date provided does not fit the pattern defined");
+ }
+
+ }
+
+ private boolean doesStringFitLengthOfPattern(String string) {
+ return string.length() <= this.pattern.length();
+ }
+
+ DateTimeFormatter getDateFormat() {
+ DateTimeFormatter result;
+ if (locale != null) {
+ result = DateTimeFormatter.ofPattern(pattern, locale)
+ .withZone(zone);
+ } else {
+ result = DateTimeFormatter.ofPattern(pattern)
+ .withZone(zone);
+ }
+ return result;
+ }
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ /**
+ * Sets the pattern
+ *
+ * @param pattern the pattern
+ */
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalTimeFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalTimeFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalTimeFormatFactory.java
new file mode 100644
index 0000000..aa177ab
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LocalTimeFormatFactory.java
@@ -0,0 +1,109 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.PatternFormat;
+import org.apache.camel.dataformat.bindy.format.FormatException;
+import org.apache.camel.util.ObjectHelper;
+
+public class LocalTimeFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(LocalTime.class);
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new LocalTimePatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getTimezone(),
+ formattingOptions.getLocale());
+ }
+
+ private static class LocalTimePatternFormat implements PatternFormat<LocalTime> {
+
+ private String pattern;
+ private Locale locale;
+ private ZoneId zone;
+
+ LocalTimePatternFormat(String pattern, String timezone, Locale locale) {
+ this.pattern = pattern;
+ this.locale = locale;
+ if (timezone.isEmpty()) {
+ this.zone = ZoneId.systemDefault();
+ } else {
+ this.zone = ZoneId.of(timezone);
+ }
+ }
+
+ public String format(LocalTime object) throws Exception {
+ ObjectHelper.notNull(this.pattern, "pattern");
+ return this.getDateFormat().format(object);
+ }
+
+ public LocalTime parse(String string) throws Exception {
+
+ LocalTime date;
+ DateTimeFormatter df = this.getDateFormat();
+
+ ObjectHelper.notNull(this.pattern, "pattern");
+
+ if (doesStringFitLengthOfPattern(string)) {
+ date = LocalTime.parse(string, df);
+ return date;
+ } else {
+ throw new FormatException("Date provided does not fit the pattern defined");
+ }
+
+ }
+
+ private boolean doesStringFitLengthOfPattern(String string) {
+ return string.length() <= this.pattern.length();
+ }
+
+ DateTimeFormatter getDateFormat() {
+ DateTimeFormatter result;
+ if (locale != null) {
+ result = DateTimeFormatter.ofPattern(pattern, locale)
+ .withZone(zone);
+ } else {
+ result = DateTimeFormatter.ofPattern(pattern)
+ .withZone(zone);
+ }
+ return result;
+ }
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ /**
+ * Sets the pattern
+ *
+ * @param pattern the pattern
+ */
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongFormatFactory.java
new file mode 100644
index 0000000..0b3a192
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongFormatFactory.java
@@ -0,0 +1,55 @@
+/**
+ * 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.bindy.format.factories;
+
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.AbstractNumberFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class LongFormatFactory extends AbstractFormatFactory {
+
+ private static final LongFormat LONG_FORMAT = new LongFormat();
+
+ {
+ supportedClasses.add(long.class);
+ supportedClasses.add(Long.class);
+ }
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return LONG_FORMAT;
+ }
+
+ private static class LongFormat extends AbstractNumberFormat<Long> {
+
+ public String format(Long object) throws Exception {
+ return object.toString();
+ }
+
+ public Long parse(String string) throws Exception {
+ return new Long(string);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongPatternFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongPatternFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongPatternFormatFactory.java
new file mode 100644
index 0000000..07d126f
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/LongPatternFormatFactory.java
@@ -0,0 +1,61 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.NumberPatternFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class LongPatternFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(long.class);
+ supportedClasses.add(Long.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isNotEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new LongPatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getLocale());
+ }
+
+ private static class LongPatternFormat extends NumberPatternFormat<Long> {
+
+ LongPatternFormat(String pattern, Locale locale) {
+ super(pattern, locale);
+ }
+
+ @Override
+ public Long parse(String string) throws Exception {
+ if (getNumberFormat() != null) {
+ return getNumberFormat().parse(string).longValue();
+ } else {
+ return Long.valueOf(string);
+ }
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortFormatFactory.java
new file mode 100644
index 0000000..1475dd3
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortFormatFactory.java
@@ -0,0 +1,56 @@
+/**
+ * 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.bindy.format.factories;
+
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.AbstractNumberFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class ShortFormatFactory extends AbstractFormatFactory {
+
+ private static final ShortFormat SHORT_FORMAT = new ShortFormat();
+
+ {
+ supportedClasses.add(short.class);
+ supportedClasses.add(Short.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return SHORT_FORMAT;
+ }
+
+ private static class ShortFormat extends AbstractNumberFormat<Short> {
+
+ public String format(Short object) throws Exception {
+ return object.toString();
+ }
+
+ public Short parse(String string) throws Exception {
+ return new Short(string);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortPatternFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortPatternFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortPatternFormatFactory.java
new file mode 100644
index 0000000..a193822
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ShortPatternFormatFactory.java
@@ -0,0 +1,60 @@
+/**
+ * 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.bindy.format.factories;
+
+import java.util.Locale;
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.format.NumberPatternFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class ShortPatternFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(short.class);
+ supportedClasses.add(Short.class);
+ }
+
+ @Override
+ public boolean canBuild(FormattingOptions formattingOptions) {
+ return super.canBuild(formattingOptions)
+ && ObjectHelper.isNotEmpty(formattingOptions.getPattern());
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new ShortPatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getLocale());
+ }
+
+ private static class ShortPatternFormat extends NumberPatternFormat<Short> {
+
+ ShortPatternFormat(String pattern, Locale locale) {
+ super(pattern, locale);
+ }
+
+ @Override
+ public Short parse(String string) throws Exception {
+ if (getNumberFormat() != null) {
+ return getNumberFormat().parse(string).shortValue();
+ } else {
+ return Short.valueOf(string);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/StringFormatFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/StringFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/StringFormatFactory.java
new file mode 100644
index 0000000..670440e
--- /dev/null
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/StringFormatFactory.java
@@ -0,0 +1,47 @@
+/**
+ * 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.bindy.format.factories;
+
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+
+public class StringFormatFactory extends AbstractFormatFactory {
+
+ private static final StringFormat STRING_FORMAT = new StringFormat();
+
+ {
+ supportedClasses.add(String.class);
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return STRING_FORMAT;
+ }
+
+ private static class StringFormat implements Format<String> {
+
+ public String format(String object) throws Exception {
+ return object;
+ }
+
+ public String parse(String string) throws Exception {
+ return string;
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
index b27c6d8..65bc353 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
@@ -137,7 +137,7 @@ public class BindyKeyValuePairDataFormat extends BindyAbstractDataFormat {
}
}
- // Test if models list is empty or not
+ // BigIntegerFormatFactory if models list is empty or not
// If this is the case (correspond to an empty stream, ...)
if (models.size() == 0) {
throw new java.lang.IllegalArgumentException("No records have been defined in the CSV");
http://git-wip-us.apache.org/repos/asf/camel/blob/311d429c/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/ConverterUtils.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/ConverterUtils.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/ConverterUtils.java
index 323fdea..778e803 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/ConverterUtils.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/ConverterUtils.java
@@ -16,6 +16,11 @@
*/
package org.apache.camel.dataformat.bindy.util;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.annotation.BindyConverter;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.KeyValuePairField;
+
/**
* To help return the char associated to the unicode string
*/
@@ -60,4 +65,29 @@ public final class ConverterUtils {
return returnCharacter;
}
}
+
+ public static FormattingOptions convert(DataField dataField, Class<?> clazz, BindyConverter converter, String locale) {
+ return new FormattingOptions()
+ .forClazz(clazz)
+ .withPattern(dataField.pattern())
+ .withLocale(locale)
+ .withTimezone(dataField.timezone())
+ .withPrecision(dataField.precision())
+ .withRounding(dataField.rounding())
+ .withImpliedDecimalSeparator(dataField.impliedDecimalSeparator())
+ .withDecimalSeparator(dataField.decimalSeparator())
+ .withBindyConverter(converter)
+ .withGroupingSeparator(dataField.groupingSeparator());
+ }
+
+ public static FormattingOptions convert(KeyValuePairField dataField, Class<?> clazz, BindyConverter converter, String locale) {
+ return new FormattingOptions()
+ .forClazz(clazz)
+ .withPattern(dataField.pattern())
+ .withLocale(locale)
+ .withTimezone(dataField.timezone())
+ .withPrecision(dataField.precision())
+ .withBindyConverter(converter)
+ .withImpliedDecimalSeparator(dataField.impliedDecimalSeparator());
+ }
}