Author: buildbot Date: Thu May 3 18:20:57 2012 New Revision: 815621 Log: Production update by buildbot for camel Modified: websites/production/camel/content/bindy.html websites/production/camel/content/book-dataformat-appendix.html websites/production/camel/content/book-in-one-page.html websites/production/camel/content/cache/main.pageCache Modified: websites/production/camel/content/bindy.html ============================================================================== --- websites/production/camel/content/bindy.html (original) +++ websites/production/camel/content/bindy.html Thu May 3 18:20:57 2012 @@ -116,7 +116,7 @@ to Java Bean using annotations. Using Bi
Parameter name | type | Info |
---|---|---|
separator | string | mandatory - can be ',' or ';' or 'anything'. This value is interpreted as a regular expression. If you want to use a sign which has a special meaning in regular expressions, e.g. the '|' sign, than you have to mask it, like ' -|' |
skipFirstLine | boolean | optional - default value = false - allow to skip the first line of the CSV file |
crlf | string | optional - default value = WINDOWS - allow to define the carriage return character to use |
generateHeaderColumns | boolean | optional - default value = false - uses to generate the header columns of the CSV generates |
isOrdered | boolean < /td> | optional - default value = false - allow to change the order of the fields when CSV is generated |
quote | String | Camel 2.8.3/2.9: option - allow to specify a quote character of the fields when CSV is generated |
This annotation is associated to the root class of the model and must be declared one time. |
DataFormat bindy = new CsvBindyDataFormat("com.acme.model"); - -from("file://inbox"). - unmarshal(bindy). - to("bean:handleOrder");
The Camel route will pick-up files in the inbox directory, unmarshall CSV records in a collection of model objects and send the collection
-to the bean referenced by 'handleOrder'.
The collection is a list of Map. Each Map of the list contains the objects of the model. Each object can be retrieve using its class name.
+-int count = 0; - - List<Map<String, Object>> models = new ArrayList<Map<String, Object>>(); - Map<String, Object> model = new HashMap<String, Object>(); +from("file://inbox") + .unmarshal(bindy) + .to("direct:handleOrders"); ++
Alternatively, you can use a named reference to a data format which can then be defined in your Registry e.g. your Spring XML file:
++from("file://inbox") + .unmarshal("myBindyDataFormat") + .to("direct:handleOrders"); ++
The Camel route will pick-up files in the inbox directory, unmarshall CSV records into a collection of model objects and send the collection
+to the route referenced by 'handleOrders'.
The collection returned is a List of Map objects. Each Map within the list contains the model objects that were marshalled out of each line of the CSV. The reason behind this is that each line can correspond to more than one object. This can be confusing when you simply expect one object to be returned per line.
- model = it.next(); +Each object can be retrieve using its class name.
++ List<Map<String, Object>> unmarshaledModels = (List<Map<String, Object>>) exchange.getIn().getBody(); - for(String key : model.keySet()) { - Object obj = model.get(key); - LOG.info("Count : " + count + ", " + obj.toString()); + int modelCount = 0; + for (Map<String, Object> model : unmarshaledModels) { + for (String className : model.keySet()) { + Object obj = model.get(className); + LOG.info("Count : " + modelCount + ", " + obj.toString()); } - - count++; + modelCount++; } - LOG.info("Nber of CSV records received by the csv bean : " + count); + LOG.info("Total CSV records received by the csv bean : " + modelCount);
To generate CSV records from a collection of model objects, you create the following route :
+ +Assuming that you want to extract a single Order object from this map for processing in a route, you could use a combination of a Splitter and a Processor as per the following:
-from("bean:handleOrder") - marshal(bindy) - to("file://outbox") +from("file://inbox") + .unmarshal(bindy) + .split(body()) + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + Message in = exchange.getIn(); + Map<String, Object> modelMap = (Map<String, Object>) in.getBody(); + in.setBody(modelMap.get(Order.class.getCanonicalName())); + } + }) + .to("direct:handleSingleOrder") + .end();
You can if you prefer use a named reference to a data format which can then be defined in your Registry such as via your Spring XML file. e.g.
+ +To generate CSV records from a collection of model objects, you create the following route :
-from("file://inbox"). - unmarshal("myBindyDataFormat"). - to("bean:handleOrder"); +from("direct:handleOrders") + .marshal(bindy) + .to("file://outbox")
Parameter name | type | Info |
---|---|---|
separator | string | mandatory - can be ',' or ';' or 'anything'. This value is interpreted as a regular expression. If you want to use a sign which has a special meaning in regular expressions, e.g. the '|' sign, than you have to mask it, like ' -|' |
skipFirstLine | boolean | optional - default value = false - allow to skip the first line of the CSV file |
crlf | string | optional - default value = WINDOWS - allow to define the carriage return character to use |
generateHeaderColumns | boolean | optional - default value = false - uses to generate the header columns of the CSV generates |
isOrdered | boolean < /td> | optional - default value = false - allow to change the order of the fields when CSV is generated |
quote | String | Camel 2.8.3/2.9: option - allow to specify a quote character of the fields when CSV is generated |
This annotation is associated to the root class of the model and must be declared one time. |
DataFormat bindy = new CsvBindyDataFormat("com.acme.model"); - -from("file://inbox"). - unmarshal(bindy). - to("bean:handleOrder");
The Camel route will pick-up files in the inbox directory, unmarshall CSV records in a collection of model objects and send the collection
-to the bean referenced by 'handleOrder'.
The collection is a list of Map. Each Map of the list contains the objects of the model. Each object can be retrieve using its class name.
+-int count = 0; - - List<Map<String, Object>> models = new ArrayList<Map<String, Object>>(); - Map<String, Object> model = new HashMap<String, Object>(); +from("file://inbox") + .unmarshal(bindy) + .to("direct:handleOrders"); ++
Alternatively, you can use a named reference to a data format which can then be defined in your Registry e.g. your Spring XML file:
++from("file://inbox") + .unmarshal("myBindyDataFormat") + .to("direct:handleOrders"); ++
The Camel route will pick-up files in the inbox directory, unmarshall CSV records into a collection of model objects and send the collection
+to the route referenced by 'handleOrders'.
The collection returned is a List of Map objects. Each Map within the list contains the model objects that were marshalled out of each line of the CSV. The reason behind this is that each line can correspond to more than one object. This can be confusing when you simply expect one object to be returned per line.
- model = it.next(); +Each object can be retrieve using its class name.
++ List<Map<String, Object>> unmarshaledModels = (List<Map<String, Object>>) exchange.getIn().getBody(); - for(String key : model.keySet()) { - Object obj = model.get(key); - LOG.info("Count : " + count + ", " + obj.toString()); + int modelCount = 0; + for (Map<String, Object> model : unmarshaledModels) { + for (String className : model.keySet()) { + Object obj = model.get(className); + LOG.info("Count : " + modelCount + ", " + obj.toString()); } - - count++; + modelCount++; } - LOG.info("Nber of CSV records received by the csv bean : " + count); + LOG.info("Total CSV records received by the csv bean : " + modelCount);
To generate CSV records from a collection of model objects, you create the following route :
+ +Assuming that you want to extract a single Order object from this map for processing in a route, you could use a combination of a Splitter and a Processor as per the following:
-from("bean:handleOrder") - marshal(bindy) - to("file://outbox") +from("file://inbox") + .unmarshal(bindy) + .split(body()) + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + Message in = exchange.getIn(); + Map<String, Object> modelMap = (Map<String, Object>) in.getBody(); + in.setBody(modelMap.get(Order.class.getCanonicalName())); + } + }) + .to("direct:handleSingleOrder") + .end();
You can if you prefer use a named reference to a data format which can then be defined in your Registry such as via your Spring XML file. e.g.
+ +To generate CSV records from a collection of model objects, you create the following route :
-from("file://inbox"). - unmarshal("myBindyDataFormat"). - to("bean:handleOrder"); +from("direct:handleOrders") + .marshal(bindy) + .to("file://outbox")
Parameter name | type | Info |
---|---|---|
separator | string | mandatory - can be ',' or ';' or 'anything'. This value is interpreted as a regular expression. If you want to use a sign which has a special meaning in regular expressions, e.g. the '|' sign, than you have to mask it, like ' -|' |
skipFirstLine | boolean | optional - default value = false - allow to skip the first line of the CSV file |
crlf | string | optional - default value = WINDOWS - allow to define the carriage return character to use |
generateHeaderColumns | boolean | optional - default value = false - uses to generate the header columns of the CSV generates |
isOrdered | boolean < /td> | optional - default value = false - allow to change the order of the fields when CSV is generated |
quote | String | Camel 2.8.3/2.9: option - allow to specify a quote character of the fields when CSV is generated |
This annotation is associated to the root class of the model and must be declared one time. |
DataFormat bindy = new CsvBindyDataFormat("com.acme.model"); - -from("file://inbox"). - unmarshal(bindy). - to("bean:handleOrder");
The Camel route will pick-up files in the inbox directory, unmarshall CSV records in a collection of model objects and send the collection
-to the bean referenced by 'handleOrder'.
The collection is a list of Map. Each Map of the list contains the objects of the model. Each object can be retrieve using its class name.
+-int count = 0; - - List<Map<String, Object>> models = new ArrayList<Map<String, Object>>(); - Map<String, Object> model = new HashMap<String, Object>(); +from("file://inbox") + .unmarshal(bindy) + .to("direct:handleOrders"); ++
Alternatively, you can use a named reference to a data format which can then be defined in your Registry e.g. your Spring XML file:
++from("file://inbox") + .unmarshal("myBindyDataFormat") + .to("direct:handleOrders"); ++
The Camel route will pick-up files in the inbox directory, unmarshall CSV records into a collection of model objects and send the collection
+to the route referenced by 'handleOrders'.
The collection returned is a List of Map objects. Each Map within the list contains the model objects that were marshalled out of each line of the CSV. The reason behind this is that each line can correspond to more than one object. This can be confusing when you simply expect one object to be returned per line.
- model = it.next(); +Each object can be retrieve using its class name.
++ List<Map<String, Object>> unmarshaledModels = (List<Map<String, Object>>) exchange.getIn().getBody(); - for(String key : model.keySet()) { - Object obj = model.get(key); - LOG.info("Count : " + count + ", " + obj.toString()); + int modelCount = 0; + for (Map<String, Object> model : unmarshaledModels) { + for (String className : model.keySet()) { + Object obj = model.get(className); + LOG.info("Count : " + modelCount + ", " + obj.toString()); } - - count++; + modelCount++; } - LOG.info("Nber of CSV records received by the csv bean : " + count); + LOG.info("Total CSV records received by the csv bean : " + modelCount);
To generate CSV records from a collection of model objects, you create the following route :
+ +Assuming that you want to extract a single Order object from this map for processing in a route, you could use a combination of a Splitter and a Processor as per the following:
-from("bean:handleOrder") - marshal(bindy) - to("file://outbox") +from("file://inbox") + .unmarshal(bindy) + .split(body()) + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + Message in = exchange.getIn(); + Map<String, Object> modelMap = (Map<String, Object>) in.getBody(); + in.setBody(modelMap.get(Order.class.getCanonicalName())); + } + }) + .to("direct:handleSingleOrder") + .end();
You can if you prefer use a named reference to a data format which can then be defined in your Registry such as via your Spring XML file. e.g.
+ +To generate CSV records from a collection of model objects, you create the following route :
-from("file://inbox"). - unmarshal("myBindyDataFormat"). - to("bean:handleOrder"); +from("direct:handleOrders") + .marshal(bindy) + .to("file://outbox")