Hi Markus,

In theory you should be able to handle this with two separate methods to 
test that boolean value, one which returns the value and one which 
returns the inverse. You'd need to structure your binding definition 
this way (I'm assuming you're doing an output-only binding... if you're 
doing both input and output you'd probably need to instead use a custom 
marshaller/unmarshaller):

  ...
  <structure field="houndDog">
    <structure test-method="ifHound" map-as="houndType"/>
    <structure test-method="ifDog" map-as="dogType"/>
  </structure>

where houndType and dogType are abstract <mapping> definitions for the 
DogHound class. Or you could use inline definitions with this type of 
binding:

  ...
  <structure field="houndDog">
    <structure test-method="ifHound" name="HOUND">
      <!-- details of HOUND representation -->
    </structure>
    <structure test-method="ifDog" map-as="DOG">
      <!-- details of DOG representation -->
    </structure>
  </structure>

The only issue here is that this goes down some rarely traveled paths in 
the binding compiler code generation, and I can't guarantee it'll work 
(at least not without trying it myself).

One of the reasons I really want to move on to JiBX 2.0 is to clearly 
specify what types of binding constructs are allowed, and create 
comprehensive tests for those constructs. In the 1.x series the binding 
definition has just kind of grown by accretion, so the main trails 
through the code are well tested but the side paths may or may not lead 
anywhere. This particular case is one of those side paths.

If the above approach doesn't work, you could easily do what you want 
using a custom marshaller. Just have the marshaller code check the 
value, and then write the appropriate start tag and call the abstract 
<mapping> definition to handle the content (by getting an IMarshaller 
instance for that abstract mapping, using the getMarshaller() method in 
the org.jibx.runtime.MarshallingContext class). When the call to the 
abstract marshaller returns you finish with the end tag and return.

  - Dennis

Dennis M. Sosnoski
XML and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Markus Jostock wrote:
> Dear all
>
> I would like to (have to ;-) map a class on two different XML tag 
> names, depending on a boolean attribute of the class.
>
> class DogHound {
>   Boolean dog;
>   ...
> }
>
> if dog==true it should be bound to <DOG ... />
> else it should be bound to <HOUND ... />
>
> Could I do this by using two different mappings? Or a kind of factory?
>
> I would be really glad for some kind of hint in which direction I 
> should go.
>
> Many thanks in advance!
>
> Markus
>
> -- 
>
> ________________________________________________________
> *Markus Jostock*
> Software Engineer
> ________________________________________________________
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
> trial. Simplify your report design, integration and deployment - and focus on 
> what you do best, core application coding. Discover what's new with 
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>   

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to