users@jaxb.java.net

RE: Re: How to get different things into the same list?

From: Markus Karg <karg_at_quipsy.de>
Date: Thu, 3 Jul 2008 16:32:13 +0200

Thanks a lot for your answer! Indeed, it pointed me in the exactly right direction. As I found out, it's just as easy as using @XmlElements to surround multiple @XmlElement annotations. :-)

Thank you so much!
Markus



-----Original Message-----
From: Kevin Wooten [mailto:kevin_at_wooten.com]
Sent: Mittwoch, 2. Juli 2008 18:11
To: users_at_jaxb.dev.java.net
Subject: Re: How to get different things into the same list?


You need to tell JAXB to create one list and what to allow inside it.
Here is a snippet of my JAXB parser for COLLADA 3D files that should
help point you in the right direction...

     @XmlElementRefs({
         @XmlElementRef(name = "matrix", namespace = "http://www.collada.org/2005/11/COLLADASchema
", type = Matrix.class),
         @XmlElementRef(name = "rotate", namespace = "http://www.collada.org/2005/11/COLLADASchema
", type = Rotate.class),
         @XmlElementRef(name = "skew", namespace = "http://www.collada.org/2005/11/COLLADASchema
", type = Skew.class),
         @XmlElementRef(name = "translate", namespace = "http://www.collada.org/2005/11/COLLADASchema
", type = JAXBElement.class),
     })
     protected List<Object> transforms;

In this list it is imperative that the elements of "transforms" are
kept in the order defined in the file (otherwise the data is useless);
when using this method JAXB guarantees that this is the case. Use
this as a guide and look at the docs for these elements, that should
get you going.


On Jul 2, 2008, at 8:52 AM, Markus Karg wrote:

> Hi, I am a JAXB beginner and have the following problem. I do not
> use schema, but only manually annotated Java classes.
>
> Given the following XML:
>
> <A>
> <B />
> <C />
> <C />
> <B />
> </A>
>
> As you can see, A's children can only be B and C. But: The sequence
> of B and C is essential and in terms of Java, B and C must be public
> classes which the same interface or super class.
>
> In fact I do not know how to solve that. I tried adding a
> Collection<? extends X> to A, where X is an abstract superclass to B
> and C. But that is not working. Also I do not know how to correctly
> annotate the Collection that stores the B and C mix: When using
> @XmlAnyElement I end up with a collection filled of DOM stuff or
> something, but not with real B or C instances. On the other hand,
> when I annotate it with @XmlElement, I have to provide the actual
> class to fill in (B or C), while I actually need B AND C inside
> it...?!
>
> Can anoybody help me with this, I am totally confused!
>
> Thanks a lot
> Markus
>
> QUIPSY QUALITY GmbH & Co. KG
> Ein Unternehmen der MES-Gruppe
> Stuttgarter Strasse 23
> D-75179 Pforzheim
> Tel: 07231-9189-52
> Fax: 07231-9189-59
> www.quipsy.de
> karg_at_quipsy.de
> Registergericht Mannheim HRA 701214
> Geschäftsführer: Nils Schroeder
>
> Diese E-Mail enthält persönliche, vertrauliche und vor Weitergabe
> geschützte Informationen und ist ausschließlich für den vorgesehenen
> o.g. Empfänger (Adressaten) bestimmt. Falls Sie diese E-Mail
> versehentlich erhalten haben und nicht der vorgesehene Empfänger
> sind, bitten wir Sie, die E-Mail und deren Anhänge nicht
> aufzubewahren, nicht zu vervielfältigen, nicht zu nutzen und nicht
> weiterzugeben. Bitte informieren Sie uns als Absender über diesen
> Zustellungsfehler und löschen Sie die E-Mail.
>
>
>
>
>
> <Markus
> KARG
> .vcf
> >---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net