Rhett,

Thanks for pointing me to that thread on the list.  Glad I'm not off base.

My real motivation for this is to use the dynamically generated (ie runtime) mapping 
file and specifying the default value in the <bind-xml> tag.

If you could point me to some rational starting places in the code, I'd be happy to 
give it a shot.

Kevin

-----Original Message-----
From: Rhett Sutphin [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 15, 2004 8:58 AM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] problem with marshal behavior of default
attribute values


Hi Kevin,

Comments below.

Ruland, Kevin S [ITS] wrote:
> I'm working with a document with optional attributes with defined 
> default values.  Previously I posted a question on this topic when using 
> a custom mapping file and dynamically generated mappings.  The 
> suggestion was to use the source generator.  Indeed the source generator 
> has better behavior but is still slightly bugged because it will 
> unmarshal attributes which have the default value.
> 
> What I expect to happen is if the object's attribute has the default 
> value, I would not expect it to be unmarshalled.  What I find though is 
> the marshaller will print the attribute as long as it has been set.  
> Technically this is not incorrect behavior because the resulting 
> document is valid.  However, it is counter intuitive.
> 
> I am using this extremly simple schema for my example:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema
>    xmlns:xsd="http://www.w3.org/2001/XMLSchema";
>    elementFormDefault="qualified">
> 
> <xsd:element name="AnElement">
>   <xsd:complexType>
>     <xsd:attribute name="name" type="xsd:string" use="required"/>
>     <xsd:attribute name="default-true" type="xsd:boolean" default="true"/>
>     <xsd:attribute name="default-false" type="xsd:boolean" 
> default="false"/>
>  </xsd:complexType>
> </xsd:element>
> 
> </xsd:schema>
> 
> With the original source document of:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <AnElement name="tuesday" default-true="false"/>
> 
> My simple little Main program, unmarshals this, then sets "default-true" 
> to "true" and marshalls it.
> 
> I get:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <AnElement name="tuesday" default-true="true"/>
> 
> What I'm asking is, are my expectations unrealisitic?  What's the 
> complexity of trying to put the default value as specified in the schema 
> in the FieldDescriptor or FieldHandler and using that to both initialize 
> the object (prior to unmarshalling) and in the 'hasXXX()' methods?

Your expectations are fine -- it wouldn't be terribly hard to achieve the effect you 
desire -- it's just that no one has volunteered to do it.  There was a thread about 
this a while back in which some implementation alternatives were discussed: 
http://www.mail-archive.com/[EMAIL PROTECTED]/msg14065.html .  If you want to give it 
a shot, I'm sure there are others who'd be interested.

Rhett Sutphin

----------------------------------------------------------- 
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