camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmoulli...@apache.org
Subject svn commit: r956575 - in /camel/trunk/components/camel-bindy/src: main/java/org/apache/camel/dataformat/bindy/ main/java/org/apache/camel/dataformat/bindy/annotation/ test/java/org/apache/camel/dataformat/bindy/fixed/marshall/simple/ test/java/org/apac...
Date Mon, 21 Jun 2010 13:23:12 GMT
Author: cmoulliard
Date: Mon Jun 21 13:23:11 2010
New Revision: 956575

URL: http://svn.apache.org/viewvc?rev=956575&view=rev
Log:
CAMEL-2731 : add a padding char per field 

Modified:
    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/annotation/DataField.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/marshall/simple/BindySimpleFixedLengthMarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/BindySimpleFixedLengthUnmarshallTest.java

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=956575&r1=956574&r2=956575&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
Mon Jun 21 13:23:11 2010
@@ -334,9 +334,11 @@ public class BindyFixedLengthFactory ext
 
                     result = formatString(format, value);
                     
-                    // Get length of the field, alignment (LEFT or RIGHT)
+                    // Get length of the field, alignment (LEFT or RIGHT), pad
                     int fieldLength = datafield.length();
                     String align = datafield.align();
+                    char paddCharField = datafield.paddingChar();
+                    char paddChar;
                     
                     if (fieldLength > 0) {
                        
@@ -344,12 +346,21 @@ public class BindyFixedLengthFactory ext
 
                         // Check if we must padd
                         if (result.length() < fieldLength) {
+                        	
+                        	// No padding defined for the field
+                        	if ( paddCharField == 0 ) {
+                        		// We use the padding defined for the Record
+                        		paddChar = paddingChar;
+                        	} else {
+                        		paddChar = paddCharField;
+                        	}
+                        	
                             if (align.contains("R")) {
-                                temp.append(generatePaddingChars(paddingChar, fieldLength,
result.length()));
+                                temp.append(generatePaddingChars(paddChar, fieldLength, result.length()));
                                 temp.append(result);
                             } else if (align.contains("L")) {
                                 temp.append(result);
-                                temp.append(generatePaddingChars(paddingChar, fieldLength,
result.length()));
+                                temp.append(generatePaddingChars(paddChar, fieldLength, result.length()));
                             } else {
                                 throw new IllegalArgumentException("Alignement for the "
                                                                        + field.getName()

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java?rev=956575&r1=956574&r2=956575&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java
Mon Jun 21 13:23:11 2010
@@ -78,6 +78,14 @@ public @interface DataField {
      * @return String
      */
     String align() default "R";
+    
+    /**
+     * The char to pad with.
+     * @return the char to pad with if the record is set to a fixed length;
+     * 
+     * @return char
+     */
+    char paddingChar() default ' ';
 
     /**
      * precision of the BigDecimal number to be created

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/marshall/simple/BindySimpleFixedLengthMarshallTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/marshall/simple/BindySimpleFixedLengthMarshallTest.java?rev=956575&r1=956574&r2=956575&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/marshall/simple/BindySimpleFixedLengthMarshallTest.java
(original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/marshall/simple/BindySimpleFixedLengthMarshallTest.java
Mon Jun 21 13:23:11 2010
@@ -64,7 +64,7 @@ public class BindySimpleFixedLengthMarsh
     @DirtiesContext
     public void testMarshallMessage() throws Exception {
 
-        expected = "10A9  PaulineM    ISINXD12345678BUYShare2500.45USD01-08-2009\r\n";
+        expected = "10A9  PaulineM    ISINXD12345678BUYShare000002500.45USD01-08-2009\r\n";
         result.expectedBodiesReceived(expected);
 
         template.sendBody(generateModel());
@@ -118,7 +118,7 @@ public class BindySimpleFixedLengthMarsh
 
     }
 
-    @FixedLengthRecord(length = 60, paddingChar = ' ')
+    @FixedLengthRecord(length = 65, paddingChar = ' ')
     public static class Order {
 
         @DataField(pos = 1, length = 2)
@@ -145,15 +145,16 @@ public class BindySimpleFixedLengthMarsh
         @DataField(pos = 36, length = 5)
         private String instrumentType;
 
-        @DataField(pos = 41, precision = 2, length = 7)
+        @DataField(pos = 41, precision = 2, length = 12, paddingChar = '0')
         private BigDecimal amount;
 
-        @DataField(pos = 48, length = 3)
+        @DataField(pos = 53, length = 3)
         private String currency;
 
-        @DataField(pos = 51, length = 10, pattern = "dd-MM-yyyy")
+        @DataField(pos = 56, length = 10, pattern = "dd-MM-yyyy")
         private Date orderDate;
 
+
         public int getOrderNr() {
             return orderNr;
         }

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/BindySimpleFixedLengthUnmarshallTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/BindySimpleFixedLengthUnmarshallTest.java?rev=956575&r1=956574&r2=956575&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/BindySimpleFixedLengthUnmarshallTest.java
(original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/BindySimpleFixedLengthUnmarshallTest.java
Mon Jun 21 13:23:11 2010
@@ -63,7 +63,7 @@ public class BindySimpleFixedLengthUnmar
     @DirtiesContext
     public void testUnMarshallMessage() throws Exception {
 
-        expected = "10A9  PaulineM    ISINXD12345678BUYShare2500.45USD01-08-2009";
+        expected = "10A9  PaulineM    ISINXD12345678BUYShare000002500.45USD01-08-2009";
 
         template.sendBody(expected);
 
@@ -80,7 +80,7 @@ public class BindySimpleFixedLengthUnmar
 
     }
     
-    @FixedLengthRecord(length = 60, paddingChar = ' ')
+    @FixedLengthRecord(length = 65, paddingChar = ' ')
     public static class Order {
 
         @DataField(pos = 1, length = 2)
@@ -107,13 +107,13 @@ public class BindySimpleFixedLengthUnmar
         @DataField(pos = 36, length = 5)
         private String instrumentType;
 
-        @DataField(pos = 41, precision = 2, length = 7)
+        @DataField(pos = 41, precision = 2, length = 12, paddingChar = '0')
         private BigDecimal amount;
 
-        @DataField(pos = 48, length = 3)
+        @DataField(pos = 53, length = 3)
         private String currency;
 
-        @DataField(pos = 51, length = 10, pattern = "dd-MM-yyyy")
+        @DataField(pos = 56, length = 10, pattern = "dd-MM-yyyy")
         private Date orderDate;
 
         public int getOrderNr() {



Mime
View raw message