Thanks. Using _lang as the field name in combination with specifying the set-method and get-method solved the problem.

<mapping>
<class name="com.dcx.i18n.xml.Tuv" auto-complete="true">
<field name="_lang" required="true" get-method="getLang" set-method="setLang">
<bind-xml name="xml:lang" node="attribute"/>
</field>
</class>
</mapping>


--
Joe Banks
mailto:[EMAIL PROTECTED]
Beauty is the eye of the beerholder.





From: Keith Visco <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] problem with auto-complete attribute in mapping
Date: Tue, 10 Dec 2002 14:54:46 -0600



Hi Joe,

When using auto-complete in conjunction you'll need to make sure you
specifiy the proper field name. Look at the generated descriptor to make
sure you use the proper field name so that the auto-complete code
matches it properly.

For example, instead of "lang" you may need to use "_lang"

--Keith


Joe Banks wrote:
>
> I have used Castor to generate code for the marshalling framework based on
> an xml schema. I want to use the default marshalling behavoir except for
> one attribute in one element. So I created a mapping for the class and set
> the auto-complete attribute to true, then specified a field mapping for that
> attribute. I would expect that when I marshalled the object that it would
> use the default behavoir for all fields except for the one I specified a
> mapping for, in which case the mapping would override that behavior.
> Instead, when I marshalled the object I got _both_ behaviors (two attributes
> appeared in the xml - one with the attribute name I specified with
> bind-xml,the other with the default attribute name - both had the same
> value.
>
> Here's the relevant portion of the scheme:
>
> ...
> <xs:element name="tuv">
> <xs:complexType>
> ...
> <xs:attribute name="xml:lang" type="xs:string" use="required"/>
> </xs:complexType>
> </xs:element>
>
> ...
>
> The class is generated with the following:
>
> public class Tuv implements java.io.Serializable {
>
> private java.lang.String _lang;
>
> ...
>
> public java.lang.String getLang()
> {
> return this._lang;
> } //-- java.lang.String getLang()
>
> public void setLang(java.lang.String lang)
> {
> this._lang = lang;
> } //-- void setLang(java.lang.String)
>
> ...
>
> So I specify the following mapping:
>
> <mapping>
> <class name="com.dcx.i18n.xml.Tuv" auto-complete="true">
> <field name="lang" required="true">
> <bind-xml name="xml:lang" node="attribute"/>
> </field>
> </class>
> </mapping>
>
> I then create a Tuv object, set the _lang property and marshall:
> ...
> Tuv tuv = new Tuv();
> tuv.setLang("EN");
>
> Writer wr = new BufferedWriter(new FileWriter(_path));
> Mapping mapping = new Mapping();
> URL url = ClassLoader.getSystemResource(mappingFile);
> mapping.loadMapping(url);
> Marshaller marshaller = new Marshaller(wr);
> marshaller.setMapping(mapping);
> marshaller.marshal(tuv);
> ...
>
> What I get is the following:
>
> ...
> <tuv xml:lang="EN" lang="EN"></tuv>
> ...
>
> I would expect:
> ...
> <tuv xml:lang="EN"></tuv>
> ...
>
> Any thoughts? I'm out of ideas here.
>
> --
> Joe Banks
>
> _________________________________________________________________
> Help STOP SPAM with the new MSN 8 and get 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
> -----------------------------------------------------------
> 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

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail

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

Reply via email to