...
| No Format |
|---|
<?xml version="1.0"?> <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.01.xsd" xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.1.xsd"> <!-- Configure the EDI ParserReader to parse the message stream into a stream of SAX events. --> <resource-config<reader selectorclass="org.xmlmilyn.saxsmooks.driveredi.SmooksEDIReader"> <resource>org.milyn.smooks.edi.SmooksEDIParser</resource> <params> <!-- Generate the event stream based on this "mapping model". --> <param name="mapping-model">/example/edi-to-xml-order-mapping.xml</param> </resource-config>params> </reader> <!-- Create an "example.beans.Order" bean instance when we visit the start of the <order> element. Assign the new bean instance to the beanId of "order". Target the to be created Header bean under the beanId The "header" via the ${header} bean binding. As soon as this bean is created it will be set on this bean instance. Target the to be created ArrayList instance under the beanId "orderItems" via the ${orderItems} bean bindingand "orderItemList" beans are wired in. As soon as this list is created it will be set on this bean instance. --> <resource-config selector<jb:bindings beanId="order"> <resource>org.milyn.javabean.BeanPopulator</resource> <param name="beanId">order</param> <param name="beanClass">example.model.Order</param> <param name="bindings class="example.model.Order" createOnElement="order"> <binding <jb:wiring property="header" selectorbeanIdRef="${header}" /> <binding <jb:wiring property="orderItems" selectorbeanIdRef="${orderItems}orderItemList" /> </param>jb:bindings> </resource-config> <!-- Create an "example.beans.Header" bean instance when we visit the start of the <order> element. Note, we're creating this bean instance before we encounter the actual <header> element. This bean is setwired oninto the on the previous declared Order bean as soon as it is created, because it is target by that bean via a bean binding. Target the to be created Customer instance under the beanId "customer" via the ${customer} bean binding"order" bean. As soon as this bean is created it will be set on this bean instance. --> <resource-config selector<jb:bindings beanId="orderheader"> <resource>org.milyn.javabean.BeanPopulator</resource> <param name="beanClass">example.model.Header</param> <param name="bindings class="example.model.Header" createOnElement="order"> <!-- Header bindings... --> <binding <jb:wiring property="customer" selectorbeanIdRef="${customer}" /> <binding <jb:value property="orderId" selectordata="header /order-id" /> <binding <jb:value property="orderStatus" typedecoder="Long" selectordata="header /status-code" /> <binding <jb:value property="netAmount" typedecoder="BigDecimal" selectordata="header /net-amount" /> <binding <jb:value property="totalAmount" typedecoder="BigDecimal" selectordata="header /total-amount" /> <binding <jb:value property="tax" typedecoder="BigDecimal" selectordata="header /tax" /> <binding <jb:value property="date" typedecoder="OrderDateLongDate" selectordata="header /date"> /> <jb:decodeParam name="format">EEE MMM dd HH:mm:ss z yyyy</jb:decodeParam> </param>jb:value> </resource-config>jb:bindings> <!-- Create an "example.beans.Customer" bean instance when we visit the start of the <customer-details> element. This bean is setwired oninto the on the previous declared Header bean as soon as it is created, because it is target by that bean via a bean binding"header" bean. --> <resource-config selector<jb:bindings beanId="customer-details"> <resource>org.milyn.javabean.BeanPopulator</resource> <param name="beanClass">example.model.Customer</param> <param name="bindings class="example.model.Customer" createOnElement="customer-details"> <!-- Customer bindings... --> <binding <jb:value property="userName" selectordata="customer-details /username" /> <binding <jb:value property="firstName" selectordata="customer-details /name /firstname" /> <binding <jb:value property="lastName" selectordata="customer-details /name /lastname" /> <binding <jb:value property="state" selectordata="customer-details /state" /> </param>jb:bindings> </resource-config> < <!-- Create an ArrayList when we visit the start of the <order> element. The "orderItem" beans are Thiswired listinto isthis setlist onand thethis on the previous declared Order bean as soon as it is created, because it is target by that bean via a bean binding. Target the to be created OrderItem beans under the beanId "orderItem" via the ${orderItem} bean binding. As soon as these beans are created they will be added to this list. list is wired into the "order" bean. --> <resource-config selector<jb:bindings beanId="orderorderItemList"> <resource>org.milyn.javabean.BeanPopulator</resource> <param name="beanClass">java.util.ArrayList</param> <param name="beanId">orderItems</param> <param name="bindings class="java.util.ArrayList" createOnElement="order"> <binding selector<jb:wiring beanIdRef="${orderItem}" /> </param>jb:bindings> </resource-config> <!-- Create an "example.beans.OrderItem" bean instance when we visit the start of the <order-item> element. This bean is addwired tointo the on the previous declared ArrayList as soon as it is created, because it is target by that ArrayList via a bean binding"orderItemList" ArrayList. --> <resource-config selector<jb:bindings beanId="order-itemorderItem"> <resource>org.milyn.javabean.BeanPopulator</resource> <param name="beanClass">example.model.OrderItem</param> <param name="bindings class="example.model.OrderItem" createOnElement="order-item"> <!-- OrderItem bindings... --> <binding <jb:value property="quantity" typedecoder="Integer" selectordata="order-item /quantity" /> <binding <jb:value property="productId" typedecoder="String" selectordata="order-item /product-id" /> <binding <jb:value property="price" typedecoder="BigDecimal" selectordata="order-item /price" /> <binding <jb:value property="title" selectordata="order-item /title" /> </param> </resource-config> <!-- Configure a special decoder for the <date> field of the <header> - to set the date format. --> <resource-config selector="decoder:OrderDateLong"> <resource>org.milyn.javabean.decoders.DateDecoder</resource> <param name="format">EEE MMM dd HH:mm:ss z yyyy</param> </resource-config> </</jb:bindings> </smooks-resource-list> |
Here's the edi mapping ("/src/main/java/example/edi-to-xml-order-mapping.xml"). See the edi-to-xml tutorial for more details on this mapping:
...