CAMEL-7159 - search for Link-ed fields and add them to the model automatically


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/47a3c264
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/47a3c264
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/47a3c264

Branch: refs/heads/camel-2.11.x
Commit: 47a3c264862650e0e554d22c6b783333bac9d502
Parents: deed273
Author: Jonathan Anstey <jans...@gmail.com>
Authored: Fri Jan 31 12:32:09 2014 -0330
Committer: Jonathan Anstey <jans...@gmail.com>
Committed: Fri Jan 31 12:36:50 2014 -0330

----------------------------------------------------------------------
 .../camel/dataformat/bindy/csv/BindyCsvDataFormat.java | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/47a3c264/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
----------------------------------------------------------------------
diff --git 
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
 
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
index 3ab3614..5e32a3c 100755
--- 
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
+++ 
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
@@ -19,6 +19,7 @@ package org.apache.camel.dataformat.bindy.csv;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -31,6 +32,8 @@ 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.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.Link;
 import org.apache.camel.dataformat.bindy.util.ConverterUtils;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.PackageScanClassResolver;
@@ -88,6 +91,16 @@ public class BindyCsvDataFormat extends 
BindyAbstractDataFormat {
                 String name = model.getClass().getName();
                 Map<String, Object> row = new HashMap<String, Object>(1);
                 row.put(name, model);
+                // search for @Link-ed fields and add them to the model
+                for (Field field : model.getClass().getDeclaredFields()) {
+                    Link linkField = field.getAnnotation(Link.class);
+                    if (linkField != null) {
+                        boolean accessible = field.isAccessible();
+                        field.setAccessible(true);
+                        row.put(field.getType().getName(), field.get(model));
+                        field.setAccessible(accessible);
+                    }
+                } 
                 models.add(row);
             }
         }

Reply via email to