camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1345679 - in /camel/trunk/components/camel-bindy/src: main/java/org/apache/camel/dataformat/bindy/ main/java/org/apache/camel/dataformat/bindy/annotation/ main/java/org/apache/camel/dataformat/bindy/csv/ main/java/org/apache/camel/dataform...
Date Sun, 03 Jun 2012 14:25:10 GMT
Author: davsclaus
Date: Sun Jun  3 14:25:10 2012
New Revision: 1345679

URL: http://svn.apache.org/viewvc?rev=1345679&view=rev
Log:
CAMEL-5326: Bindy do not use default locale, unless explict configured.

Modified:
    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/FormatFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/Section.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/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java

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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -571,7 +571,7 @@ public class BindyCsvFactory extends Bin
     }
     /**
      * Set the default values for the non defined fields.
-     * @param The model which has its default fields set.
+     * @param model the model which has its default fields set.
      * @throws IllegalAccessException if the underlying fields are inaccessible
      * @throws Exception In case the field cannot be parsed
      */

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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -97,13 +97,14 @@ public final class FormatFactory {
     }
 
     private static Locale getLocale(String locale) {
+        Locale answer = null;
         if (locale != null && !(locale.length() == 0)) {
             String[] result = locale.split("-");
             if (result.length <= 2) {
-                return result.length == 1 ? new Locale(result[0]) : new Locale(result[0],
result[1]);
+                answer = result.length == 1 ? new Locale(result[0]) : new Locale(result[0],
result[1]);
             }
         }
-        return null;
+        return answer;
     }
 
 }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/Section.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/Section.java?rev=1345679&r1=1345678&r2=1345679&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/Section.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/Section.java
Sun Jun  3 14:25:10 2012
@@ -31,8 +31,6 @@ public @interface Section {
 
     /**
      * Number of the section
-     * 
-     * @return
      */
     int number();
 }

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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -76,22 +76,20 @@ public class BindyCsvDataFormat extends 
             outputStream.write(bytesCRLF);
         }
 
-        List<Map<String, Object>> models;
+        List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
 
-        // the body is not a prepared list so help a bit here and create one for us
-        if (exchange.getContext().getTypeConverter().convertTo(List.class, body) == null)
{
-            models = new ArrayList<Map<String, Object>>();
-            Iterator<Object> it = ObjectHelper.createIterator(body);
-            while (it.hasNext()) {
-                Object model = it.next();
+        // the body is not a prepared list of map that bindy expects so help a bit here and
create one for us
+        Iterator<Object> it = ObjectHelper.createIterator(body);
+        while (it.hasNext()) {
+            Object model = it.next();
+            if (model instanceof Map) {
+                models.add((Map<String, Object>) model);
+            } else {
                 String name = model.getClass().getName();
-                Map<String, Object> row = new HashMap<String, Object>();
-                row.put(name, body);
+                Map<String, Object> row = new HashMap<String, Object>(1);
+                row.put(name, model);
                 models.add(row);
             }
-        } else {
-            // cast to the expected type
-            models = (List<Map<String, Object>>) body;
         }
 
         for (Map<String, Object> model : models) {

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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -29,7 +29,11 @@ public class BytePatternFormat extends N
 
     @Override
     public Byte parse(String string) throws Exception {
-        return super.getNumberFormat().parse(string).byteValue();
+        if (getNumberFormat() != null) {
+            return getNumberFormat().parse(string).byteValue();
+        } else {
+            return Byte.valueOf(string);
+        }
     }
 
 }

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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -27,14 +27,14 @@ import org.apache.camel.util.ObjectHelpe
 public class DatePatternFormat implements PatternFormat<Date> {
 
     private String pattern;
-    private Locale locale = Locale.getDefault();
+    private Locale locale;
 
     public DatePatternFormat() {
     }
 
     public DatePatternFormat(String pattern, Locale locale) {
         this.pattern = pattern;
-        this.locale = locale != null ? locale : Locale.getDefault();
+        this.locale = locale;
     }
 
     public String format(Date object) throws Exception {
@@ -69,7 +69,11 @@ public class DatePatternFormat implement
     }
 
     protected java.text.DateFormat getDateFormat() {
-        return new SimpleDateFormat(this.pattern, locale);
+        if (locale != null) {
+            return new SimpleDateFormat(pattern, locale);
+        } else {
+            return new SimpleDateFormat(pattern);
+        }
     }
 
     public String getPattern() {

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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -29,7 +29,11 @@ public class DoublePatternFormat extends
 
     @Override
     public Double parse(String string) throws Exception {
-        return super.getNumberFormat().parse(string).doubleValue();
+        if (getNumberFormat() != null) {
+            return getNumberFormat().parse(string).doubleValue();
+        } else {
+            return Double.valueOf(string);
+        }
     }
 
 }

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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -29,7 +29,11 @@ public class FloatPatternFormat extends 
 
     @Override
     public Float parse(String string) throws Exception {
-        return super.getNumberFormat().parse(string).floatValue();
+        if (getNumberFormat() != null) {
+            return getNumberFormat().parse(string).floatValue();
+        } else {
+            return Float.valueOf(string);
+        }
     }
 
 }

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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -29,27 +29,12 @@ public class IntegerPatternFormat extend
     }
 
     @Override
-    public Integer parse(String string) throws FormatException {
-
-        Integer res = null;
-        NumberFormat pat;
-
-        // First we will test if the string can become an Integer
-        try {
-            res = Integer.parseInt(string);
-
-            // Second, we will parse the string using DecimalPattern
-            // to apply pattern
-
-            pat = super.getNumberFormat();
-            pat.parse(string).intValue();
-
-        } catch (Exception ex) {
-            throw new FormatException("String provided does not fit the Integer pattern defined
or is not parseable");
+    public Integer parse(String string) throws Exception {
+        if (getNumberFormat() != null) {
+            return getNumberFormat().parse(string).intValue();
+        } else {
+            return Integer.valueOf(string);
         }
-
-        return res;
-
     }
 
 }

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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -29,7 +29,11 @@ public class LongPatternFormat extends N
 
     @Override
     public Long parse(String string) throws Exception {
-        return super.getNumberFormat().parse(string).longValue();
+        if (getNumberFormat() != null) {
+            return getNumberFormat().parse(string).longValue();
+        } else {
+            return Long.valueOf(string);
+        }
     }
 
 }

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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -21,33 +21,40 @@ import java.text.NumberFormat;
 import java.util.Locale;
 
 import org.apache.camel.dataformat.bindy.PatternFormat;
-import org.apache.camel.util.ObjectHelper;
 
 public abstract class NumberPatternFormat<T> implements PatternFormat<T> {
 
     private String pattern;
-    private Locale locale = Locale.getDefault();
+    private Locale locale;
 
     public NumberPatternFormat() {
     }
 
     public NumberPatternFormat(String pattern, Locale locale) {
         this.pattern = pattern;
-        this.locale = locale != null ? locale : Locale.getDefault();
+        this.locale = locale;
     }
 
     public String format(T object) throws Exception {
-        ObjectHelper.notNull(this.pattern, "pattern");
-        return this.getNumberFormat().format(object);
+        if (getNumberFormat() != null) {
+            return this.getNumberFormat().format(object);
+        } else {
+            return object.toString();
+        }
     }
 
-    @SuppressWarnings("unchecked")
-    public T parse(String string) throws Exception {
-        ObjectHelper.notNull(this.pattern, "pattern");
-        return (T)this.getNumberFormat().parse(string);
-    }
+    public abstract T parse(String string) throws Exception;
 
+    /**
+     * Gets the number format if in use.
+     *
+     * @return the number format, or <tt>null</tt> if not in use
+     */
     protected NumberFormat getNumberFormat() {
+        if (locale == null) {
+            return null;
+        }
+
         NumberFormat format = NumberFormat.getNumberInstance(locale);
         if (format instanceof DecimalFormat) {
             ((DecimalFormat)format).applyLocalizedPattern(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=1345679&r1=1345678&r2=1345679&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
Sun Jun  3 14:25:10 2012
@@ -29,6 +29,10 @@ public class ShortPatternFormat extends 
 
     @Override
     public Short parse(String string) throws Exception {
-        return super.getNumberFormat().parse(string).shortValue();
+        if (getNumberFormat() != null) {
+            return getNumberFormat().parse(string).shortValue();
+        } else {
+            return Short.valueOf(string);
+        }
     }
 }

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java?rev=1345679&r1=1345678&r2=1345679&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java
(original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java
Sun Jun  3 14:25:10 2012
@@ -95,7 +95,7 @@ public class BindySimpleCsvUnmarshallBad
         // and check that we have the caused exception stored
         Exception cause = error.getReceivedExchanges().get(0).getProperty(Exchange.EXCEPTION_CAUGHT,
Exception.class);
         TestSupport.assertIsInstanceOf(Exception.class, cause.getCause());
-        assertEquals("String provided does not fit the Integer pattern defined or is not
parseable, position: 1, line: 1", cause.getMessage());
+        assertEquals("Parsing error detected for field defined at the position: 1, line:
1", cause.getMessage());
 
     }
 



Mime
View raw message