You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by rodrickmusser <ro...@columbiaultimate.com> on 2013/07/11 20:59:03 UTC

Using Bindy for multiple record types in the same file

I am wondering if Bindy can be used in the following scenario:

The file format I am working with is fixed length.  The first two characters
indicate the record type.  For example, "01" indicates an order record, "02"
indicates a customer record.  If the record is an order record, characters
2-11 are the order id.  If the record is a customer record, characters 2-20
is the customer name.

How does Bindy handle this situation?



--
View this message in context: http://camel.465427.n5.nabble.com/Using-Bindy-for-multiple-record-types-in-the-same-file-tp5735541.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Bindy for multiple record types in the same file

Posted by rodrickmusser <ro...@columbiaultimate.com>.
Thanks for the great responses.  They are very helpful.

After discovering more about the problem domain, it appears that our clients
do not always adhere to the file format.  For example, in a standard file,
positions 10-20 may represent the account number.  Client 1 sends files that
adhere to this standard.  Client 2 sends a file where positions 10-20
represent the account's creation date.  Client 3 sends a file where
positions 10-20 represent a comment about the account.  (So why they even
bother defining a file format standard is beyond me.)  We need to configure
these changes after the software is deployed.  So, I think this precludes me
from using an annotation driven mapping.  Which is unfortunate, because
Bindy looks like a great framework to use.

I'm debating between using Bean-IO where, as I understand it, the mapping is
defined in an xml file, or building something myself.  If I go with Bean-IO,
and we get a client who doesn't exactly adhere to the standard, I can create
a special xml mapping just for that client.



--
View this message in context: http://camel.465427.n5.nabble.com/Using-Bindy-for-multiple-record-types-in-the-same-file-tp5735541p5735578.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Bindy for multiple record types in the same file

Posted by lb <lb...@gmail.com>.
You have different options:
1) use Bindy the Willem's way (bear in mind that if you use two data format
classes you have to place them in different top-level packages)
2) use Bean-IO and do something like:

final Predicate predicateOrder       = body().startsWith("01");
final Predicate predicateCustomer = body().startsWith("02");

from("file://tmp")
    .split(body(String.class)
        .tokenize("\n")).streaming()
        .choice()
            .when(predicateOrder)
                .unmarshal(new
BeanIODataFormat("beanio-mapping.xml","order"))
                .to("log:ORDER?level=INFO&showHeaders=false")
            .when(predicateCustomer)
                .unmarshal(new
BeanIODataFormat("beanio-mapping.xml","customer"))
                .to("log:CUSTOMER?level=INFO&showHeaders=false")
            .end();

--
lb



On Fri, Jul 12, 2013 at 4:17 AM, Willem jiang <wi...@gmail.com>wrote:

> I think you can split the file and routing the lines to different bindy
> data format base on the first 2 character.
>
>
> --
> Willem Jiang
>
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Web: http://www.fusesource.com | http://www.redhat.com
> Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/)
> (English)
>           http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
> Twitter: willemjiang
> Weibo: 姜宁willem
>
>
>
>
>
> On Friday, July 12, 2013 at 2:59 AM, rodrickmusser wrote:
>
> > I am wondering if Bindy can be used in the following scenario:
> >
> > The file format I am working with is fixed length. The first two
> characters
> > indicate the record type. For example, "01" indicates an order record,
> "02"
> > indicates a customer record. If the record is an order record, characters
> > 2-11 are the order id. If the record is a customer record, characters
> 2-20
> > is the customer name.
> >
> > How does Bindy handle this situation?
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Using-Bindy-for-multiple-record-types-in-the-same-file-tp5735541.html
> > Sent from the Camel - Users mailing list archive at Nabble.com (
> http://Nabble.com).
>
>
>
>

Re: Using Bindy for multiple record types in the same file

Posted by Willem jiang <wi...@gmail.com>.
I think you can split the file and routing the lines to different bindy data format base on the first 2 character.


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Friday, July 12, 2013 at 2:59 AM, rodrickmusser wrote:

> I am wondering if Bindy can be used in the following scenario:
>  
> The file format I am working with is fixed length. The first two characters
> indicate the record type. For example, "01" indicates an order record, "02"
> indicates a customer record. If the record is an order record, characters
> 2-11 are the order id. If the record is a customer record, characters 2-20
> is the customer name.
>  
> How does Bindy handle this situation?
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-Bindy-for-multiple-record-types-in-the-same-file-tp5735541.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).