camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmoulli...@apache.org
Subject svn commit: r790157 [1/3] - in /camel/trunk/components/camel-bindy/src: main/java/org/apache/camel/dataformat/bindy/ test/data/ test/data/big/ test/data2/ test/java/org/apache/camel/dataformat/bindy/csv/ test/java/org/apache/camel/dataformat/bindy/mode...
Date Wed, 01 Jul 2009 13:27:04 GMT
Author: cmoulliard
Date: Wed Jul  1 13:27:04 2009
New Revision: 790157

URL: http://svn.apache.org/viewvc?rev=790157&view=rev
Log:
Change type of the field annotedLinkFields from Map<String, Object> into a Map<String,
List<Field>>, adapt test cases and made some clean-up in list, map names.

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/BindyKeyValuePairFactory.java
    camel/trunk/components/camel-bindy/src/test/data/big/csv.txt
    camel/trunk/components/camel-bindy/src/test/data/csv.txt
    camel/trunk/components/camel-bindy/src/test/data2/csv.txt
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvMarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/twoclassesandonelink/Client.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/twoclassesandonelink/Order.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclass/Order.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassandskipfirstline/Order.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/util/AnnotationModuleLoaderTest.java

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=790157&r1=790156&r2=790157&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 Jul  1 13:27:04 2009
@@ -18,6 +18,7 @@
 
 import java.lang.reflect.Field;
 import java.text.NumberFormat;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -37,7 +38,8 @@
 public abstract class BindyAbstractFactory implements BindyFactory {
     private static final transient Log LOG = LogFactory.getLog(BindyAbstractFactory.class);
     protected Set<Class> models;
-    protected Map<String, Field> mapAnnotatedLinkField = new LinkedHashMap<String,
Field>();
+    protected Map<String, List<Field>> annotedLinkFields = new LinkedHashMap<String,
List<Field>>();
+    protected List<Field> linkFields = new ArrayList<Field>();
     protected String crlf;
 
     private AnnotationModelLoader modelsLoader;
@@ -83,19 +85,28 @@
     public abstract String unbind(Map<String, Object> model) throws Exception;
 
     /**
-     * Link objects together (Only 1to1 relation is allowed)
+     * Link objects together
      */
     public void link(Map<String, Object> model) throws Exception {
-        for (String link : mapAnnotatedLinkField.keySet()) {
-            Field field = mapAnnotatedLinkField.get(link);
-            field.setAccessible(true);
-
-            // Retrieve linked object
-            String toClassName = field.getType().getName();
-            Object to = model.get(toClassName);
-
-            ObjectHelper.notNull(to, "No @link annotation has been defined for the oject
to link");
-            field.set(model.get(field.getDeclaringClass().getName()), to);
+    	
+    	// Iterate class by class
+    	for (String link : annotedLinkFields.keySet()) {
+            List<Field> linkFields = annotedLinkFields.get(link);
+            
+            // Iterate through Link fields list
+            for (Field field : linkFields) {
+            	
+            	// Change protection for private field
+                field.setAccessible(true);
+
+                // Retrieve linked object
+                String toClassName = field.getType().getName();
+                Object to = model.get(toClassName);
+
+                ObjectHelper.notNull(to, "No @link annotation has been defined for the oject
to link");
+                field.set(model.get(field.getDeclaringClass().getName()), to);
+            	
+            }
         }
     }
 

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=790157&r1=790156&r2=790157&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 Jul  1 13:27:04 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.dataformat.bindy;
 
 import java.lang.reflect.Field;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -44,8 +45,8 @@
 
     private static final transient Log LOG = LogFactory.getLog(BindyCsvFactory.class);
 
-    private Map<Integer, DataField> mapDataField = new LinkedHashMap<Integer, DataField>();
-    private Map<Integer, Field> mapAnnotedField = new LinkedHashMap<Integer, Field>();
+    private Map<Integer, DataField> dataFields = new LinkedHashMap<Integer, DataField>();
+    private Map<Integer, Field> annotedFields = new LinkedHashMap<Integer, Field>();
     private Map<String, Integer> sections = new HashMap<String, Integer>();
 
     private String separator;
@@ -80,6 +81,8 @@
     public void initAnnotedFields() {
 
         for (Class<?> cl : models) {
+        	
+        	List<Field> linkFields = new ArrayList<Field>();
 
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Class retrieved : " + cl.getName());
@@ -92,8 +95,8 @@
                         LOG.debug("Position defined in the class : " + cl.getName() + ",
position : " + dataField.pos()
                                 + ", Field : " + dataField.toString());
                     }
-                    mapDataField.put(dataField.pos(), dataField);
-                    mapAnnotedField.put(dataField.pos(), field);
+                    dataFields.put(dataField.pos(), dataField);
+                    annotedFields.put(dataField.pos(), field);
                 }
 
                 Link linkField = field.getAnnotation(Link.class);
@@ -102,8 +105,14 @@
                     if (LOG.isDebugEnabled()) {
                         LOG.debug("Class linked  : " + cl.getName() + ", Field" + field.toString());
                     }
-                    mapAnnotatedLinkField.put(cl.getName(), field);
+                    linkFields.add( field );
                 }
+
+            }
+            
+            
+            if (! linkFields.isEmpty() ) {
+            	annotedLinkFields.put(cl.getName(), linkFields);
             }
         }
     }
@@ -120,9 +129,9 @@
 
             if (!data.get(pos).equals("")) {
 
-                DataField dataField = mapDataField.get(pos);
+                DataField dataField = dataFields.get(pos);
                 ObjectHelper.notNull(dataField, "No position defined for the field positoned
: " + pos);
-                Field field = mapAnnotedField.get(pos);
+                Field field = annotedFields.get(pos);
                 field.setAccessible(true);
 
                 if (LOG.isDebugEnabled()) {
@@ -143,8 +152,8 @@
 
         StringBuilder builder = new StringBuilder();
 
-        Map<Integer, DataField> dataFields = new TreeMap<Integer, DataField>(mapDataField);
-        Iterator<Integer> it = dataFields.keySet().iterator();
+        Map<Integer, DataField> dataFieldsSorted = new TreeMap<Integer, DataField>(dataFields);
+        Iterator<Integer> it = dataFieldsSorted.keySet().iterator();
         
         // Map containing the OUT position of the field
         // The key is double and is created using the position of the field and 
@@ -163,10 +172,10 @@
 
         while (it.hasNext()) {
 
-            DataField dataField = mapDataField.get(it.next());
+            DataField dataField = dataFieldsSorted.get(it.next());
 
             // Retrieve the field
-            Field field = mapAnnotedField.get(dataField.pos());
+            Field field = annotedFields.get(dataField.pos());
             // Change accessibility to allow to read protected/private fields
             field.setAccessible(true);
 

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=790157&r1=790156&r2=790157&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 Jul  1 13:27:04 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.dataformat.bindy;
 
 import java.lang.reflect.Field;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -45,8 +46,8 @@
 
     private static final transient Log LOG = LogFactory.getLog(BindyKeyValuePairFactory.class);
 
-    private Map<Integer, KeyValuePairField> mapKeyValuePairField = new LinkedHashMap<Integer,
KeyValuePairField>();
-    private Map<Integer, Field> mapAnnotedField = new LinkedHashMap<Integer, Field>();
+    private Map<Integer, KeyValuePairField> keyValuePairFields = new LinkedHashMap<Integer,
KeyValuePairField>();
+    private Map<Integer, Field> annotedFields = new LinkedHashMap<Integer, Field>();
     private Map<String, Integer> sections = new HashMap<String, Integer>();
 
     private String keyValuePairSeparator;
@@ -82,6 +83,8 @@
     public void initAnnotedFields() {
 
         for (Class<?> cl : models) {
+        	
+        	List<Field> linkFields = new ArrayList<Field>();
 
             for (Field field : cl.getDeclaredFields()) {
                 KeyValuePairField keyValuePairField = field.getAnnotation(KeyValuePairField.class);
@@ -90,8 +93,8 @@
                         LOG.debug("Key declared in the class : " + cl.getName() + ", key
: " + keyValuePairField.tag()
                                 + ", Field : " + keyValuePairField.toString());
                     }
-                    mapKeyValuePairField.put(keyValuePairField.tag(), keyValuePairField);
-                    mapAnnotedField.put(keyValuePairField.tag(), field);
+                    keyValuePairFields.put(keyValuePairField.tag(), keyValuePairField);
+                    annotedFields.put(keyValuePairField.tag(), field);
                 }
 
                 Link linkField = field.getAnnotation(Link.class);
@@ -100,9 +103,13 @@
                     if (LOG.isDebugEnabled()) {
                         LOG.debug("Class linked  : " + cl.getName() + ", Field" + field.toString());
                     }
-                    mapAnnotatedLinkField.put(cl.getName(), field);
+                    linkFields.add( field );
                 }
             }
+            
+            if (! linkFields.isEmpty() ) {
+            	annotedLinkFields.put(cl.getName(), linkFields);
+            }
 
         }
     }
@@ -132,10 +139,10 @@
                     LOG.debug("Key : " + tag + ", value : " + value);
                 }
 
-                KeyValuePairField keyValuePairField = mapKeyValuePairField.get(tag);
+                KeyValuePairField keyValuePairField = keyValuePairFields.get(tag);
                 ObjectHelper.notNull(keyValuePairField, "No tag defined for the field : "
+ tag);
 
-                Field field = mapAnnotedField.get(tag);
+                Field field = annotedFields.get(tag);
                 field.setAccessible(true);
 
                 if (LOG.isDebugEnabled()) {
@@ -159,8 +166,8 @@
 
         StringBuilder builder = new StringBuilder();
 
-        Map<Integer, KeyValuePairField> keyValuePairFields = new TreeMap<Integer,
KeyValuePairField>(mapKeyValuePairField);
-        Iterator<Integer> it = keyValuePairFields.keySet().iterator();
+        Map<Integer, KeyValuePairField> keyValuePairFieldsSorted = new TreeMap<Integer,
KeyValuePairField>(keyValuePairFields);
+        Iterator<Integer> it = keyValuePairFieldsSorted.keySet().iterator();
         
         // Map containing the OUT position of the field
         // The key is double and is created using the position of the field and 
@@ -180,11 +187,11 @@
 
         while (it.hasNext()) {
 
-            KeyValuePairField keyValuePairField = mapKeyValuePairField.get(it.next());
+            KeyValuePairField keyValuePairField = keyValuePairFieldsSorted.get(it.next());
             ObjectHelper.notNull(keyValuePairField, "KeyValuePair is null !");
 
             // Retrieve the field
-            Field field = mapAnnotedField.get(keyValuePairField.tag());
+            Field field = annotedFields.get(keyValuePairField.tag());
             // Change accessibility to allow to read protected/private fields
             field.setAccessible(true);
 



Mime
View raw message