users@jaxb.java.net

Re: Problems generating objects from complexContent

From: Martin Grebac <martin.grebac_at_oracle.com>
Date: Tue, 23 Aug 2011 16:41:07 +0200

Hi,
 I believe the issue comes from the content property generated in
PartyDescriptor which is supposed to 'swallow' all the content - which
corresponds to how jaxb handles inheritance. You might find this useful
as well:
http://blogs.oracle.com/mgrebac/entry/handling_extended_mixed_content_in
 MartiNG

On 08/11/2011 06:33 PM, Bastien Jansen wrote:
> Hi Martin,
>
> You can find the full XSD at the following URL:
>
> http://ddex.net/xml/20081015/ddexC.xsd
> http://ddex.net/xml/20081015/ddex.xsd
> http://ddex.net/xml/2008/ern-main/30/ern-main.xsd
>
> Here are the customisations I'm using:
>
> <jxb:bindings version="1.0"
> xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
> <jxb:bindings schemaLocation="ern-main.xsd" node="/xs:schema">
> <jxb:schemaBindings>
> <jxb:package name="com.myproject.jaxb.sonymobile.ernm"/>
> </jxb:schemaBindings>
> </jxb:bindings>
>
> <jxb:bindings schemaLocation="ddexC.xsd" node="/xs:schema">
> <jxb:schemaBindings>
> <jxb:package name="com.myproject.jaxb.sonymobile.ddexc"/>
> </jxb:schemaBindings>
> </jxb:bindings>
>
> <jxb:bindings schemaLocation="ddexC.xsd"
> node="/xs:schema/xs:complexType[@name='PartyDescriptor']/xs:choice/xs:element[@name='PartyId']">
> <jxb:property name="SinglePartyId"/>
> </jxb:bindings>
>
> <jxb:bindings schemaLocation="ddex.xsd" node="/xs:schema">
> <jxb:schemaBindings>
> <jxb:package name="com.myproject.jaxb.sonymobile.ddex"/>
> <jxb:nameXmlTransform>
> <jxb:typeName suffix="Values"/>
> </jxb:nameXmlTransform>
> </jxb:schemaBindings>
> </jxb:bindings>
> </jxb:bindings>
>
> I put each XSD into a different package to avoid class name
> collisions. I hope you will find answers to all your questions using
> these elements :)
>
> Thanks again for your help, I appreciate it very much!
>
> Bastien
>
> On 11 August 2011 18:23, Martin Grebac <martin.grebac_at_oracle.com
> <mailto:martin.grebac_at_oracle.com>> wrote:
>
> Hi,
> your usecase is not complete, so hard to tell what's happening.
> Do you
> use any specific customizations while generating the code? Is
> ArtistRole
> defined in the PartyDescriptor? Is any of those using a mixed content
> mode which would imply different code generation path?
> MartiNG
>
> On 08/10/2011 11:35 PM, Bastien Jansen wrote:
> > Hi,
> >
> > I'm trying to generate Java objects from the DDEX XSD
> > (http://ddex.net/xml/20081015/ddexC.xsd) using JAXB. The problem is
> > that the generated objects are missing java attributes.
> > For example, this element definition:
> >
> > <xs:complexType name="DisplayArtist">
> > <xs:complexContent>
> > <xs:extension base="ddexC:PartyDescriptor">
> > <xs:sequence>
> > <xs:element name="ArtistRole"
> > type="ddexC:ArtistRole" minOccurs="0"
> > maxOccurs="unbounded">
> > </xs:element>
> > </xs:sequence>
> > <xs:attribute name="SequenceNumber"
> type="xs:integer"
> > use="optional">
> > </xs:attribute>
> > </xs:extension>
> > </xs:complexContent>
> > </xs:complexType>
> >
> > is translated into
> >
> > @XmlAccessorType(XmlAccessType.FIELD)
> > @XmlType(name = "DisplayArtist")
> > public class DisplayArtist
> > extends PartyDescriptor
> > {
> >
> > @XmlAttribute(name = "SequenceNumber")
> > protected BigInteger sequenceNumber;
> >
> > public BigInteger getSequenceNumber() {
> > return sequenceNumber;
> > }
> >
> > public void setSequenceNumber(BigInteger value) {
> > this.sequenceNumber = value;
> > }
> >
> > }
> >
> > DisplayArtist.java is missing a List<ArtistRole>. I don't know
> why it
> > is not generated. I noticed that if if remove the complexContent and
> > extension tags, I get what I want (but I loose the inheritance...).
> >
> > Does anyone know why this happens?
>
> --
> Martin Grebac, GlassFish/Metro/JAXB/Tooling at Oracle
> http://blogs.sun.com/mgrebac
> ICQ: 93478885
>
>

-- 
Martin Grebac, GlassFish/Metro/JAXB/Tooling at Oracle
http://blogs.sun.com/mgrebac
ICQ: 93478885