Hi,

Thanks for the reply. But is there a way where I hava
a mapping with label and reuse it for the product and
the customer ?

Thanks
Ruchik

--- Mocky Habeeb <[EMAIL PROTECTED]> wrote:

> JiBX handles this situation with structures. The
> structure basics are
> explained here: 
>
http://jibx.sourceforge.net/tutorial/binding-structures.html
> Information on how to convert different date formats
> can be found here:
> http://jibx.sourceforge.net/details/conversions.html
> and here:
>
http://jibx.sourceforge.net/details/format-element.html
> 
> By way of example however, this binding file:
> 
> <binding value-style="element">
>     <mapping name="store" class="Store">
>         <collection field="products"
> item-type="Product"/>
>         <collection field="customers"
> item-type="Customer"/>
>     </mapping>
>     
>     <mapping name="product" class="Product">
>         <value name="name" field="name"/>
>         <structure field="life">
>             <value name="manufacture-date"
> field="startDate"/>
>             <value name="expiry-date"
> field="endDate"/>
>         </structure>
>     </mapping>
>     
>     <mapping name="customer" class="Customer">
>         <value name="name" field="name"/>
>         <structure field="membership">
>             <value name="joining-date"
> field="startDate"/>
>             <value name="end-date" field="endDate"/>
>         </structure>
>     </mapping>
> </binding>
> 
> Mapped to these classes:
> 
> public class Store {
>     private ArrayList products;
>     private ArrayList customers;
> 
>     public String toString() {
>         return "Products:" + products +
> "\nCustomers:" + customers;
>     }
> 
>     public static void main(String[] argz) throws
> Exception {
>         IBindingFactory bfact =
> BindingDirectory.getFactory(Store.class);
>         IUnmarshallingContext uctx =
> bfact.createUnmarshallingContext();
>         Store store = (Store)
> uctx.unmarshalDocument(new
> FileInputStream("store.xml"), null);
>         System.out.println("store:\n" + store);
>     }
> }
> 
> public class Product {
>     private String name;
>     private Period life;
>     public String toString() {
>         return "Product {name: " + name + ", life: "
> + life + "}";
>     }
> }
> 
> public class Customer {
>     private String name;
>     private Period membership;
>     public String toString() {
>         return "Customer {name: " + name + ",
> membership: " + membership
> + "}";
>     }
> }
> 
> public class Period {
>     private Date startDate;
>     private Date endDate;
>     public String toString(){
>         return "Period {start: " + startDate + ",
> end: " + endDate +
> "}";
>     }
> }
> 
> When fed this xml file:
> <store>
>       <product>
>               <name>biscuits</name>
>       
>
<manufacture-date>2005-07-05T01:33:00</manufacture-date>
>               <expiry-date>2008-12-31T23:59:59</expiry-date>
>       </product>
>       <customer>
>               <name>xxx</name>
>               <joining-date>2004-09-12T11:28:00</joining-date>
>               <end-date>2005-09-12T11:27:59</end-date>
>       </customer>
> </store>
> 
> Will produce the following output:
> store:
> Products:[Product {name: biscuits, life: Period
> {start: Mon Jul 04
> 21:33:00 EDT 2005, end: Wed Dec 31 18:59:59 EST
> 2008}}]
> Customers:[Customer {name: xxx, membership: Period
> {start: Sun Sep 12
> 07:28:00 EDT 2004, end: Mon Sep 12 07:27:59 EDT
> 2005}}]
> 
> 
> Mocky
> 
> 
> 
> 
> 
> 
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of Ruchik
> Bhatt
> Sent: Wednesday, July 20, 2005 6:10 AM
> To: [email protected]
> Subject: [jibx-users] Mapping multiple elements to
> one class and using
> it as datatype
> 
> 
> Hi,
> 
> I have the following classes.
> Class Period {
> private Date startDate;
> privae Date endDate;
> }
> 
> Class Product {
> private String name;
> /**
> store the manufacture date and expiry date of the
> product
> */
> private Period life;
> }
> 
> Class Product {
> private String name;
> /**
> store the manufacture date and expiry date of the
> product
> */
> private Period membership;
> }
> The xml structure is 
> <Strore>
>       <product>
>               <name>biscuits</name>
>               <manufacture-date>01-jul-05</manufacture-date>
>               <expiry-date>11-jul-05</expiry-date>
>       </product>
>       <customer>
>               <name>xxx</name>
>               <joining-date>01-jul-05</mdate>
>               <end-date>01-jul-06</edate>
>       </customer>
> </store>
> 
> I want to define binding for the product and
> customer
> such that the dates are mapped to the period.
> Please help.
> 
> Thanks in advance.
> 
> Ruchik
> 
> 
>               
> __________________________________ 
> Yahoo! Mail for Mobile 
> Take Yahoo! Mail with you! Check email on your
> mobile phone. 
> http://mobile.yahoo.com/learn/mail 
> 
> 
>
-------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux
> Migration Strategies
> from IBM. Find simple to follow Roadmaps,
> straightforward articles,
> informative Webcasts and more! Get everything you
> need to get up to
> speed, fast.
>
http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> jibx-users mailing list
> [email protected]
>
https://lists.sourceforge.net/lists/listinfo/jibx-users
> 
> 
> 
>
-------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux
> Migration Strategies
> from IBM. Find simple to follow Roadmaps,
> straightforward articles,
> informative Webcasts and more! Get everything you
> need to get up to
> speed, fast.
>
http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> jibx-users mailing list
> [email protected]
>
https://lists.sourceforge.net/lists/listinfo/jibx-users
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to