Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9F759111D7 for ; Sun, 18 May 2014 05:25:31 +0000 (UTC) Received: (qmail 81302 invoked by uid 500); 18 May 2014 05:00:30 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 68883 invoked by uid 500); 18 May 2014 04:35:31 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 64769 invoked by uid 99); 18 May 2014 04:19:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 May 2014 04:19:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 May 2014 04:19:45 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 208AD2388ADA for ; Sun, 18 May 2014 04:19:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r909130 [4/6] - in /websites/production/camel/content: ./ cache/ Date: Sun, 18 May 2014 04:19:19 -0000 To: commits@camel.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140518041920.208AD2388ADA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: websites/production/camel/content/book-dataformat-appendix.html ============================================================================== --- websites/production/camel/content/book-dataformat-appendix.html (original) +++ websites/production/camel/content/book-dataformat-appendix.html Sun May 18 04:19:18 2014 @@ -1197,213 +1197,82 @@ from("file://site/inbox").unma </dependency> ]]> -

Bindy

- -

The goal of this component is to allow the parsing/binding of non-structured data (or to be more precise non-XML data)
-to/from Java Beans that have binding mappings defined with annotations. Using Bindy, you can bind data from sources such as :

-
  • CSV records,
  • Fixed-length records,
  • FIX messages,
  • or almost any other non-structured data
- - -

to one or many Plain Old Java Object (POJO). Bindy converts the data according to the type of the java property. POJOs can be linked together with one-to-many relationships available in some cases. Moreover, for data type like Date, Double, Float, Integer, Short, Long and BigDecimal, you can provide the pattern to apply during the formatting of the property.

- -

For the BigDecimal numbers, you can also define the precision and the decimal or grouping separators.

- -

Type

Format Type

Pattern example

Link

Date

DateFormat

"dd-MM-yyyy"

http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html

Decimal*

Decimalformat

"##.###.###"

http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html

- -

Decimal* = Double, Integer, Float, Short, Long

-
+

Bindy

The goal of this component is to allow the parsing/binding of non-structured data (or to be more precise non-XML data)
to/from Java Beans that have binding mappings defined with annotations. Using Bindy, you can bind data from sources such as :

  • CSV records,
  • Fixed-length records,
  • FIX messages,
  • or almost any other non-structured data

to one or many Plain Old Java Object (POJO). Bindy converts the data according to the type of the java property. POJOs can be linked together with one-to-many relationships available in some cases. Moreover, for data type like Date, Double, Float, Integer, Short, Long and BigDecimal, you can provide the pattern to apply during the formatting of the property.

For the BigDecimal numbers, you can also define the precision and the decimal or grouping separators.

Type

Format Type

Pattern example

Link

Date

DateFormat

"dd-MM-yyyy"

http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html

Decimal*

Decimalformat

"##.###.###"

http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html

Decimal* = Double, Integer, Float, Short, Long

Format supported

Icon

This first release only support comma separated values fields and key value pair fields (e.g. : FIX messages).

- -

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, ...) add the required annotations (described hereafter) to the Class or field.

-
+

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, ...) add the required annotations (described hereafter) to the Class or field.

Multiple models

Icon

If you use multiple models, each model has to be placed in it's own package to prevent unpredictable results.

- - -

Annotations

- -

The annotations created allow to map different concept of your model to the POJO like :

- -
  • Type of record (csv, key value pair (e.g. FIX message), fixed length ...),
  • Link (to link object in another object),
  • DataField and their properties (int, type, ...),
  • KeyValuePairField (for key = value format like we have in FIX financial messages),
  • Section (to identify header, body and footer section),
  • OneToMany
- - -

This section will describe them :

- -

1. 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

csv

Class

- - -

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 - possible values = WINDOWS,UNIX,MAC, or custom; default value = WINDOWS - allow to define the carriage return character to use. If you specify a value other than the three listed before, the value you enter (custom) will be used as the CRLF character(s)

generateHeaderColumns

boolean

o ptional - default value = false - uses to generate the header columns of the CSV generates

autospanLine

boolean

Camel 2.13/2.12.2: optional - default value = false - if enabled then the last column is auto spanned to end of line, for example if its a comment, etc this allows the line to contain all characters, also the delimiter char.

isOrdered

boolean

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.

- - -

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

- -
- -
- -

case 2 : separator = ';'

- -

Compare to the previous case, the separator here is ';' instead of ',' :

- -

10; J; Pauline; M; XD12345678; Fortis Dynamic 15/15; 2500; USD; 08-01-2009

- -
- -
- -

case 3 : separator = '|'

- -

Compare to the previous case, the separator here is '|' instead of ';' :

- -

10| J| Pauline| M| XD12345678| Fortis Dynamic 15/15| 2500| USD| 08-01-2009

- -
- -
- -

case 4 : separator = '\",\"'
-Applies for Camel 2.8.2 or older

- -

When the field to be parsed of the CSV record contains ',' or ';' which is also used as separator, we whould find another strategy
-to tell camel bindy how to handle this case. To define the field containing the data with a comma, you will use simple or double quotes
-as delimiter (e.g : '10', 'Street 10, NY', 'USA' or "10", "Street 10, NY", "USA").
-Remark : In this case, the first and last character of the line which are a simple or double quotes will removed by bindy

- -

"10","J","Pauline"," M","XD12345678","Fortis Dynamic 15,15" 2500","USD","08-01-2009"

- -
- -
- -

From Camel 2.8.3/2.9 or never bindy will automatic detect if the record is enclosed with either single or double quotes and automatic remove those quotes when unmarshalling from CSV to Object. Therefore do not include the quotes in the separator, but simple do as below:

- -

"10","J","Pauline"," M","XD12345678","Fortis Dynamic 15,15" 2500","USD","08-01-2009"

- -
- -
- -

Notice that if you want to marshal from Object to CSV and use quotes, then you need to specify which quote character to use, using the quote attribute on the @CsvRecord as shown below:

- -
- -
- - -

case 5 : separator & skipfirstline

- -

The feature is interesting when the client wants to have in the first line of the file, the name of the data fields :

- -

order id, client id, first name, last name, isin code, instrument name, quantity, currency, date

- -

To inform bindy that this first line must be skipped during the parsing process, then we use the attribute :

- -
- -
- -

case 6 : generateHeaderColumns

- -

To add at the first line of the CSV generated, the attribute generateHeaderColumns must be set to true in the annotation like this :

- -
- -
- -

As a result, Bindy during the unmarshaling process will generate CSV like this :

- -

order id, client id, first name, last name, isin code, instrument name, quantity, currency, date
-10, J, Pauline, M, XD12345678, Fortis Dynamic 15/15, 2500, USD,08-01-2009

- -

case 7 : carriage return

- -

If the platform where camel-bindy will run is not Windows but Macintosh or Unix, than you can change the crlf property like this. Three values are available : WINDOWS, UNIX or MAC

- -
- -
- -

Additionally, if for some reason you need to add a different line ending character, you can opt to specify it using the crlf parameter. In the following example, we can end the line with a comma followed by the newline character:

- -
- -
- -

case 8 : isOrdered

- -

Sometimes, the order to follow during the creation of the CSV record from the model is different from the order used during the parsing. Then, in this case, we can use the attribute isOrdered = true to indicate this in combination with attribute 'position' of the DataField annotation.

- -
- -
- -

Remark : pos is used to parse the file, stream while positions is used to generate the CSV

- - - - -

The link annotation will allow to link objects together.

- -

Annotation name

Record type

Level

Link

all

Class & Property

- - -

Parameter name

type

Info

linkType

LinkType

optional - by default the value is LinkType.oneToOne - so you are not obliged to mention it

 

 

Only one-to-one relation is allowed.

- - -

e.g : If the model Class Client is linked to the Order class, then use annotation Link in the Order class like this :

- -
Property Link
- -
- -

AND for the class Client :

- -
Class Link
- -
- - -

3. DataField

- -

The DataField annotation defines the property of the field. Each datafield is identified by its position in the record, a type (string, int, date, ...) and optionally of a pattern

- -

Annotation name

Record type

Level

DataField

all

Property

- - -

Parameter name

type

Info

pos

int

mandatory - digit number starting from 1 to ...

pattern

string

optional - default value = "" - will be used to format Decimal, Date, ...

length

int

optional - represents the length of the field for fixed length format

precision

int

optional - represents the precision to be used when the Decimal number will be formatted/parsed

pattern

string

optional - default value = "" - is used by the Java Formater (SimpleDateFormat by example) to format/validate data

position

int

optional - must be used when the position of the field in the CSV generated m ust be different compare to pos

required

boolean

optional - default value = "false"

trim

boolean

optional - default value = "false"

defaultValue

string

optional - default value = "" - defines the field's default value when the respective CSV field is empty/not available

impliedDecimalSeparator

boolean

Camel 2.11: optional - default value = "false" - Indicates if there is a decimal point implied at a specified location

lengthPos

int

Camel 2.11: optional - can be used to identify a data field in a fixed-length record that defines the fixed length for this field

delimiter

string

Camel 2.11: optional - can be used to demarcate the end of a variable-length field within a fixed-length record

- - -

case 1 : pos

- -

This parameter/attribute represents the position of the field in the csv record

- -
Position
- -
- -

As you can see in this example the position starts at '1' but continues at '5' in the class Order. The numbers from '2' to '4' are defined in the class Client (see here after).

- -
Position continues in another model class
- -
- -

case 2 : pattern

- -

The pattern allows to enrich or validates the format of your data

- -
Pattern
- -
- -

case 3 : precision

- -

The precision is helpful when you want to define the decimal part of your number

- -
Precision
- -
- -

case 4 : Position is different in output

- -

The position attribute will inform bindy how to place the field in the CSV record generated. By default, the position used corresponds to the position defined with the attribute 'pos'. If the position is different (that means that we have an asymetric processus comparing marshaling from unmarshaling) than we can use 'position' to indicate this.

- -

Here is an example

- -
Position is different in output
- -
- -
+
Icon
- -

This attribute of the annotation @DataField must be used in combination with attribute isOrdered = true of the annotation @CsvRecord

+

This attribute of the annotation @DataField must be used in combination with attribute isOrdered = true of the annotation @CsvRecord

- - - -

case 5 : required

- -

If a field is mandatory, simply use the attribute 'required' setted to true

- -
Required
- -
- -

If this field is not present in the record, than an error will be raised by the parser with the following information :

- -

Some fields are missing (optional or mandatory), line :

- - -

case 6 : trim

- -

If a field has leading and/or trailing spaces which should be removed before they are processed, simply use the attribute 'trim' setted to true

- -
Trim
- -
- -

case 7 : defaultValue

- -

If a field is not defined then uses the value indicated by the defaultValue attribute

- -
Default value
- -
-
+
Icon
- -

This attribute is only applicable to optional fields.

+

This attribute is only applicable to optional fields.

- - - - -

4. FixedLengthRecord

- -

The FixedLengthRecord annotation is used to identified the root class of the model. It represents a record = a line of a file/message containing data fixed length formatted and can be linked to several children model classes. This format is a bit particular beause data of a field can be aligned to the right or to the left.
-When the size of the data does not fill completely the length of the field, we can then add 'padd' characters.

- -

Annotation name

Record type

Level

FixedLengthRecord

fixed

Class

- - -

Parameter name

type

Info

crlf

string

optional - possible values = WINDOWS,UNIX,MAC, or custom; default value = WINDOWS - allow to define the carriage return character to use. If you specify a value other than the three listed before, the value you enter (custom) will be used as the CRLF character(s)

paddingChar

char

mandatory - default value = ' '

length

int

mandatory = size of the fixed length record

hasHeader

boolean

Camel 2.11 - optional - Indicates that the record(s) of this type may be preceded by a single header record at the beginning of the file / stream

hasFooter

boolean

Camel 2.11 - optional - Indicates that the record(s) of this type may be followed by a single footer record at the end of the file / stream

skipHeader

boolean

Camel 2.11 - optional - Configures the data format to skip marshalling / unmarshalling of the header record. Configure this parameter on the primary record (e.g., not the header or footer).

skipFooter

boolean

Camel 2.11 - optional - Configures the data format to skip marshalling / unmarshalling of the footer record Configure this parameter on the primary record (e.g., not the header or footer)..

isHeader

boolean

Camel 2.11 - optional - Identifies this FixedLengthRecord as a header record

isFooter

boolean

Camel 2.11 - optional - Identifies this FixedLengthRecords as a footer record

ignoreTrailingChars

boolean

Camel 2.11.1 - optional - Indicates that characters beyond the last mapped filed can be ignored when unmarshalling / parsing.

 

 

This annotation is associated to the root class of the model and must be declared one time.

- - -
+

4. FixedLengthRecord

The FixedLengthRecord annotation is used to identified the root class of the model. It represents a record = a line of a file/message containing data fixed length formatted and can be linked to several children model classes. This format is a bit particular beause data of a field can be aligned to the right or to the left.
When the size of the data does not fill completely the length of the field, we can then add 'padd' characters.

Annotation name

Record type

Level

FixedLengthRecord

fixed

Class

Parameter name

type

Info

crlf

string

optional - possible values = WINDOWS,UNIX,MAC, or custom; default value = WINDOWS - allow to define the carriage return character to use. If you specify a value other than the three listed before, the value you enter (custom) will be used as the CRLF character(s)

paddingChar

char

mandatory - default value = ' '

length

int

mandatory = size of the fixed length record

hasHeader

boolean

Camel 2.11 - optional - Indicates that the record(s) of this type may be preceded by a single header record at the beginning of the file / stream

hasFooter

boolean

Camel 2.11 - optional - Indicates that the record(s) of this type may be followed by a single footer record at the end of the file / stream

skipHeader

boolean

Camel 2.11 - optional - Configures the data format to skip marshalling / unmarshalling of the header record. Configure this parameter on the primary record (e.g., not the header or footer).

skipFooter

boolean

Camel 2.11 - optional - Configures the data format to skip marshalling / unmarshalling of the footer record Configure this parameter on the primary record (e.g., not the header or footer)..

isHeader

boolean

Camel 2.11 - optional - Identifies this FixedLengthRecord as a header record

isFooter

boolean

Camel 2.11 - optional - Identifies this FixedLengthRecords as a footer record

ignoreTrailingChars

boolean

Camel 2.11.1 - optional - Indicates that characters beyond the last mapped filed can be ignored when unmarshalling / parsing.

 

 

This annotation is associated to the root class of the model and must be declared one time.

Icon
- -

The hasHeader/hasFooter parameters are mutually exclusive with isHeader/isFooter. A record may not be both a header/footer and a primary fixed-length record.

+

The hasHeader/hasFooter parameters are mutually exclusive with isHeader/isFooter. A record may not be both a header/footer and a primary fixed-length record.

- - -

case 1 : Simple fixed length record

- -

This simple example shows how to design the model to parse/format a fixed message

- -

10A9PaulineMISINXD12345678BUYShare2500.45USD01-08-2009

- -
Fixed-simple
- -
- -

case 2 : Fixed length record with alignment and padding

- -

This more elaborated example show how to define the alignment for a field and how to assign a padding character which is ' ' here''

- -

10A9 PaulineM ISINXD12345678BUYShare2500.45USD01-08-2009

- -
Fixed-padding-align
- -
- -

case 3 : Field padding

- -

Sometimes, the default padding defined for record cannnot be applied to the field as we have a number format where we would like to padd with '0' instead of ' '. In this case, you can use in the model the attribute paddingField to set this value.

- -

10A9 PaulineM ISINXD12345678BUYShare000002500.45USD01-08-2009

- -
Fixed-padding-field
- -
- -

case 4: Fixed length record with delimiter

- -

Fixed-length records sometimes have delimited content within the record. The firstName and lastName fields are delimited with the '^' character in the following example:

- -

10A9Pauline^M^ISINXD12345678BUYShare000002500.45USD01-08-2009

- -
Fixed-delimited
- -
- -
+
Icon
- -

As of Camel 2.11 the 'pos' value(s) in a fixed-length record may optionally be defined using ordinal, sequential values instead of precise column numbers.

+

As of Camel 2.11 the 'pos' value(s) in a fixed-length record may optionally be defined using ordinal, sequential values instead of precise column numbers.

- - -

case 5 : Fixed length record with record-defined field length

- -

Occasionally a fixed-length record may contain a field that define the expected length of another field within the same record. In the following example the length of the instrumentNumber field value is defined by the value of instrumentNumberLen field in the record.

- -

10A9Pauline^M^ISIN10XD12345678BUYShare000002500.45USD01-08-2009

- -
Fixed-delimited
- -
- - -

case 6 : Fixed length record with header and footer

- -

Bindy will discover fixed-length header and footer records that are configured as part of the model – provided that the annotated classes exist either in the same package as the primary @FixedLengthRecord class, or within one of the configured scan packages. The following text illustrates two fixed-length records that are bracketed by a header record and footer record.

- -

101-08-2009
-10A9 PaulineM ISINXD12345678BUYShare000002500.45USD01-08-2009
-10A9 RichN ISINXD12345678BUYShare000002700.45USD01-08-2009
-9000000002

- -
Fixed-header-and-footer-main-class
- -
- -

case 7 : Skipping content when parsing a fixed length record. (Camel 2.11.1)

- -

It is common to integrate with systems that provide fixed-length records containing more information than needed for the target use case. It is useful in this situation to skip the declaration and parsing of those fields that we do not need. To accomodate this, Bindy will skip forward to the next mapped field within a record if the 'pos' value of the next declared field is beyond the cursor position of the last parsed field. Using absolute 'pos' locations for the fields of interest (instead of ordinal values) causes Bindy to skip content between two fields.

- -

Similarly, it is possible that none of the content beyond some field is of interest. In this case, you can tell Bindy to skip parsing of everything beyond the last mapped field by setting the ignoreTrailingChars property on the @FixedLengthRecord declaration.

- -
- -
- - -

5. 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)

- -
+

5. 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)

"FIX information"

Icon

More information about FIX can be found on this web site : http://www.fixprotocol.org/. To work with FIX messages, the model must contain a Header and Trailer classes linked to the root message class which could be a Order class. This is not mandatory but will be very helpful when you will use camel-bindy in combination with camel-fix which is a Fix gateway based on quickFix project http://www.quickfixj.org/.

- - - -

Annotation name

Record type

Level

Message

key value pair

Class

- - -

Parameter name

type

Info

pairSeparator

string

mandatory - can be '=' or ';' or 'anything'

keyValuePairSeparair

string

mandatory - can be '\u0001', '\u0009', '#' or 'anything'

crlf

string

optional - possible values = WINDOWS,UNIX,MAC, or custom; default value = WINDOWS - allow to define the carriage return character to use. If you specify a value other than the three listed before, the value you enter (custom) will be used as the CRLF character(s)

type

string

optional - define the type of message (e.g. FIX, EMX, ...)

version

string

optional - version of the message (e.g. 4.1)

isOrdered

boolean

optional - default value = false - allow to change the order of the fields when FIX message is generated

 

 

This annotation is associated to the message class of the model and must be declared one time.

- - -

case 1 : separator = 'u0001'

- -

The separator used to segregate the key value pair fields in a FIX message is the ASCII '01' character or in unicode format '\u0001'. This character must be escaped a second time to avoid a java runtime error. Here is an example :

- -

8=FIX.4.1 9=20 34=1 35=0 49=INVMGR 56=BRKR 1=BE.CHM.001 11=CHM0001-01 22=4 ...

- -

and how to use the annotation

- -
FIX - message
- -
- -
+

Look at test cases

Icon [... 377 lines stripped ...]