camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r824993 - in /camel/trunk/components/camel-bindy/src: main/java/org/apache/camel/dataformat/bindy/ main/java/org/apache/camel/dataformat/bindy/csv/ main/java/org/apache/camel/dataformat/bindy/format/ test/java/org/apache/camel/dataformat/bi...
Date Wed, 14 Oct 2009 01:05:27 GMT
Author: ningjiang
Date: Wed Oct 14 01:05:26 2009
New Revision: 824993

URL: http://svn.apache.org/viewvc?rev=824993&view=rev
Log:
Fixed the CS errors of camel-bindy

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/csv/BindyCsvDataFormat.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/NumberPatternFormat.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvGenerateHeaderMarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvGenerateHeaderMarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/generateheader/Order.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassmath/Math.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=824993&r1=824992&r2=824993&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 Oct 14 01:05:26 2009
@@ -260,7 +260,7 @@
             Object modelField = model.get(field.getDeclaringClass().getName());
 
             if (modelField != null) {
-           	
+           
                 // Get field value
                 Object value = field.get(modelField);
                 String strValue = "";
@@ -344,39 +344,39 @@
             }
         }
         
-       	return builder.toString();
+        return builder.toString();
 
     }
     
     public String generateHeader() {
-    	
+
         Map<Integer, DataField> dataFieldsSorted = new TreeMap<Integer, DataField>(dataFields);
-		Iterator<Integer> it = dataFieldsSorted.keySet().iterator();
+        Iterator<Integer> it = dataFieldsSorted.keySet().iterator();
+
+        StringBuilder builderHeader = new StringBuilder();
 
-		StringBuilder builderHeader = new StringBuilder();
+        while (it.hasNext()) {
 
-		while (it.hasNext()) {
+            DataField dataField = dataFieldsSorted.get(it.next());
 
-			DataField dataField = dataFieldsSorted.get(it.next());
+            // Retrieve the field
+            Field field = annotedFields.get(dataField.pos());
+            // Change accessibility to allow to read protected/private fields
+            field.setAccessible(true);
 
-			// Retrieve the field
-			Field field = annotedFields.get(dataField.pos());
-			// Change accessibility to allow to read protected/private fields
-			field.setAccessible(true);
+            // Get dataField
+            if (!dataField.columnName().equals("")) {
+                builderHeader.append(dataField.columnName());
+            } else {
+                builderHeader.append(field.getName());
+            }
 
-			// Get dataField
-			if ( ! dataField.columnName().equals("") ) {
-				builderHeader.append(dataField.columnName());
-			} else {
-				builderHeader.append(field.getName());
-			}
+            if (it.hasNext()) {
+                builderHeader.append(separator);
+            }
 
-			if (it.hasNext()) {
-				builderHeader.append(separator);
-			}
+        }
 
-		} 
-        
         return builderHeader.toString();
     }
 
@@ -388,7 +388,7 @@
     private void initCsvRecordParameters() {
         if (separator == null) {
             for (Class<?> cl : models) {
-            	
+            
                 // Get annotation @CsvRecord from the class
                 CsvRecord record = cl.getAnnotation(CsvRecord.class);
 

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=824993&r1=824992&r2=824993&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 Oct 14 01:05:26 2009
@@ -53,36 +53,35 @@
 
     @SuppressWarnings("unchecked")
     public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws
Exception {
-    
+
         BindyCsvFactory factory = getFactory(exchange.getContext().getPackageScanClassResolver());
         ObjectHelper.notNull(factory, "not instantiated");
-        
-        List<Map<String, Object>> models = (ArrayList<Map<String, Object>>)
body;
+
+        List<Map<String, Object>> models = (ArrayList<Map<String, Object>>)body;
         byte[] bytesCRLF;
-    
-     
+
         // Get CRLF
         bytesCRLF = Converter.getByteReturn(factory.getCarriageReturn());
-        
-        if ( factory.getGenerateHeaderColumnNames() ) {
-        	
-        	String result = factory.generateHeader();
-        	byte[] bytes = exchange.getContext().getTypeConverter().convertTo(byte[].class,
exchange, result);
-            outputStream.write( bytes );
-            
+
+        if (factory.getGenerateHeaderColumnNames()) {
+
+            String result = factory.generateHeader();
+            byte[] bytes = exchange.getContext().getTypeConverter().convertTo(byte[].class,
exchange, result);
+            outputStream.write(bytes);
+
             // Add a carriage return
-            outputStream.write( bytesCRLF );
+            outputStream.write(bytesCRLF);
         }
-        
+
         // We iterate over the list of CSV record
         for (Map<String, Object> model : models) {
-        	
-        	String result = factory.unbind(model);
-        	byte[] bytes = exchange.getContext().getTypeConverter().convertTo(byte[].class,
exchange, result);
-            outputStream.write( bytes );
-            
+
+            String result = factory.unbind(model);
+            byte[] bytes = exchange.getContext().getTypeConverter().convertTo(byte[].class,
exchange, result);
+            outputStream.write(bytes);
+
             // Add a carriage return
-            outputStream.write( bytesCRLF );
+            outputStream.write(bytesCRLF);
         }
     }
 

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=824993&r1=824992&r2=824993&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 Oct 14 01:05:26 2009
@@ -30,26 +30,27 @@
 
     @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");
-    	}
-    	
-    	return res;
-    	
+
+        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");
+        }
+
+        return res;
+
     }
 
 }

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=824993&r1=824992&r2=824993&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 Oct 14 01:05:26 2009
@@ -48,7 +48,7 @@
     }
 
     protected NumberFormat getNumberFormat() {
-    	return new DecimalFormat(pattern);
+        return new DecimalFormat(pattern);
     }
 
     public String getPattern() {

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvGenerateHeaderMarshallTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvGenerateHeaderMarshallTest.java?rev=824993&r1=824992&r2=824993&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvGenerateHeaderMarshallTest.java
(original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvGenerateHeaderMarshallTest.java
Wed Oct 14 01:05:26 2009
@@ -44,8 +44,8 @@
 public class BindyComplexCsvGenerateHeaderMarshallTest extends AbstractJUnit4SpringContextTests
{
 
     private List<Map<String, Object>> models = new ArrayList<Map<String,
Object>>();
-    private String result = "Order Nr,Client Nr,First Name,Last Name,Instrument Code,Instrument
Nr,Order Type,Instrument Type,amount,currency,Order Date\r\n" + 
-    	"10,A1,Julia,Roberts,ISIN,LU123456789,BUY,Share,150,USD,14-01-2009\r\n";
+    private String result = "Order Nr,Client Nr,First Name,Last Name,Instrument Code,Instrument
Nr,Order Type,Instrument Type,amount,currency,Order Date\r\n"
+        + "10,A1,Julia,Roberts,ISIN,LU123456789,BUY,Share,150,USD,14-01-2009\r\n";
 
     @Produce(uri = "direct:start")
     private ProducerTemplate template;

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvGenerateHeaderMarshallTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvGenerateHeaderMarshallTest.java?rev=824993&r1=824992&r2=824993&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvGenerateHeaderMarshallTest.java
(original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvGenerateHeaderMarshallTest.java
Wed Oct 14 01:05:26 2009
@@ -42,8 +42,8 @@
 public class BindySimpleCsvGenerateHeaderMarshallTest extends AbstractJUnit4SpringContextTests
{
 
     private List<Map<String, Object>> models = new ArrayList<Map<String,
Object>>();
-    private String result = "Order Nr,Client Nr,First Name,Last Name,Instrument Code,Instrument
Nr,Order Type,Instrument Type,amount,currency,Order Date\r\n" +
-    		"1,B2,Keira,Knightley,ISIN,XX23456789,BUY,Share,400.25,EUR,14-01-2009\r\n";
+    private String result = "Order Nr,Client Nr,First Name,Last Name,Instrument Code,Instrument
Nr,Order Type,Instrument Type,amount,currency,Order Date\r\n"
+        + "1,B2,Keira,Knightley,ISIN,XX23456789,BUY,Share,400.25,EUR,14-01-2009\r\n";
 
     @Produce(uri = "direct:start")
     private ProducerTemplate template;

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=824993&r1=824992&r2=824993&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
Wed Oct 14 01:05:26 2009
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.dataformat.bindy.csv;
 
-import static org.junit.Assert.assertEquals;
-
 import java.util.List;
 import java.util.Map;
 
@@ -42,98 +40,108 @@
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 
+import static org.junit.Assert.assertEquals;
+
 @ContextConfiguration(locations = "org.apache.camel.dataformat.bindy.csv.BindySimpleCsvUnmarshallBadIntegerTest$ContextConfig",
loader = JavaConfigContextLoader.class)
 public class BindySimpleCsvUnmarshallBadIntegerTest extends AbstractJUnit4SpringContextTests
{
 
     private static final transient Log LOG = LogFactory.getLog(BindySimpleCsvUnmarshallBadIntegerTest.class);
 
-    private static final String uriMockResult = "mock:result";
-    private static final String uriMockError = "mock:error";  
-    private static final String uriDirectStart = "direct:start";
-    private String record;
+    private static final String URI_MOCK_RESULT = "mock:result";
+    private static final String URI_MOCK_ERROR = "mock:error";
+    private static final String URI_DIRECT_START = "direct:start";
     
-    @EndpointInject(uri = uriMockResult)
-    private MockEndpoint result;
+    @Produce(uri = URI_DIRECT_START)
+    protected ProducerTemplate template;
     
-    @EndpointInject(uri = uriMockError)
+    private String record;
+
+    @EndpointInject(uri = URI_MOCK_RESULT)
+    private MockEndpoint result;
+
+    @EndpointInject(uri = URI_MOCK_ERROR)
     private MockEndpoint error;
 
-    @Produce(uri = uriDirectStart)
-    protected ProducerTemplate template;
     
+
     @SuppressWarnings("unchecked")
-	@Test
+    @Test
     @DirtiesContext
     public void testIntegerMessage() throws Exception {
-    	
-    	record = "10000,25.10";
-    	
-   		template.sendBody(record);
-    	
+
+        record = "10000,25.10";
+
+        template.sendBody(record);
+
         result.expectedMessageCount(1);
         result.assertIsSatisfied();
-        
-        List<Map<String, org.apache.camel.dataformat.bindy.model.simple.oneclassmath.Math>>
model = (List<Map<String, org.apache.camel.dataformat.bindy.model.simple.oneclassmath.Math>>)
result.getExchanges().get(0).getIn().getBody();
- 
-        LOG.info(">>> Model generated : " + model.get(0).get("org.apache.camel.dataformat.bindy.model.simple.oneclassmath.Math").toString());
+
+        List<Map<String, org.apache.camel.dataformat.bindy.model.simple.oneclassmath.Math>>
model = (List<Map<String, org.apache.camel.dataformat.bindy.model.simple.oneclassmath.Math>>)result
+            .getExchanges().get(0).getIn().getBody();
+
+        LOG.info(">>> Model generated : "
+                 + model.get(0).get("org.apache.camel.dataformat.bindy.model.simple.oneclassmath.Math")
+                     .toString());
 
     }
-    
+
     @Test
     @DirtiesContext
     public void testIntegerTooBigError() throws Exception {
-    	record = "1000000000000000000000000000000000000,25.10";
-    	
+        record = "1000000000000000000000000000000000000,25.10";
+
         template.sendBody(record);
-    	
-    	// We don't expect to have a message as an error will be raised
-    	result.expectedMessageCount(0);
-    	
-    	// Message has been delivered to the mock error
+
+        // We don't expect to have a message as an error will be raised
+        result.expectedMessageCount(0);
+
+        // Message has been delivered to the mock error
         error.expectedMessageCount(1);
-        
-    	result.assertIsSatisfied();
-    	error.assertIsSatisfied();
-    	
+
+        result.assertIsSatisfied();
+        error.assertIsSatisfied();
+
         // and check that we have the caused exception stored
-        Exception cause = error.getReceivedExchanges().get(0).getProperty(Exchange.EXCEPTION_CAUGHT,
Exception.class);
+        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(
+                     "String provided does not fit the Integer pattern defined or is not
parseable, position : 1, line : 1",
+                     cause.getMessage());
+
     }
 
     @Configuration
     public static class ContextConfig extends SingleRouteCamelConfiguration {
-    	
-        BindyCsvDataFormat orderBindyDataFormat = new BindyCsvDataFormat("org.apache.camel.dataformat.bindy.model.simple.oneclassmath");
+
+        BindyCsvDataFormat orderBindyDataFormat = new BindyCsvDataFormat(
+                                                                         "org.apache.camel.dataformat.bindy.model.simple.oneclassmath");
 
         @Override
         @Bean
         public RouteBuilder route() {
             return new RouteBuilder() {
-            	
+
                 @Override
                 public void configure() {
-            	
-                Tracer tracer = new Tracer();
-                tracer.setLogLevel(LoggingLevel.FATAL);
-                tracer.setLogName("org.apache.camel.bindy");
-                tracer.setLogStackTrace(true);
-                tracer.setTraceExceptions(true);
-
-                getContext().addInterceptStrategy(tracer);
-            	
-                // default should errors go to mock:error
-                errorHandler(deadLetterChannel(uriMockError).redeliverDelay(0));
-                
-                onException(Exception.class).maximumRedeliveries(0).handled(true);
 
-                from(uriDirectStart).unmarshal(orderBindyDataFormat).to(uriMockResult);
-                
+                    Tracer tracer = new Tracer();
+                    tracer.setLogLevel(LoggingLevel.FATAL);
+                    tracer.setLogName("org.apache.camel.bindy");
+                    tracer.setLogStackTrace(true);
+                    tracer.setTraceExceptions(true);
+
+                    getContext().addInterceptStrategy(tracer);
+
+                    // default should errors go to mock:error
+                    errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliverDelay(0));
+
+                    onException(Exception.class).maximumRedeliveries(0).handled(true);
+
+                    from(URI_DIRECT_START).unmarshal(orderBindyDataFormat).to(URI_MOCK_RESULT);
+
                 }
             };
         }
     }
 }
-
-    
\ No newline at end of file

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/generateheader/Order.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/generateheader/Order.java?rev=824993&r1=824992&r2=824993&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/generateheader/Order.java
(original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/generateheader/Order.java
Wed Oct 14 01:05:26 2009
@@ -22,12 +22,10 @@
 import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
 import org.apache.camel.dataformat.bindy.annotation.DataField;
 import org.apache.camel.dataformat.bindy.annotation.Link;
-import org.apache.camel.dataformat.bindy.model.complex.generateheader.Client;
-import org.apache.camel.dataformat.bindy.model.complex.generateheader.Security;
 
 @CsvRecord(separator = ",", generateHeaderColumns = true)
 public class Order {
-	
+
     @DataField(pos = 1, columnName = "Order Nr")
     private int orderNr;
     

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassmath/Math.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassmath/Math.java?rev=824993&r1=824992&r2=824993&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassmath/Math.java
(original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassmath/Math.java
Wed Oct 14 01:05:26 2009
@@ -25,31 +25,30 @@
 @CsvRecord(separator = ",")
 public class Math {
 
-	@DataField(pos = 1, pattern = "00")
+    @DataField(pos = 1, pattern = "00")
     private Integer intAmount;
-    
+
     @DataField(pos = 2, precision = 2, pattern = "00.00")
     private BigDecimal bigDecimal;
-    
+
     public Integer getIntAmount() {
-		return intAmount;
-	}
+        return intAmount;
+    }
+
+    public void setIntAmount(Integer intAmount) {
+        this.intAmount = intAmount;
+    }
+
+    public BigDecimal getBigDecimal() {
+        return bigDecimal;
+    }
+
+    public void setBigDecimal(BigDecimal bigDecimal) {
+        this.bigDecimal = bigDecimal;
+    }
 
-	public void setIntAmount(Integer intAmount) {
-		this.intAmount = intAmount;
-	}
-
-	public BigDecimal getBigDecimal() {
-		return bigDecimal;
-	}
-
-	public void setBigDecimal(BigDecimal bigDecimal) {
-		this.bigDecimal = bigDecimal;
-	}
-	
-	@Override
-	public String toString() {
-	        return "intAmount : " + this.intAmount + ", " +
-	               "bigDecimal : " + this.bigDecimal;
-	}
+    @Override
+    public String toString() {
+        return "intAmount : " + this.intAmount + ", " + "bigDecimal : " + this.bigDecimal;
+    }
 }



Mime
View raw message