...
- CSV record,
- Fixedlength record,
- FIX messages,
- or any other non-structured data
...
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 the required annotations (described hereafter) with Class or property name.
Annotations
The annotations created allow to map different concept of your model to the POJOs like :
- Kind of record (csv, fixed length, ..),
- Link,
- Data field and their properties (int, type, ...)
This section will describe them :
CsvRecord
The CsvRecord annotation is used to identified the root class of the model. It represents a record = a line of a CSV file and can be linked to several children model classes.
Note | ||
---|---|---|
| ||
To work with FIX messages, the model must contain : Header and Trailer classes linked to the root class which could be a Order class. This is not mandatory but will be helful when you will use camel-bindy in combination with camel-fix which is a Fix gateway based on quickFix project [http://www.quickfixj.org. |
Annotations
The annotations created allow to map different concept of your model to the POJOs like :
- Type of record/message (csv, fixed length, key value pair (e.g. FIX message) ...),
- Link,
- Data field and their properties (int, type, ...)
- Key value Pair field
This section will describe them :
CsvRecord
The CsvRecord annotation is used to identified the root class of the model. It represents a record = a line of a CSV file and can be linked to several children model classes.
Annotation name | Record type | Level |
---|---|---|
CsvRecord | ||
Annotation name | Record type | Level |
CsvRecord | csv | Class |
Parameter name | type | Info |
---|---|---|
separator | string | mandatory - can be ',' or ';' or 'anything' |
skipFirstLine | boolean | optional - default value = false - allow to skip the first line of the CSV file |
|
| This annotation is associated to the root class of the model and must be declared one time. |
...
Code Block | ||
---|---|---|
| ||
@CsvRecord(separator = ",") public class Order { @DataField(pos = 0) private int orderNr; @Link private Client client; @DataField(pos = 4) private String isinCode; @DataField(name = "Name", pos = 5) private String instrumentName; @DataField(pos = 6, precision = 2) -- precision private BigDecimal amount; @DataField(pos = 7) private String currency; @DataField(pos = 8, pattern = "dd-MM-yyyy") private Date orderDate;pos = 7) private String currency; @DataField(pos = 8, pattern = "dd-MM-yyyy") private Date orderDate; ... } |
Message
The Message annotation is used to identified the class of your model who will contain key value pairs fields. This kind of format is used mainly in Financial Exchange Protocol Messages (FIX). Nevertheless, this annotation can be used for any other format where data are identified by keys. The key pair values are separated each other by a separator which can be a special character like a tab delimitor (unicode representation : \u0009) or a start of heading (unicode representation : \u0001)
Note | ||
---|---|---|
| ||
More information about FIX can be found on this web site : http://www.fixprotocol.org/ |
Annotation name | Record type | Level |
---|---|---|
Message | key value pair | Class |
Parameter name | type | Info |
---|---|---|
pair separator | string | mandatory - can be '=' or ';' or 'anything' |
key value pair separair | string | mandatory - can be ' |
type | string | optional - define the type of message (e.g. FIX, EMX, ...) |
version | string | optional - version of the message (e.g. 4.1) |
|
| This annotation is associated to the message class of the model and must be declared one time. |
case 1 : separator = ','
The separator used to segregate the fields in the CSV record is ',' :
10, J, Pauline, M, XD12345678, Fortis Dynamic 15/15, 2500, USD,08-01-2009
Code Block | ||
---|---|---|
| ||
@CsvRecord( separator = "," )
public Class Order {
...
}
|
Using the Java DSL
The next step consists in instantiaing the DataFormat bindy class associated with this record type and providing Java package name(s) as parameter.
...