Hi Gilad,

Does the same problem occur when you generate the source using the type-centric approach?

http://castor.codehaus.org/sourcegen.html#The-'type'-method

--Keith

Gilad Haimov wrote:

 Hi all,

We use Castor to bind XML configuration data to our Java app.
Our XML data contains an 'inherited' element, i.e. an element which is defined, in schema, to be of one of several types, all inherited ('extension's) of a single base-type:


XML Schema definition:
======================
   -- definition of  the base type --
   <xs:complexType name="BaseType">
       <xs:sequence>
       </xs:sequence>
   </xs:complexType>

   -- definition of  a derived type,  notice the xs:extension line --
   <xs:complexType name="DerivedType">
       <xs:complexContent>
           <xs:extension base="BaseType">
               <xs:sequence>
                   <.. more elements are declared here.../>
               </xs:sequence>
           </xs:extension>
       </xs:complexContent>
   </xs:complexType>

   -- naming a base-type element, to be used below --
   <xs:element name="myData" type="BaseType" />


   -- root element --
   <xs:element name="monitor-session">
       <xs:complexType>
           <xs:sequence>
                ......
               -- ref to base type --
               <xs:element ref="myData" />
           </xs:sequence>
       </xs:complexType>
   </xs:element>



XML file definition:
======================
<?xml version="1.0" encoding="ISO-8859-1"?>

<monitor-session
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xsi:noNamespaceSchemaLocation="../watchDog.xsd">

  ......

    -- $$$ defining myData as accepting derived-type data
   <myData xsi:type="DerivedType">
   </myData>

  .........
</monitor-session>



And, the problem:
======================
Running Unmarshaller.unmarshal(..) on this file results in a ClassCastException. The reason: the Castor generated descriptor file attempts to cast a DerivedType obj, from $$$,
to a myData class:
                target.setListener( (myData) value);
where value is of type  DerivedType (all Castor-generated classes).

DerivedType class is derived from BaseType, as should be.
But, since for some reason myData class is also derived BaseType (as opposted to an instance of that class), there's not much chance for the above cast to succeed,
hence the ClassCastException.


Any ideas on how to get it right?


Thanks,
Gilad

-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------




-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to