Results 1 to 7 of 7

Thread: Printing original line after using tokenizers

  1. #1
    Join Date
    Jul 2010
    Posts
    10

    Default Printing original line after using tokenizers

    How can I get original line read from file after I have read and tokenized it using tokenizers and field-set mappers ? I want to split good and bad lines . After reading/searching I believe I have lost original item once once I mapped to Java object.
    Thanks.

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    It's not as common a requirement as you might think, so you don't find a ready-made API for it in the framework. A FieldSet is a very low level abstraction, so you can pretty much get the line from there. The best solution I have seen is a composite item type that contains a domain object and the input field set,

  3. #3
    Join Date
    Jul 2010
    Posts
    10

    Default

    Dave, Thanks for your reply. I would have been able to recreate the line from FieldSet if I would have read all the fields. I am reading limited number of fields from my long fixed-length line. It will be redundant to read all fields. Even if I do that and use composite item type, I will have to "recreate" the line which is not good idea as I will have to know formats of all other fields.

    I am not sure if this is not common requirement. Its common to send back problematic records back to the sender of the file . The sender may correct it manually and send all the records again as new input file.

    Is there any type of reader which just reads line as is ? Something like "PassThroughReader" ? May be I can use composite pattern there to collect lines as is and also map to my domain objects using FieldSet mappers.

  4. #4
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    That's another option. In either case you don't need a custom reader, just plug a LineMapper into the existing reader. A pass through LineMapper is trivial to write (so not in the framework a far as I know).

  5. #5
    Join Date
    Jul 2010
    Posts
    10

    Default

    Hi Dave,
    Thanks for response again. I just checked, PassThroughLineMapper is already there !. I think its for same purpose . My current reader is already PatternMatchingCompositeLineMapper using LineTokenizer mapping to domain objects. How can I plug in additional PassThroughLineMapper into it , is it possible to map input line to more than one domain object ? ( Here second domain will be just String )

  6. #6
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    Sounds like you just need to push the PatternMatchingCompositeLineMapper down to an ItemProcessor. Or use an extra composite wrapper around the PatternMatchingCompositeLineMapper and the PassThroughLineMapper.

  7. #7
    Join Date
    Jul 2010
    Posts
    10

    Smile

    Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •