users@jaxb.java.net

RE: bindings to convert common container pattern from schema to java

From: KARR, DAVID (ATTSI) <"KARR,>
Date: Mon, 18 Oct 2010 10:17:21 -0700

I've resolved this problem. The key is that this can't be done with a
bindings file, it has to be done with a JAXB plugin. Fortunately,
someone has already done this:
http://www.conspicio.dk/blog/bjarne/jaxb-xmlelementwrapper-plugin

I've tested this with my application, and it appears to work fine.

> -----Original Message-----
> From: KARR, DAVID (ATTSI)
> Sent: Friday, October 15, 2010 8:34 AM
> To: users_at_jaxb.dev.java.net
> Subject: bindings to convert common container pattern from schema to
> java
>
> 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.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net