users@jaxb.java.net

Re: Multiple inheritance problem

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 15 Jan 2010 12:44:22 +0100

You might use these annotations for the field "header" in class AbstractMessage:

  @XmlElement(name="header")
  @XmlSchemaType(name="any")

Marshalling of Message1 results in:

<msg1>
    <header xsi:type="msgHeader1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <foo>foo in hdr1</foo>
    </header>
    <Summary>1000</Summary>
    <field1>42</field1>
</msg1>

and Message2 gives s.th. like:

<msg2>
    <header xsi:type="msgHeader2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <bar>bar in hdr2</bar>
    </header>
    <Summary>1000</Summary>
    <field2>42</field2>
</msg2>

-W


On Thu, Jan 7, 2010 at 3:47 PM, Bellandi, Daniele
<Daniele.Bellandi_at_contshipitalia.com> wrote:
> Hi,
>
> I've a problem in inheritance between classes.
>
> I use a little example for explain a situation very similar to mine.
>
> I'm quite newbie in jaxb and I'm trying to insert it in a preexistent
> project...it is very structurated..and
>
> so I've encountered some problems...
>
>
>
> public abstract class AbstractMessage implements .... {
>
>
>
>             protected AbstractHeader header;      <---------------- HOW TO
> DEFINE?!
>
>
>
>             @XmlElementWrapper(name = InformationsList")
>
>             protected List<Information> informations = new
> ArrayList<Information>();
>
>
>
>             @XmlElement(name="Summary")
>
>             protected MsgSummary summary;
>
> }
>
>
>
> ------------- Headers ----------------
>
>
>
> public abstract class AbstractHeader {
>
>   ...
>
>   ..
>
>   .
>
> }
>
>
>
> public class MsgHeader1 extends AbstractHeader {
>
>   ...
>
>   ..
>
>   .
>
> }
>
>
>
> public class MsgHeader2 extends AbstractHeader {
>
>   ...
>
>   ..
>
>   .
>
> }
>
>
>
> ------------- Messages ----------------
>
>
>
> public class Message1 extends AbstractMessage {
>
>
>
> /* Here I'd like to marshall/unmarshall header as MsgHeader1*/
>
>
>
>   ...
>
>   ..
>
>   .
>
> }
>
>
>
> public class Message2 extends AbstractMessage {
>
>
>
> /* Here I'd like to marshall/unmarshall header as MsgHeader2*/
>
>
>
>   ...
>
>   ..
>
>   .
>
> }
>
>
>
>
>
> Can you Help me?
>
> Thanks in advance.
>
>
>
> Daniele Bellandi
>
>
>
>