users@jaxb.java.net

bindings to convert common container pattern from schema to java

From: KARR, DAVID (ATTSI) <"KARR,>
Date: Fri, 15 Oct 2010 08:33:58 -0700

It seems to me that one of the most common patterns for modifying the
mapping from schema to Java is seen in this common container pattern:

XML:
  <services>
    <service>...</service>
    <service>...</service>
  </services>

Java:
  private List<Service> services;
  public List<Service> getServices() { ... }
  public void setServices(List<Service> services) { ... }

Both of these are how I would want the pattern rendered. However, no
matter if you're building schema-first or Java-first, the other side
won't work out that way unless you modify the bindings.

When I've built this Java-first, I would add the following before the
instance variable:

    @XmlElementWrapper(name = "services")
    @XmlElement(name = "service")

This produces the schema structure that I want.

Now, I have to go the other direction. I have a hand-coded schema with
the correct structure, and I have to build the "jxb:bindings" structure
to result in the correct structure in the Java code.

I've found several occurrences of the "documentation" for
"jxb:bindings", but all of them seem to cover the same similar examples
and not cover an example like this. Can someone explain in detail how I
would do this? Bonus points for pointing me to documentation that
actually talks about examples like this.