Title: Instantiating extension types using XML mapping

I am having trouble instantiating extension types using XML mapping. Castor is not able to instantiate extended types. Here's my schema:

  <xsd:complexType name="MessageType" abstract="true">
  </xsd:complexType>

  <xsd:complexType name="CreateMeetingMessageType">
    <xsd:complexContent>
      <xsd:extension base="MessageType">
        <xsd:sequence>
          <xsd:element name="meeting" type="MeetingType"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  ...

Here's my mapping file:

  <class name="Message">
    <map-to xml="message" ns-uri="my-schema"/>
  </class>

  <class name="CreateMeetingMessage" extends="Message">
    <map-to xml="message" ns-uri="my-schema"/>
    <field name="meeting" type="Meeting">
      <bind-xml name="meeting"/>
    </field>
  </class>
  ...

Here's my XML instance:

<message
  xmlns="my-schema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:type="CreateMeetingMessageType">
  <meeting>
    ...
  </meeting>
</message>

When I try to unmarshall this instance using Castor, I get the following exception:

 org.xml.sax.SAXException: unable to instantiate org.framework.message.Message;
     java.lang.InstantiationException: org.framework.message.Message
     at org.exolab.castor.xml.UnmarshalHandler.startElement(Unknown Source)
     at org.exolab.castor.xml.util.DOMEventProducer.process(Unknown Source)
     at org.exolab.castor.xml.util.DOMEventProducer.process(Unknown Source)
     at org.exolab.castor.xml.util.DOMEventProducer.start(Unknown Source)
     at org.exolab.castor.xml.Unmarshaller.unmarshal(Unknown Source)
     at org.exolab.castor.xml.Unmarshaller.unmarshal(Unknown Source)
     at Test.main(Client.java:81)

I would appreciate any ideas to overcome this problem.

Thanks.
Naresh

Reply via email to