users@jaxb.java.net

RE: Re: Extensible soutions using JAXB?

From: Ernst, Matthias <matthias.ernst_at_coremedia.com>
Date: Fri, 25 May 2007 10:00:03 +0200

> Could you please elaborate on my
> assumptions and how this is done? I'm very interested.

Andrew,

straw man:

@XmlType
public class Feed {
  @XmlElement public String author;
  @XmlAnyElement @XmlElementRef public List<Object> extensions;
}

JaxbContext.create(Feed.class).newUnmarshaller().unmarshal(
  <feed><author>Matthias</author><liaison>CoreMedia</liaison></feed>,
Feed.class);

would unmarshal into:

  Feed {
    author = "Matthias"
    extensions = [ org.w3c.dom.Element "liaison" { org.w3c.dom.Text "CoreMedia" } ]
  }

So far so great. Now you realise that "liaison" is a "standard" element for your application. You go ahead and add

@XmlRootElement(name="liaison")
@XmlType(name="liaison")
public class Liaison {
  @XmlValue
  public String value;
}

and make it known to the context: JaxbContext.create(Feed.class, Laison.class) ...

et voila: it unmarshals into

  Feed {
    author = "Matthias"
    extensions = [ Liaison { value="CoreMedia" } ]
  }


Does that help?
Matthias

-- 
matthias.ernst_at_coremedia.com
software architect
+49.40.32 55 87.503
CoreMedia AG
Executive Board: Sören Stamer (CEO), Dr. Klemens Kleiminger (CFO)
Supervisory Board: Prof. Dr. Joachim Schmidt (Chairman)
Trade Register: Amtsgericht Hamburg, HR B 76277
 
> -----Original Message-----
> From: Andrew Hughes [mailto:azza_at_lisasoft.com] 
> Sent: Friday, May 25, 2007 4:11 AM
> To: users_at_jaxb.dev.java.net
> Subject: Re: Extensible soutions using JAXB?
> 
> Hi Ernst,
> 
> No, not ATOM... but an RSS format never the less (plus 
> others). I must confess that I don't really follow your 
> explaination... are you suggesting that I can write java 
> class that can be used in conjunction with JAXB to harvest 
> all extension/unbound elements from the document? I hope so, 
> it sounds pretty cool!