I can't seem to get all the JAXB magic right with regard to the abstract super-class generated from a substitution group. I'm using the reference implementation of JAXB.
Here's the class hierarchy:
+ DatasourceAbstract
+----- DatasourceQuery
+------DatasourceStatic
Given that (as documented below) I have provided the class and all its subclasses to JAXBContext explicitly, it's a mystery to me as to why they are "not known".
If more information is needed, let me know. I provided everything I thought relevant, but didn't want to overload the post.
Error (somewhat edited for clarity):
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Invalid @XmlElementRef : Type "class com.escholar.reports.reportXML.DatasourceAbstract" or any of its subclasses are not known to this context.
this problem is related to the following location:
at protected java.util.LinkedList com.escholar.reports.reportXML.Data.dataSourceSubstitutionGroupHead
at com.escholar.reports.reportXML.Data
at protected com.escholar.reports.reportXML.Data com.escholar.reports.reportXML.ReportJAXB.data
at com.escholar.reports.reportXML.ReportJAXB
at public com.escholar.reports.reportXML.ReportJAXB com.escholar.reports.reportXML.ObjectFactory.createReportResourceJAXB()
at com.escholar.reports.reportXML.ObjectFactory
at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
..... Partially ellided stacktrace ............
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at com.escholar.reports.utilities.reportsamples.ReportXMLGenerator.main(ReportXMLGenerator.java:69)
JAXBContext Creation
Here's where I create the JAXB Context (the line that triggers the above exception):
JAXBContext jc =
JAXBContext.newInstance(
com.escholar.reports.reportXML.ObjectFactory.class,
com.escholar.reports.reportXML.DatasourceAbstract.class,
com.escholar.reports.reportXML.DatasourceStatic.class,
com.escholar.reports.reportXML.DatasourceQuery.class);
DatasourceAbstract class
And here's the class it's complaining about. Note that I also used @XmlSeeAlso to identify the subclasses.
package com.escholar.reports.jaxb;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DatasourceAbstract")
@XmlSeeAlso({
DatasourceStatic.class,
DatasourceQuery.class
})
public abstract class DatasourceAbstract {
@XmlAttribute(name = "Name")
@XmlSchemaType(name = "anySimpleType")
protected String name;
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
}
Reference to DatasourceAbstract
Here's where DatasourceAbstract is referenced:
package com.escholar.reports.jaxb;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"dataSourceSubstitutionGroupHead"
})
@XmlRootElement(name = "Data")
public class Data {
@XmlElementRef(name = "DataSourceSubstitutionGroupHead", type = JAXBElement.class)
protected List<JAXBElement<?>> dataSourceSubstitutionGroupHead;
public List<JAXBElement<?>> getDataSourceSubstitutionGroupHead() {
if (dataSourceSubstitutionGroupHead == null) {
dataSourceSubstitutionGroupHead = new ArrayList<JAXBElement<?>>();
}
return this.dataSourceSubstitutionGroupHead;
}
}