title: Type of substitution group or any of its subclasses are not known to this context
body: <p>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.</p>
  
  <p>Here's the class hierarchy:</p>
  
  <pre><code>+ DatasourceAbstract
    +----- DatasourceQuery
    +------DatasourceStatic
  </code></pre>
  
  <p>Given that (as documented below) I have provided the class and <strong>all</strong> its subclasses to JAXBContext explicitly, it's a mystery to me as to why they are "not known".  </p>
  
  <p>If more information is needed, let me know.  I provided everything I thought relevant, but didn't want to overload the post.</p>
  
  <h2>Error (somewhat edited for clarity):</h2>
  
  <pre><code>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)
  </code></pre>
  
  <h2>JAXBContext Creation</h2>
  
  <p>Here's where I create the JAXB Context (the line that triggers the above exception):</p>
  
  <pre><code>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);
  </code></pre>
  
  <h2>DatasourceAbstract class</h2>
  
  <p>And here's the class it's complaining about.  Note that I also used @XmlSeeAlso to identify the subclasses.</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <h2>Reference to DatasourceAbstract</h2>
  
  <p>Here's where DatasourceAbstract is referenced:</p>
  
  <pre><code>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&lt;JAXBElement&lt;?&gt;&gt; dataSourceSubstitutionGroupHead;
  
      public List&lt;JAXBElement&lt;?&gt;&gt; getDataSourceSubstitutionGroupHead() {
          if (dataSourceSubstitutionGroupHead == null) {
              dataSourceSubstitutionGroupHead = new ArrayList&lt;JAXBElement&lt;?&gt;&gt;();
          }
          return this.dataSourceSubstitutionGroupHead;
      }
  }
  </code></pre>