Bindy has been edited by Charles Moulliard (Feb 05, 2009). Content:BindyAvailable as of Camel 2.0 The idea that the developers have followed to design this component was to allow the binding of non structured data (or to be more precise non-XML data)
to one or many POJOS and to convert the data according to the type of the java property. POJOS can be linked together. Moreover, for data type like Date, Double, Float, For the BigDecimal number, you can also define the precision and the decimal or grouping separators
Decimal* = Double, Integer, Float, Short, Long
To work with camel-bindy, you must first define your model in a package (e.g. com.acme.model) and for each model class (e.g. Order, Client, Instrument, ...) associate
Using the Java DSLThe next step consists in creating the DataFormat bindy class associated with the record type and providing Java package name(s) as parameter to instantiate the class. For example the following uses the named CsvBindyFormat class (correspond to the class associated with the type CSV record) which is configured with "com.acme.model" package name to initialize the model objects configured in this package. 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. List<Map<String, Object>> models = new ArrayList<HashMap<String, Object>>; Map<String, Object> model = new HashMap<String, Object>; ... To generate CSV records from a collection of model objects, you create the following route : from("") 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. from("file://inbox"). unmarshal("myBindyDataFormat"). to("bean:handleOrder"); Using Spring XMLTODO: DependenciesTo use Bindy in your camel routes you need to add the a dependency on camel-bindy which implements this data format. If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions). <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-bindy</artifactId> <version>2.0.0</version> </dependency> |
Unsubscribe or edit your notifications preferences