title: JAXB Generated Classes from xsd file
body: <p>I have a xsd file that im generating into Classes with xjc / JAXB.</p>
  
  <p>Now i want to use the  method <code>getOwne</code>r(function attached), and from this object i want to get the name of the owner..<br>
  The main problem that this method return an Object Class and not a Customer Class.
  there is a way to achieve that?</p>
  
  <p><strong>Notice:</strong> this is a ref by attribute</p>
  
  <p>Thanks!</p>
  
  <p>Here is what i tried:</p>
  
  <pre><code>
  public class Demo {
  
      public static void main(String[] args) throws Exception {
          JAXBContext jc = JAXBContext.newInstance(Statement.class);
  
          Unmarshaller unmarshaller = jc.createUnmarshaller();
          File xml = new File("src/Data.xml");
          Statement items =  (Statement)unmarshaller.unmarshal(xml);
          List&lt;Order&gt; orders = items.getOrders().getOrder();
          for(Order order : orders) {
              System.out.println(order.getOwner());
          }
  }
  </code></pre>
  
  <p>Data.xml:</p>
  
  <pre><code>&lt;statement&gt;
    &lt;customer number="E1" name="Tom" type="normal"/&gt;
    &lt;customer number="E2" name="Tomer" type="normal"/&gt;
    &lt;orders count="200"&gt;
      &lt;!--1 or more repetitions:--&gt;
      &lt;order number="string" owner="E1" total="1000.00"/&gt;
      &lt;order number="string2" owner="E2" total="1020.00"/&gt;
    &lt;/orders&gt;
  &lt;/statement&gt;
  
  </code></pre>
  
  <p>Schema.xsd:</p>
  
  <pre><code>    &lt;?xml version="1.0" ?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
             targetNamespace="http://www.java2s.com/statement"
             xmlns="http://www.java2s.com/statement"&gt;
      &lt;xs:element name="statement"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element ref="customer" /&gt;
                  &lt;xs:element ref="orders" /&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  
      &lt;xs:element name="customer"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence /&gt;
              &lt;xs:attribute name="number" type="xs:ID" /&gt;
              &lt;xs:attribute name="name"   type="xs:string" /&gt;
              &lt;xs:attribute name="type"   type="xs:string"
                            use="optional" default="normal" /&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  
      &lt;xs:element name="orders"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element ref="order" maxOccurs="unbounded" /&gt;
              &lt;/xs:sequence&gt;
              &lt;xs:attribute name="count" type="xs:nonNegativeInteger" /&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  
      &lt;xs:element name="order"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
              &lt;/xs:sequence&gt;
              &lt;xs:attribute name="number" type="xs:ID" /&gt;
              &lt;xs:attribute name="owner"  type="xs:IDREF" /&gt;
              &lt;xs:attribute name="total"  type="xs:decimal" /&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>info in Order.java:</p>
  
  <pre><code>    @XmlAttribute(name = "owner")
      @XmlIDREF
      @XmlSchemaType(name = "IDREF")
      protected Object owner;
  ...
  
  public Object getOwner() {
          return owner;
      }
  </code></pre>