|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Use of <Condition> or Templates for selective XML-Java bindingI have a huge XML with following strcuture ( simplified to explain the issue)
I want to transform/bind this XML to Java objects based on Item Type , i.e. I want only Book and CD types and ignore all other. What's the best/efficient way to do this with Smooks v1.2 1. Use <condition> MVEL script on the source to filter out ItemType - Will this be effiecient since my XML is large? 2. Use Templates and DomModelCreator ? Appreciate your inputs. XML : <ItemBatch> <Item> <ItemId>100</ItemId> <ItemType>Book</ItemType> <ItemPrice>1000</ItemPrice> </Item> <Item> <ItemId>101</ItemId> <ItemType>CD</ItemType> <ItemPrice>20000</ItemPrice> </Item> <Item> <ItemId>103</ItemId> <ItemType>Other</ItemType> <ItemPrice>500</ItemPrice> </Item> <Item> <ItemId>104</ItemId> <ItemType>Book</ItemType> <ItemPrice>4000</ItemPrice> </Item> . . . . . <Item> <ItemId>100000</ItemId> <ItemType>Book</ItemType> <ItemPrice>600</ItemPrice> </Item> </ItemBatch> Java Object graph : public class ItemList{ ArrayList<Book> bookItems=new ArrayList<Book>(); ArrayList<CD> cdItems=new ArrayList<CD>(); } Approach- I tried to use MVEL script like this- but it is not working .. What am I missing here ? <jb:bean beanId="ItemBatch" class="java.util.HashMap" createOnElement="ItemBatch/Item"> <jb:value property="ItemType" data="ItemType" /> </jb:bean> <jb:bean beanId="ItemList" class="com.fmrco.fi.oms.transactionfeedhandler.message.TransactionBatch" createOnElement="ItemBatch"> <jb:wiring property="itemList" beanIdRef="itemList" /> </jb:bean> <jb:bean beanId="bookItems" class="java.util.ArrayList" createOnElement="ItemBatch"> <jb:wiring beanIdRef="Book" /> </jb:bean> <jb:bean beanId="Book" class="example.Book" createOnElement="ItemBatch/Item"> <condition> ItemBatch.ItemType == 'Book'</condition> <jb:value property="ItemId" decoder="String" data="ItemId" /> </jb:bean> Thanks -SK |
|
|
Re: Use of <Condition> or Templates for selective XML-Java bindingIf it's a huge message, the best way to handle it would probably be to
split it up, item by item, routing each Item object instance to e.g. a JMS Queue for parallel processing by another process. You could use a condition on the routing config to only route books or CDs to that JMS Queue. You could have a 2nd, 3rd etc JMS queue (or use a file or DB) and route the other item types to those. psk wrote: > I have a huge XML with following strcuture ( simplified to explain the issue) > I want to transform/bind this XML to Java objects based on Item Type , i.e. > I want only Book and CD types and ignore all other. > > What's the best/efficient way to do this with Smooks v1.2 > > 1. Use <condition> MVEL script on the source to filter out ItemType - Will > this be effiecient since my XML is large? > > 2. Use Templates and DomModelCreator ? > > Appreciate your inputs. > > XML : > > <ItemBatch> > <Item> > <ItemId>100</ItemId> > <ItemType>Book</ItemType> > <ItemPrice>1000</ItemPrice> > </Item> > > <Item> > <ItemId>101</ItemId> > <ItemType>CD</ItemType> > <ItemPrice>20000</ItemPrice> > </Item> > <Item> > <ItemId>103</ItemId> > <ItemType>Other</ItemType> > <ItemPrice>500</ItemPrice> > </Item> > <Item> > <ItemId>104</ItemId> > <ItemType>Book</ItemType> > <ItemPrice>4000</ItemPrice> > </Item> > . > . > > . > . > . > <Item> > <ItemId>100000</ItemId> > <ItemType>Book</ItemType> > <ItemPrice>600</ItemPrice> > </Item> > > > </ItemBatch> > > > > Java Object graph : > > public class ItemList{ > > ArrayList<Book> bookItems=new ArrayList<Book>(); > ArrayList<CD> cdItems=new ArrayList<CD>(); > > } > > Thanks > -SK > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Use of <Condition> or Templates for selective XML-Java bindingOK..Let's keep huge message aside.. I was trying to get this working uisng <condition> script..
Could you pls check what's wrong with this configuration...if I use <condition> to filter out only Book item types it's not working. If I remove "isdef" it errors out. -Thanks <jb:bean beanId="ItemBatch" class="java.util.HashMap" createOnElement="ItemBatch/Item"> <jb:value property="ItemType" data="ItemType" /> </jb:bean> <jb:bean beanId="ItemList" class="com.fmrco.fi.oms.transactionfeedhandler.message.TransactionBatch" createOnElement="ItemBatch"> <jb:wiring property="itemList" beanIdRef="itemList" /> </jb:bean> <jb:bean beanId="bookItems" class="java.util.ArrayList" createOnElement="ItemBatch"> <jb:wiring beanIdRef="Book" /> </jb:bean> <jb:bean beanId="Book" class="example.Book" createOnElement="ItemBatch/Item"> <condition> isdef ItemBatch.ItemType == 'Book'</condition> <jb:value property="ItemId" decoder="String" data="ItemId" /> </jb:bean>
|
|
|
Re: Use of <Condition> or Templates for selective XML-Java binding
|
|
|
Re: Use of <Condition> or Templates for selective XML-Java bindingSorry for not replying to your message... I'm totally tied up at work at
the moment with a release, so I'm not able to give time to Smooks related questions. Bottom line... I'm not sure the conditional stuff will work all that well with the Java Binding functionality because there are multiple Visitor implemention at play behind the scenes and getting it to work properly would require coordination between them. This is something we should look at fixing in Smooks wrt Java Binding. So for you, you should be able to wire the beans together manually yourself using a groovy scriptlet (see groovy scripting) i.e. access the BeanRepository directly in the script, adding the items you want to List bean. I think this has come up before on this list so search the archives. Regards, T. psk wrote: > > >> OK. I want to keep aside huge message issue and was trying to get this >> working with <condition>...Could youpls check what's wrong with this >> configuration...If I remove this line >> <condition>isdef ItemBatch.ItemType == 'Book'</condition> then I get all >> item in my list and if I include it then none. >> >> Thx- >> >> <jb:bean beanId="ItemBatch" class="java.util.HashMap" >> createOnElement="ItemBatch/Item"> >> <jb:value property="ItemType" data="ItemType" /> >> </jb:bean> >> >> <jb:bean beanId="ItemList" >> class="com.fmrco.fi.oms.transactionfeedhandler.message.TransactionBatch" >> createOnElement="ItemBatch"> >> <jb:wiring property="itemList" beanIdRef="itemList" /> >> </jb:bean> >> >> <jb:bean beanId="bookItems" class="java.util.ArrayList" >> createOnElement="ItemBatch"> >> >> <jb:wiring beanIdRef="Book" /> >> >> </jb:bean> >> >> >> <jb:bean beanId="Book" class="example.Book" >> createOnElement="ItemBatch/Item"> >> <condition>isdef ItemBatch.ItemType == 'Book'</condition> >> <jb:value property="ItemId" decoder="String" data="ItemId" /> >> >> >> </jb:bean> >> >> >> >> >> > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |