title: Polymorphism in XSD schema and JAXB classes
body: <p>I have an xml like this:</p>
  
  <pre><code>&lt;todo&gt;
      &lt;doLaundry cost="1"/&gt;
      &lt;washCar cost="10"/&gt;
      &lt;tidyBedroom cost="0" experiencePoints="5000"/&gt;
  &lt;/todo&gt;
  </code></pre>
  
  <p>And the XSD schema for it is:</p>
  
  <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;xs:complexType name="todo"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:choice maxOccurs="unbounded"&gt;
                  &lt;xs:element name="doLaundry" type="doLaundry" /&gt;
                  &lt;xs:element name="washCar" type="washCar" /&gt;
                  &lt;xs:element name="tidyBedroom" type="tidyBedroom" /&gt;
              &lt;/xs:choice&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="doLaundry"&gt;
          &lt;xs:attribute name="cost" type="xs:int" /&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="washCar"&gt;
          &lt;xs:attribute name="cost" type="xs:int" /&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="tidyBedroom"&gt;
          &lt;xs:attribute name="cost" type="xs:int" /&gt;
          &lt;xs:attribute name="experiencePoints" type="xs:int" /&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>And when I process this schema through JAXB I get a class with a method like this:</p>
  
  <pre><code>public class Todo {
  
      public List&lt;Object&gt; getDoLaundryOrWashCarOrTidyBedroom() {
          ...
      }
  
  }
  </code></pre>
  
  <p>Ideally, what I would like is a way to define a generic base type that all the other XSD types extend. The Jaxb classes generated from the XSD schema should have a method to return a list of generic tasks. This would make it very easy to add new tasks to the todo list:</p>
  
  <pre><code>public class Todo {
  
      public List&lt;Task&gt; getTasks() {
          ...
      }
  
  }
  
  public abstract class Task {
      public int getCost() {
          ...
      }
  }
  
  public class TidyBedroom extends Task {
      public int getExperiencePoints() {
          ...
      }
  }
  </code></pre>
  
  <p>What should the XSD schema look like in order to generate the above Java classes?</p>