2015-04-07 148 views
0

我是使用BeanIO 2.1的全新產品,我又遇到了一個問題。多條線路上的一條記錄,只有RID第一條記錄

我試圖解碼一個固定長度的文件,它具有傳播上幾行,這裏的「擺脫」只標註在第一這些線路的一些記錄

例子:

:10:BLABLABLABLA 
:11:/TRTP/SEPA OVERBOEKING/IBAN 
HR W HERMAN 
503270327C30,49NTRFSCT20111212 
:12:BLABLABLABLA 

正如你所看到的,記錄':11:'分佈在3條線上。 我想抓住這些線作爲一個字符串列表,其中擺脫':11:'將被忽略。

這是mapping.xml文件:

<record name="ownerInformation" order="2" class="com.batch.records.OwnerInformation" minOccurs="1" maxOccurs="6" collection="list"> 
    <field name="tag" type="string" length="4" rid="true" literal=":11:" ignore="true" /> 
    <field name="description" type="string" length="unbounded" maxLength="65" /> 
</record> 

結果,異常UnexpectedRecordException:

org.beanio.UnexpectedRecordException:流的末尾達到預期的記錄 'ownerInformation'

再次感謝您的幫助

回答

1

有可能Map Bean Objects that Span Multiple Records

您將不得不爲每條線創建記錄ID,例如: 我使用commans來分隔字段。

11,/TRTP/SEPA OVERBOEKING/IBAN 
12,HR W HERMAN 
13,503270327C30 
13,49NTRFSCT20111212 

事情是這樣的:

<group name=ownerInfo class="com.batch.records.OwnerInformation" minOccurs="1" maxOccurs="6"> 
    <record name="typeInfo" class="com.batch.records.Type" order="1" minOccurs="1" maxOccurs="1" > 
    <field name="recordType" rid="true" literal="11" ignore="true" /> 
    <field name="iban" /> 
    </record> 
    <record name="customer" class="com.batch.records.Customer" order="2" minOccurs="1" maxOccurs="1" > 
    <field name="recordType" rid="true" literal="12" ignore="true" /> 
    <field name="name" /> 
    </record> 
    <record name="items" class="com.batch.records.Item" collection="list" order="3" minOccurs="1" maxOccurs="unbounded" > 
    <field name="recordType" rid="true" literal="13" ignore="true" /> 
    <field name="id" /> 
    </record> 
</group> 

這將映射到OwnerInformation這樣的:

package com.batch.records; 

/* Getters and Setter are omitted for brevity */ 

public class OwnerInformation { 
    Type type; 
    Customer customer; 
    List<Item> items; 
} 

public class Type { 
    String iban; 
} 

public class Customer { 
    String name; 
} 

public class Item { 
    String id; 
} 
0

一種方法是繪製出你不需要的線條和因此它包括你想從數據中得到的內容。以下是可以按原樣處理不同記錄類型的映射。這會爲您提供正在查找的正確訂單項。

請注意,您對每行有一個「刪除」,對於您的數據行,您基本上使用正則表達式來表示「任何不以冒號開頭的內容」。在你的「而閱讀()」代碼,你可以用你的跳閘邏輯:

if (reader.getRecordName().equals("record11")) 

或映射走得更遠,並添加組。

這裏的mapping.xml區分你行,你需要:

<beanio xmlns="http://www.beanio.org/2012/03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd"> 

<stream name="fabizFile" format="fixedlength"> 
    <record name="record10"> 
     <field name="recordType" rid="true" literal=":10:" /> 
     <field name="sometext" length="12" /> 
    </record> 
    <record name="record11"> 
     <field name="recordType" rid="true" literal=":11:" /> 
     <field name="sometext" length="unbounded" maxLength="40" /> 
    </record> 
    <record name="record12"> 
     <field name="recordType" rid="true" literal=":12:" /> 
     <field name="sometext" length="unbounded" maxLength="40" /> 
    </record> 
    <record name="goodstuff" class="FabizModel"> 
     <field name="recordText" rid="true" regex="^(?!:).+" length="unbounded" maxLength="50" /> 
    </record> 
</stream> 
</beanio> 
+0

你好,感謝您的回覆。最後我去了一個小組,其中第一個記錄確實是一個字面值爲11的記錄:下面的行記錄不受任何前綴限制。這樣我就可以在一個地方找到所有信息的單個對象。 – Fabiz