Hi Frank,

To be more compliant with XML Schema, Castor uses the Schema type by
default. Currently the only way to over-ride this is to remove the
Schema type from the generated descriptors. If the Schema type is null,
Castor will use the java class name. So you need to modify the generated
descriptors, find the appropriate field descriptors and set the schema
type to null.

Since overriding descriptors manually is a pain and would need to be
done each time you generate the source code, the approach I usually take
when faced with this is to create a custom ClassDescriptorResolver (it
could extend Castor's default ClassDescriptorResolverImpl) that upon
loading a class descriptor will automatically handle the changes I want
to make.

--Keith

Frank Buchli wrote:
> 
> Hi
> 
> We are wondering, how to tell a Marshaller to set a custom xsi:type
> (e.g. xsi:type=java:com.xxx.yyy) to a certain field.
> 
> Background:
> ----------
> Our project consists of several modules. Several modules have different
> xml-schemas defined, but all of them share a basic structure. That's the
> reason why why define in one module (called base-module) this basic
> structure in a schema. This basic shema is then included from the other
> modules.
> We let castor generate from the schema all our classes. The classes from
> the base-module are generated in the base-module. The rest of the
> classes are generated in the other modules (without the basic classes,
> those have to be deleted with a maven post-goal, otherwise they are
> duplicated).
> 
> Our basic structure:
> 
> Envelope
> |
> +--Request
> |
> +--Response
> 
> Request and Response are abstract types.
> 
> In a specific module a Request can then be e.g. XRequest or YRequest;
> and a Response can be e.g. SResponse or TResponse.
> 
> Question
> --------
> We want to tell the Marshaller that he sets the xsi:type of a certain
> field to the concrete java class of the specific module.
> 
> E.g.
> The field "request" of "Envelope" should be the
> xsi:type="java:com.xxx.module1.XRequest"
> (instead of xsi:type="Request" which takes the java class
> com.xxx.basicmodule.Request)
> 
> Our "vision"
> ------------
> 
> Envelope envelope = new Envelope();  //com.xxx.basicmodule.Envelope
> Marshaller marshaller = new Marshaller(outWriter);
> marshaller.setRootElement(ENVELOPE_TAG);   //ENVELOPE_TAG = "envelope";
> >>>marshaller.setXSITypeForElement("request","java:com.xxx.module1.XRequest");
> marshaller.marshal(envelope);
> 
> Any idea how this could work ?
> 
> Kind regards
> 
> Frank Buchli
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

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

Reply via email to