[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jibx-users
Subject:    Re: [jibx-users] marshalling based on 'choice'
From:       Bao Trang <btrang () gmail ! com>
Date:       2004-09-22 13:02:36
Message-ID: f53bfceb04092206023b4c64c8 () mail ! gmail ! com
[Download RAW message or body]

I'll give it a shot.  Thanks!


On Tue, 21 Sep 2004 19:12:48 -0700, Dennis Sosnoski <dms@sosnoski.com> wrote:
> Bao Trang wrote:
> 
> >In my java class, I have a boolean and two objects, A and B.  If the
> >boolean is set to true, I want the marshaller to output object A in my
> >XML file.  Otherwise, I want the marshaller to output object B.
> >
> >
> You should be able to do this by using a pair of test-methods, one for
> object A (which just returns the boolean) and one for object B (which
> returns the logical not of the boolean). Then your binding definition
> would go something like this:
> 
>   <mapping ...>
>     ...
>     <structure name="A" field="aproperty" usage="optional"
> test-method="testA">
>       ...
>     </structure>
>     <structure name="B" field="bproperty" usage="optional"
> test-method="testB">
>       ...
>     </structure>
>     ...
> 
> >Conversely, when I'm unmarshalling, if Object A exists, I want my
> >boolean to be set to true.  Otherwise if Object B exists in the xml
> >file, I want the boolean to be set to false.
> >
> There's no way to do this directly, but you can use the above binding
> fragment and add a post-set method to the containing object binding. The
> post-set method will be called after that object has been unmarshalled,
> and you can then set your boolean as "aproperty != null". You can also
> use the post-set method to check that one and only one of the
> alternatives was included in the unmarshalled document, if you want
> (throwing an exception if neither was present or both were present).
> 
>   - Dennis
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
> Project Admins to receive an Apple iPod Mini FREE for your judgement on
> who ports your project to Linux PPC the best. Sponsored by IBM.
> Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>


-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic