Hi,

I use the castor source generator to create Java classes and
descriptors from a XML schema file.

Is there a way to automatically produce a mapping file, the generated
classes correspond to? Is it possible to "override" only the binding
of the XML element names to Java classes in this default mapping? This
would be great if an application wants to extend the generated
classes.


Best regards,   Bernhard.



A more detailed example follows:

In my application, I now would like to extend the generated data
classes to add application specific functionality. To get these
application specific classes instantiated during the unmarshaling
process (instead of their generated super classes), I now have to tell
the changed mapping to the marshaling framework.

Assume, I have a schema, that describes documents like the following:

   <a>
      <b c="3">first</b>
      <b>second</b>
      <b c="27">third</b>
   </a>

The corresponding schema is e.g. this one:

   <?xml version="1.0"?>
   <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
               elementFormDefault="qualified">

      <xsd:complexType name="T_a">
         <xsd:sequence>
            <xsd:element ref="b" maxOccurs="unbounded" />
         </xsd:sequence>
      </xsd:complexType>

      <xsd:complexType name="T_b">
         <xsd:simpleContent>
            <xsd:extension base="xsd:string">
               <xsd:attribute name="c" type="xsd:int" 
                              use="optional" default="0" />
            </xsd:extension>
         </xsd:simpleContent>
      </xsd:complexType>

      <xsd:element name="a" type="T_a" />
      <xsd:element name="b" type="T_b" />
   </xsd:schema>

The castor source code generator generates a bunch of
classes from this schema, A and B among them.

I now would like to extend A and B to AExtended and BExtended in the
following way:

   public class AExtended extends A {
       public AExtended() {}

       public void addB(B b) {
           super.addB(b);
           BExtended _b = (BExtended) b;
           // add some functionality here
           // ...
       }
   }

   public class BExtended extends B {
       public BExtended() {}
       // add some functionallity here
       // ...
   }

I really want to rely on the default mapping except for the
fact, that the name of the classes should be changed to AExtended and
BExtended. I tried the following mapping file:

   <?xml version="1.0"?>
   <!DOCTYPE mapping PUBLIC 
       "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN"
       "http://Castor.exolab.org/mapping.dtd";>
   <mapping>
       <class name="AExtended" auto-complete="true">
           <map-to xml="a"/>
       </class>

       <class name="BExtended" auto-complete="true">
           <map-to xml="b"/>
       </class>
   </mapping>

This does only part of the job: Instead of A, AExtended is
instantiated. But for the <b> elements, objects of class B get
instantiated further on (and the program crashes in method
AExtended.addB(B)).

The behavior changes if I explicitly declare the field b of class A to
be of type BExtended:

   <?xml version="1.0"?>
   <!DOCTYPE mapping PUBLIC 
       "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN"
       "http://Castor.exolab.org/mapping.dtd";>
   <mapping>
       <class name="AExtended" auto-complete="true">
           <map-to xml="a"/>

           <field name="b"
                  type="BExtended"
                  collection="array">
               <bind-xml name="b"/>
           </field>
       </class>

       <class name="BExtended" auto-complete="true">
           <map-to xml="b"/>
       </class>
   </mapping>

But even with this declaration, the result is not as
expected, because I do not get the default mapping from the schema,
but the default mapping for the generated classes. The default mapping
for the generated classes produces XML that does not conform to
the original schema, because all internal properties also get
marshaled.

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to