Repeating Segments clarification

712 views
Skip to first unread message

arcot

unread,
May 14, 2012, 12:42:28 AM5/14/12
to beanio-users, kalya...@gmail.com
Greetings and Salutations,

This is an amazing API for parsing flat file into Java objects. I had
a requirement where I need to process an incoming flat file into Java
objects. I was going over internet to see if there are any API that
will make my job simpler and more efficient. I came across couple o
APIs, but BeanIO was the best.

I wanted to check if BeanIO support multiple repeating segments and
segments with in segments?

Here is a my sample scenario:

Class Record1{

String field1;
String field2;
.
.
List<Object1>listOfObject1s; //list of objects of type object1
[1....10]
List<Object2>listOfObject2s; //list of objects of type object2
[1....10]
String field3;
String field4;
}


Class Object1{

String object1Field1;
List<Object3>listOfObject3s; //list of objects of type object3
[1....10]

}

Class Object2{

String object2Field1;
List<Object4>listOfObject4s; //list of objects of type object4
[1....10]
String object2Field2;
}

Class Object3{
String object3Field1;
}

Class Object4{
String object4Field1;
}

I tried an example myself with BeanIO 2.0 but it did not work.
I would highly appreciate you can tell me if this can be achieved
using BeanIO or is there any alternative approach for this?

Again, you are doing a great job.

Thank you,

Arcot.

arcot

unread,
May 14, 2012, 11:30:47 AM5/14/12
to beanio-users
Greetings and Salutation,

I figured it out, if I mention the make minOccurs = maxOccurs, then I
can have recursive repeating segments with in segments.

This API is amazing.

Thank you Once again.

Arcot.

Kevin

unread,
May 14, 2012, 10:34:57 PM5/14/12
to bea...@googlegroups.com
Thanks Arcot.  And yes, as long as the number of segments is pre-determined (i.e. minOccurs = maxOccurs as you said), nested recurring segments should work just fine.  If the number of segments is indeterminate, the segment must appear at the end of the record (for flat file formats), and cannot be nested.

Thanks,
Kevin 

arcot

unread,
May 15, 2012, 2:51:30 PM5/15/12
to beanio-users
Hi Kevin,

Thanks for replying.

I have one question for you, is there any limit on the number of time
a segment can repeat?

Here is an example:

public class Employee {
String firstName;
String lastName;
List aliasNames;
List hobbies;
}

Mapping.xml:

<beanio>
<stream name="employeeFile" format="fixedlength">
<record name="employee" class="com.sample.Employee">
<field name="firstName" length="100"/>
<field name="lastName" length="100"/>
<segment name="aliasNames" collection="list"
class="com.sample.AliasNames" minOccurs="999" maxOccurs="999">
<field name="akaFName" length="20"/>
<field name="akaLName" length="20"/>
</segment>
<segment name="hobbies" class="com.sample.Hobbies"
collection="list" minOccurs="2" maxOccurs="2">
<field name="name" length="20"/>
</segment>
</record>
</stream>
</beanio>

When I test the above code, I get this following error:

Exception in thread "main" org.beanio.BeanIOConfigurationException:
Invalid field 'name', in segment 'hobbies', in record 'employee', in
stream 'employeeFile': Cannot determine field position, field is
preceded by a component with indeterminate or unbounded occurences


When I change the minOccurs and maxOccurs of segment "aliasName" to
127 or swap the positions of segments "aliasNames" and "hobbies", I
dont get any exception.
example:
<stream name="employeeFile" format="fixedlength">
<record name="employee" class="com.sample.Employee">
<field name="firstName" length="100"/>
<field name="lastName" length="100"/>
<segment name="hobbies" class="com.sample.Hobbies"
collection="list" minOccurs="2" maxOccurs="2">
<field name="name" length="20"/>
</segment>
<segment name="aliasNames" collection="list"
class="com.sample.AliasNames" minOccurs="999" maxOccurs="999">
<field name="akaFName" length="20"/>
<field name="akaLName" length="20"/>
</segment>
</record>
</stream>

or

<stream name="employeeFile" format="fixedlength">
<record name="employee" class="com.sample.Employee">
<field name="firstName" length="100"/>
<field name="lastName" length="100"/>
<segment name="aliasNames" collection="list"
class="com.sample.AliasNames" minOccurs="127" maxOccurs="127">
<field name="akaFName" length="20"/>
<field name="akaLName" length="20"/>
</segment>
<segment name="hobbies"
class="com.sample.Hobbies" collection="list" minOccurs="2"
maxOccurs="2">
<field name="name" length="20"/>
</segment>
</record>
</stream>

Is there any restrictions that I am missing? How to address this
scenario? Is there any limitation on total size of the fixedlength
record?


Thank you in advance for you time.

Arcot.

Kevin

unread,
May 15, 2012, 11:57:20 PM5/15/12
to bea...@googlegroups.com
Hi Arcot,

This is definitely a bug.  Size limits are generally Integer.MAX_VALUE.

I've attached a 2.x snapshot JAR file that should resolve the problem, but I haven't checked any fix into SVN yet.  I should have time this weekend to formally open an issue and verify I didn't make the same coding mistake in other places- terribly busy this week, sorry.

Thanks,
Kevin
beanio.jar

Sreenivasulu Arcot

unread,
May 16, 2012, 12:17:41 AM5/16/12
to bea...@googlegroups.com
hi Kevin, 

Thanks for the quick fix, I will test this and will keep you posted.

Keep up the great work.

Thanks,

Arcot.
Reply all
Reply to author
Forward
0 new messages