camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r1038476 - in /camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy: ./ csv/ format/ kvp/
Date Wed, 24 Nov 2010 04:53:01 GMT
Author: hadrian
Date: Wed Nov 24 04:53:00 2010
New Revision: 1038476

URL: http://svn.apache.org/viewvc?rev=1038476&view=rev
Log:
CAMEL-3356. Improved locale support in camel-bindy

Added:
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java
Modified:
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BytePatternFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoublePatternFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatPatternFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerPatternFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongPatternFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/NumberPatternFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortPatternFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java

Added: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java?rev=1038476&view=auto
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java
(added)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java
Wed Nov 24 04:53:00 2010
@@ -0,0 +1,68 @@
+/**
+ * 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.kvp.BindyKeyValuePairDataFormat;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.PackageScanClassResolver;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public abstract class BindyAbstractDataFormat implements DataFormat {
+    private String[] packages;
+    private String locale;
+    private BindyAbstractFactory modelFactory;
+
+    public BindyAbstractDataFormat() {
+    }
+
+    public BindyAbstractDataFormat(String... packages) {
+        this.packages = packages;
+    }
+
+    public String[] getPackages() {
+        return packages;
+    }
+
+    public void setPackages(String... packages) {
+        this.packages = packages;
+    }
+
+    public String getLocale() {
+        return locale;
+    }
+
+    public void setLocale(String locale) {
+        this.locale = locale;
+    }
+    
+    public BindyAbstractFactory getFactory(PackageScanClassResolver resolver) throws Exception
{
+        if (modelFactory == null) {
+            modelFactory = createModelFactory(resolver);
+            modelFactory.setLocale(locale);
+        }
+        return modelFactory;
+    }
+    
+    public void setModelFactory(BindyAbstractFactory modelFactory) {
+        this.modelFactory = modelFactory;
+    }
+    
+    protected abstract BindyAbstractFactory createModelFactory(PackageScanClassResolver resolver)
throws Exception;
+}

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
Wed Nov 24 04:53:00 2010
@@ -42,6 +42,7 @@ public abstract class BindyAbstractFacto
 
     private AnnotationModelLoader modelsLoader;
     private String[] packageNames;
+    private String locale;
 
     public BindyAbstractFactory(PackageScanClassResolver resolver, String... packageNames)
throws Exception {
         this.modelsLoader = new AnnotationModelLoader(resolver);
@@ -217,6 +218,13 @@ public abstract class BindyAbstractFacto
         }
 
         return strValue;
+    }
+
+    public String getLocale() {
+        return locale;
+    }
 
+    public void setLocale(String locale) {
+        this.locale = locale;
     }
 }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
Wed Nov 24 04:53:00 2010
@@ -183,7 +183,7 @@ public class BindyCsvFactory extends Bin
             String pattern = dataField.pattern();
 
             // Create format object to format the field
-            format = FormatFactory.getFormat(field.getType(), pattern, dataField.precision());
+            format = FormatFactory.getFormat(field.getType(), pattern, getLocale(), dataField.precision());
 
             // field object to be set
             Object modelField = model.get(field.getDeclaringClass().getName());
@@ -411,7 +411,7 @@ public class BindyCsvFactory extends Bin
                     int precision = datafield.precision();
 
                     // Create format
-                    Format format = FormatFactory.getFormat(type, pattern, precision);
+                    Format format = FormatFactory.getFormat(type, pattern, getLocale(), precision);
 
                     // Get field value
                     Object value = field.get(obj);

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
Wed Nov 24 04:53:00 2010
@@ -214,7 +214,7 @@ public class BindyFixedLengthFactory ext
             pattern = dataField.pattern();
 
             // Create format object to format the field
-            format = FormatFactory.getFormat(field.getType(), pattern, dataField.precision());
+            format = FormatFactory.getFormat(field.getType(), pattern, getLocale(), dataField.precision());
 
             // field object to be set
             Object modelField = model.get(field.getDeclaringClass().getName());
@@ -327,7 +327,7 @@ public class BindyFixedLengthFactory ext
                     int precision = datafield.precision();
 
                     // Create format
-                    Format format = FormatFactory.getFormat(type, pattern, precision);
+                    Format format = FormatFactory.getFormat(type, pattern, getLocale(), precision);
 
                     // Get field value
                     Object value = field.get(obj);

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
Wed Nov 24 04:53:00 2010
@@ -289,7 +289,7 @@ public class BindyKeyValuePairFactory ex
                                 String pattern = keyValuePairField.pattern();
 
                                 // Create format object to format the field
-                                Format<?> format = FormatFactory.getFormat(field.getType(),
pattern, keyValuePairField.precision());
+                                Format<?> format = FormatFactory.getFormat(field.getType(),
pattern, getLocale(), keyValuePairField.precision());
 
                                 // format the value of the key received
                                 result = formatField(format, value, key, line);
@@ -331,7 +331,7 @@ public class BindyKeyValuePairFactory ex
                                     String pattern = keyValuePairField.pattern();
 
                                     // Create format object to format the field
-                                    Format<?> format = FormatFactory.getFormat(field.getType(),
pattern, keyValuePairField.precision());
+                                    Format<?> format = FormatFactory.getFormat(field.getType(),
pattern, getLocale(), keyValuePairField.precision());
 
                                     // format the value of the key received
                                     Object result = formatField(format, value, key, line);
@@ -462,7 +462,7 @@ public class BindyKeyValuePairFactory ex
             int precision = keyValuePairField.precision();
 
             // Create format
-            Format format = FormatFactory.getFormat(type, pattern, precision);
+            Format format = FormatFactory.getFormat(type, pattern, getLocale(), precision);
 
             // Get object to be formatted
             Object obj = model.get(field.getDeclaringClass().getName());

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
Wed Nov 24 04:53:00 2010
@@ -19,6 +19,7 @@ package org.apache.camel.dataformat.bind
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.Date;
+import java.util.Locale;
 
 import org.apache.camel.dataformat.bindy.format.BigDecimalFormat;
 import org.apache.camel.dataformat.bindy.format.BigIntegerFormat;
@@ -51,28 +52,29 @@ public final class FormatFactory {
      * 
      * @param clazz represents the type of the format (String, Integer, Byte)
      * @param pattern is the pattern to be used during the formating of the data
+     * @param locale optional locale for NumberFormat and DateFormat parsing.
      * @param precision optional scale for BigDecimal parsing.
      * @return Format the formatter
      * @throws IllegalArgumentException if not suitable formatter is found
      */
-    public static Format<?> getFormat(Class<?> clazz, String pattern, int precision)
throws Exception {
+    public static Format<?> getFormat(Class<?> clazz, String pattern, String
locale, int precision) throws Exception {
         if (clazz == byte.class || clazz == Byte.class) {
-            return pattern != null ? new BytePatternFormat(pattern) : new ByteFormat();
+            return pattern != null ? new BytePatternFormat(pattern, getLocale(locale)) :
new ByteFormat();
 
         } else if (clazz == short.class || clazz == Short.class) {
-            return pattern != null ? new ShortPatternFormat(pattern) : new ShortFormat();
+            return pattern != null ? new ShortPatternFormat(pattern, getLocale(locale)) :
new ShortFormat();
 
         } else if (clazz == int.class || clazz == Integer.class) {
-            return pattern != null ? new IntegerPatternFormat(pattern) : new IntegerFormat();
+            return pattern != null ? new IntegerPatternFormat(pattern, getLocale(locale))
: new IntegerFormat();
 
         } else if (clazz == long.class || clazz == Long.class) {
-            return pattern != null ? new LongPatternFormat(pattern) : new LongFormat();
+            return pattern != null ? new LongPatternFormat(pattern, getLocale(locale)) :
new LongFormat();
 
         } else if (clazz == float.class || clazz == Float.class) {
-            return pattern != null ? new FloatPatternFormat(pattern) : new FloatFormat();
+            return pattern != null ? new FloatPatternFormat(pattern, getLocale(locale)) :
new FloatFormat();
 
         } else if (clazz == double.class || clazz == Double.class) {
-            return pattern != null ? new DoublePatternFormat(pattern) : new DoubleFormat();
+            return pattern != null ? new DoublePatternFormat(pattern, getLocale(locale))
: new DoubleFormat();
 
         } else if (clazz == BigDecimal.class) {
             return new BigDecimalFormat(precision);
@@ -84,7 +86,7 @@ public final class FormatFactory {
             return new StringFormat();
 
         } else if (clazz == Date.class) {
-            return new DatePatternFormat(pattern);
+            return new DatePatternFormat(pattern, getLocale(locale));
 
         } else if (clazz == char.class || clazz == Character.class) {
             return new CharacterFormat();
@@ -94,4 +96,14 @@ public final class FormatFactory {
         }
     }
 
+    private static Locale getLocale(String locale) {
+        if (locale != null && !locale.isEmpty()) {
+            String[] result = locale.split("-");
+            if (result.length <= 2) {
+                return result.length == 1 ? new Locale(result[0]) : new Locale(result[0],
result[1]);
+            }
+        }
+        return null;
+    }
+
 }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
Wed Nov 24 04:53:00 2010
@@ -28,7 +28,10 @@ import java.util.Map;
 import java.util.Scanner;
 
 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.BindyKeyValuePairFactory;
 import org.apache.camel.dataformat.bindy.util.Converter;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.PackageScanClassResolver;
@@ -41,23 +44,20 @@ import org.apache.commons.logging.LogFac
  * A <a href="http://camel.apache.org/data-format.html">data format</a> (
  * {@link DataFormat}) using Bindy to marshal to and from CSV files
  */
-public class BindyCsvDataFormat implements DataFormat {
+public class BindyCsvDataFormat extends BindyAbstractDataFormat {
     private static final transient Log LOG = LogFactory.getLog(BindyCsvDataFormat.class);
 
-    private String[] packages;
-    private BindyCsvFactory modelFactory;
-
     public BindyCsvDataFormat() {
     }
 
     public BindyCsvDataFormat(String... packages) {
-        this.packages = packages;
+        super(packages);
     }
 
     @SuppressWarnings("unchecked")
     public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws
Exception {
 
-        BindyCsvFactory factory = getFactory(exchange.getContext().getPackageScanClassResolver());
+        BindyCsvFactory factory = (BindyCsvFactory)getFactory(exchange.getContext().getPackageScanClassResolver());
         ObjectHelper.notNull(factory, "not instantiated");
 
         // Get CRLF
@@ -104,7 +104,7 @@ public class BindyCsvDataFormat implemen
     }
 
     public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception
{
-        BindyCsvFactory factory = getFactory(exchange.getContext().getPackageScanClassResolver());
+        BindyCsvFactory factory = (BindyCsvFactory)getFactory(exchange.getContext().getPackageScanClassResolver());
         ObjectHelper.notNull(factory, "not instantiated");
 
         // List of Pojos
@@ -123,13 +123,10 @@ public class BindyCsvDataFormat implemen
         ObjectHelper.notNull(separator, "The separator has not been defined in the annotation
@CsvRecord or not instantiated during initModel.");
 
         int count = 0;
-
         try {
-
             // If the first line of the CSV file contains columns name, then we
             // skip this line
             if (factory.getSkipFirstLine()) {
-
                 // Check if scanner is empty
                 if (scanner.hasNextLine()) {
                     scanner.nextLine();
@@ -210,26 +207,7 @@ public class BindyCsvDataFormat implemen
 
     }
 
-    /**
-     * Method used to create the singleton of the BindyCsvFactory
-     */
-    public BindyCsvFactory getFactory(PackageScanClassResolver resolver) throws Exception
{
-        if (modelFactory == null) {
-            modelFactory = new BindyCsvFactory(resolver, packages);
-        }
-        return modelFactory;
-    }
-
-    public void setModelFactory(BindyCsvFactory modelFactory) {
-        this.modelFactory = modelFactory;
-    }
-
-    public String[] getPackages() {
-        return packages;
+    protected BindyAbstractFactory createModelFactory(PackageScanClassResolver resolver)
throws Exception {
+        return new BindyCsvFactory(resolver, getPackages());
     }
-
-    public void setPackages(String[] packages) {
-        this.packages = packages;
-    }
-
 }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BytePatternFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BytePatternFormat.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BytePatternFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/BytePatternFormat.java
Wed Nov 24 04:53:00 2010
@@ -16,14 +16,16 @@
  */
 package org.apache.camel.dataformat.bindy.format;
 
+import java.util.Locale;
+
 public class BytePatternFormat extends NumberPatternFormat<Byte> {
 
     public BytePatternFormat() {
         super();
     }
 
-    public BytePatternFormat(String pattern) {
-        super(pattern);
+    public BytePatternFormat(String pattern, Locale locale) {
+        super(pattern, locale);
     }
 
     @Override

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java
Wed Nov 24 04:53:00 2010
@@ -28,15 +28,15 @@ import org.apache.commons.logging.LogFac
 
 public class DatePatternFormat implements PatternFormat<Date> {
 
-    private static final transient Log LOG = LogFactory.getLog(DatePatternFormat.class);
-
     private String pattern;
+    private Locale locale = Locale.getDefault();
 
     public DatePatternFormat() {
     }
 
-    public DatePatternFormat(String pattern) {
+    public DatePatternFormat(String pattern, Locale locale) {
         this.pattern = pattern;
+        this.locale = locale != null ? locale : Locale.getDefault();
     }
 
     public String format(Date object) throws Exception {
@@ -71,7 +71,7 @@ public class DatePatternFormat implement
     }
 
     protected java.text.DateFormat getDateFormat() {
-        return new SimpleDateFormat(this.pattern, Locale.FRANCE);
+        return new SimpleDateFormat(this.pattern, locale);
     }
 
     public String getPattern() {
@@ -86,5 +86,4 @@ public class DatePatternFormat implement
     public void setPattern(String pattern) {
         this.pattern = pattern;
     }
-
 }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoublePatternFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoublePatternFormat.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoublePatternFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DoublePatternFormat.java
Wed Nov 24 04:53:00 2010
@@ -16,13 +16,15 @@
  */
 package org.apache.camel.dataformat.bindy.format;
 
+import java.util.Locale;
+
 public class DoublePatternFormat extends NumberPatternFormat<Double> {
 
     public DoublePatternFormat() {
     }
 
-    public DoublePatternFormat(String pattern) {
-        super(pattern);
+    public DoublePatternFormat(String pattern, Locale locale) {
+        super(pattern, locale);
     }
 
     @Override

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatPatternFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatPatternFormat.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatPatternFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/FloatPatternFormat.java
Wed Nov 24 04:53:00 2010
@@ -16,13 +16,15 @@
  */
 package org.apache.camel.dataformat.bindy.format;
 
+import java.util.Locale;
+
 public class FloatPatternFormat extends NumberPatternFormat<Float> {
 
     public FloatPatternFormat() {
     }
 
-    public FloatPatternFormat(String pattern) {
-        super(pattern);
+    public FloatPatternFormat(String pattern, Locale locale) {
+        super(pattern, locale);
     }
 
     @Override

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerPatternFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerPatternFormat.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerPatternFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/IntegerPatternFormat.java
Wed Nov 24 04:53:00 2010
@@ -17,14 +17,15 @@
 package org.apache.camel.dataformat.bindy.format;
 
 import java.text.NumberFormat;
+import java.util.Locale;
 
 public class IntegerPatternFormat extends NumberPatternFormat<Integer> {
 
     public IntegerPatternFormat() {
     }
 
-    public IntegerPatternFormat(String pattern) {
-        super(pattern);
+    public IntegerPatternFormat(String pattern, Locale locale) {
+        super(pattern, locale);
     }
 
     @Override

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongPatternFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongPatternFormat.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongPatternFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/LongPatternFormat.java
Wed Nov 24 04:53:00 2010
@@ -16,13 +16,15 @@
  */
 package org.apache.camel.dataformat.bindy.format;
 
+import java.util.Locale;
+
 public class LongPatternFormat extends NumberPatternFormat<Long> {
 
     public LongPatternFormat() {
     }
 
-    public LongPatternFormat(String pattern) {
-        super(pattern);
+    public LongPatternFormat(String pattern, Locale locale) {
+        super(pattern, locale);
     }
 
     @Override

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/NumberPatternFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/NumberPatternFormat.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/NumberPatternFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/NumberPatternFormat.java
Wed Nov 24 04:53:00 2010
@@ -18,6 +18,7 @@ package org.apache.camel.dataformat.bind
 
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
+import java.util.Locale;
 
 import org.apache.camel.dataformat.bindy.PatternFormat;
 import org.apache.camel.util.ObjectHelper;
@@ -25,13 +26,14 @@ import org.apache.camel.util.ObjectHelpe
 public abstract class NumberPatternFormat<T> implements PatternFormat<T> {
 
     private String pattern;
-    private DecimalFormat df;
+    private Locale locale = Locale.getDefault();
 
     public NumberPatternFormat() {
     }
 
-    public NumberPatternFormat(String pattern) {
+    public NumberPatternFormat(String pattern, Locale locale) {
         this.pattern = pattern;
+        this.locale = locale != null ? locale : Locale.getDefault();
     }
 
     public String format(T object) throws Exception {
@@ -46,7 +48,11 @@ public abstract class NumberPatternForma
     }
 
     protected NumberFormat getNumberFormat() {
-        return new DecimalFormat(pattern);
+        NumberFormat format = NumberFormat.getNumberInstance(locale);
+        if (format instanceof DecimalFormat) {
+            ((DecimalFormat)format).applyLocalizedPattern(pattern);
+        }
+        return format;
     }
 
     public String getPattern() {
@@ -56,5 +62,4 @@ public abstract class NumberPatternForma
     public void setPattern(String pattern) {
         this.pattern = pattern;
     }
-
 }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortPatternFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortPatternFormat.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortPatternFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/ShortPatternFormat.java
Wed Nov 24 04:53:00 2010
@@ -16,19 +16,20 @@
  */
 package org.apache.camel.dataformat.bindy.format;
 
+import java.util.Locale;
+
 public class ShortPatternFormat extends NumberPatternFormat<Short> {
 
     public ShortPatternFormat() {
         super();
     }
 
-    public ShortPatternFormat(String pattern) {
-        super(pattern);
+    public ShortPatternFormat(String pattern, Locale locale) {
+        super(pattern, locale);
     }
 
     @Override
     public Short parse(String string) throws Exception {
         return super.getNumberFormat().parse(string).shortValue();
     }
-
 }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java?rev=1038476&r1=1038475&r2=1038476&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
Wed Nov 24 04:53:00 2010
@@ -26,6 +26,8 @@ import java.util.Map;
 import java.util.Scanner;
 
 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.util.Converter;
 import org.apache.camel.spi.DataFormat;
@@ -39,23 +41,20 @@ import org.apache.commons.logging.LogFac
  * A <a href="http://camel.apache.org/data-format.html">data format</a> (
  * {@link DataFormat}) using Bindy to marshal to and from CSV files
  */
-public class BindyKeyValuePairDataFormat implements DataFormat {
+public class BindyKeyValuePairDataFormat extends BindyAbstractDataFormat {
 
     private static final transient Log LOG = LogFactory.getLog(BindyKeyValuePairDataFormat.class);
 
-    private String[] packages;
-    private BindyKeyValuePairFactory modelFactory;
-
     public BindyKeyValuePairDataFormat() {
     }
 
     public BindyKeyValuePairDataFormat(String... packages) {
-        this.packages = packages;
+        super(packages);
     }
 
     @SuppressWarnings("unchecked")
     public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws
Exception {
-        BindyKeyValuePairFactory factory = getFactory(exchange.getContext().getPackageScanClassResolver());
+        BindyAbstractFactory factory = getFactory(exchange.getContext().getPackageScanClassResolver());
         List<Map<String, Object>> models = (ArrayList<Map<String, Object>>)body;
         byte[] crlf;
 
@@ -73,7 +72,7 @@ public class BindyKeyValuePairDataFormat
     }
 
     public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception
{
-        BindyKeyValuePairFactory factory = getFactory(exchange.getContext().getPackageScanClassResolver());
+        BindyKeyValuePairFactory factory = (BindyKeyValuePairFactory)getFactory(exchange.getContext().getPackageScanClassResolver());
 
         // List of Pojos
         List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
@@ -92,9 +91,7 @@ public class BindyKeyValuePairDataFormat
 
         int count = 0;
         try {
-
             while (scanner.hasNextLine()) {
-
                 // Read the line
                 String line = scanner.nextLine().trim();
 
@@ -150,26 +147,7 @@ public class BindyKeyValuePairDataFormat
         }
     }
 
-    /**
-     * Method used to create the singleton of the BindyKeyValuePairFactory
-     */
-    public BindyKeyValuePairFactory getFactory(PackageScanClassResolver resolver) throws
Exception {
-        if (modelFactory == null) {
-            modelFactory = new BindyKeyValuePairFactory(resolver, this.packages);
-        }
-        return modelFactory;
-    }
-
-    public void setModelFactory(BindyKeyValuePairFactory modelFactory) {
-        this.modelFactory = modelFactory;
+    protected BindyAbstractFactory createModelFactory(PackageScanClassResolver resolver)
throws Exception {
+        return new BindyKeyValuePairFactory(resolver, getPackages());
     }
-
-    public String[] getPackages() {
-        return packages;
-    }
-
-    public void setPackages(String... packages) {
-        this.packages = packages;
-    }
-
 }



Mime
View raw message