I am trying to generate Java classes form xsd schema and I am using JAXB. For the most part when I run the process to generate the classes it works. However there are a few classes that the member variable, getters , and setters are not generated. Here is what I have
File ns2.xsd
<xs:element name="Observation" type="ns2:ObservationType" substitutionGroup="ns1:_MetaData"/>
<xs:complexType name="ObservationType" mixed="true">
<xs:complexContent mixed="true">
<xs:extension base="ns1:AbstractType">
<xs:sequence>
<xs:element ref="ns2:identifier"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
File ns3.xsd
<xs:element name="Observation" type="ns3:ObservationType" substitutionGroup="ns2:Observation"/>
<xs:complexType name="ObservationType" mixed="true">
<xs:annotation>
<xs:documentation>this extends the ns2:ObservationType </xs:documentation>
</xs:annotation>
<xs:complexContent mixed="true">
<xs:extension base="ns2:ObservationType">
<xs:sequence>
<xs:element ref="ns3:deliveryInfo" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
This creates an empty class
package mypackage.ns3;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* this extends the ns2:ObservationType
*
* <p>Java class for ObservationType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="ObservationType">
* <complexContent>
* <extension base="{http://earth.esa.int/ns2}ObservationType">
* <sequence>
* <element ref="{http://earth.esa.int/ns3}deliveryInfo" minOccurs="0"/>
* </sequence>
* </extension>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ObservationType")
public class ObservationType
extends mypackage.ns2.ObservationType
{
}
My question is why is not creating the required member variable and its setters and getters? Is there something wrong with the schema or is there a limitation on JAXB to create the missing information form complex types that use extensions from different files? Thank you in advance. Your help or comments will be appreciated.
What makes this use case odd is that you have inheritance in your XML Schema between two types with mixed content. I think there is an XJC (and possibly spec) bug here, and as suggested by Puce you should enter a bug for it at the following link:
schema.xsd
Here is a simpler XML schema that reproduces the same issue:
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/schema"
xmlns:tns="http://www.example.org/schema"
elementFormDefault="qualified">
<complexType name="b" mixed="true">
<sequence>
<element ref="tns:bb"/>
</sequence>
</complexType>
<complexType name="c">
<complexContent mixed="true">
<extension base="tns:b">
<sequence>
<element ref="tns:cc"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="bb" type="string"/>
<element name="cc" type="string"/>
</schema>
B
The class generated for the b
type is fine.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "b", propOrder = {"content"})
@XmlSeeAlso({C.class})
public class B {
@XmlElementRef(name = "bb", namespace = "http://www.example.org/schema", type = JAXBElement.class)
@XmlMixed
protected List<Serializable> content;
public List<Serializable> getContent() {
if (content == null) {
content = new ArrayList<Serializable>();
}
return this.content;
}
}
C
The class generated for the c
type is wrong, the question is what should it be?
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "c")
public class C extends B {
}
You could add a property to the C
class. The question then comes down to which of the mixed text goes on the property inherited from B
and which goes in the property defined on C
.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "c")
public class C
extends B
{
@XmlElementRef(name = "cc", namespace = "http://www.example.org/schema", type = JAXBElement.class)
@XmlMixed
protected List<Serializable> content2;
}
You could extend the property on B
to be aware of the element reference from the c
type. This will allow you to handle the XML correctly for the b
and c
types but would allows some documents that weren't valid against the XML schema.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "b", propOrder = {"content"})
@XmlSeeAlso({C.class})
public class B {
@XmlElementRefs({
@XmlElementRef(name = "bb", namespace = "http://www.example.org/schema", type = JAXBElement.class),
@XmlElementRef(name = "cc", namespace = "http://www.example.org/schema", type = JAXBElement.class)
})
@XmlMixed
protected List<Serializable> content;
public List<Serializable> getContent() {
if (content == null) {
content = new ArrayList<Serializable>();
}
return this.content;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With