I've been playing with castor, and coming from the position that castor is
for databinding have been under the assumption that castor would be
attempting to generate the most optimal xml possible. I have found two
instances so far where I believe this is not the case. I am using the
source generator, so I believe both these issues could be theoretically
solved within either castor code, or castor generated code.
1. In my schema, I have defined an attribute:
<xs:attribute name="idStyle" type="xs:int" default="0"/>
In castorgen, this turns into:
private int _idStyle = 0;
/**
* keeps track of state for field: _idStyle
**/
private boolean _has_idStyle;
public void setIdStyle(int idStyle)
{
this._idStyle = idStyle;
this._has_idStyle = true;
} //-- void setIdStyle(int)
By this method, if I make the following call:
foo.setIdStyle( 0 );
my marshalled xml will contain the attribute set to its default
value.
I can envision a tweak to the generated code along the following
lines:
private final static int _Default_idStyle = 0; // from the schema
default value.
private int _idStyle = _Default_idStyle;
public void setIdStyle(int idStyle)
{
this._idStyle = idStyle;
if( _Default_idStyle != this._idStyle ) {
this._has_idStyle = true;
}
else {
deleteIdStyle();
}
} //-- void setIdStyle(int)
This might get tricky to get working for complex object attributes
(you might need to implement the equals operator for non-native
types
to get meaningful results) but I believe the worst that could happen
would be that a default value would still be serialized.
2. In my schema, I have the following type:
<xs:element name="TableCollection" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element ref="Table" minOccurs="1"
maxOccurs="5"/>
</xs:sequence>
</xs:complexType>
</xs:element>
In castor, if I create a TableCollection, and add it to my model
(as part of initialization of a new object), marshalling the
collection
that is empty produces a <TableCollection/> tag, which is invalid
according to the schema. Additionally, the tag is unnecessary
because
its minOccurs is 0. I have worked around it, by creating the
collections
on demand, and by deleting collections that have 0 size before
marshalling,
but it seems that it wouldn't be too difficult to put code in the
marshalling framework that would not write an optional element in
cases
where it has no children. Is this something that has just never
been
done, or is there a good reason relating to another part of the
marshalling
framework, of why castor behaves this way.
Finally, has there ever been talk of having the castor framework marshall
directly into a mapped terse, or compressed xml? I.E. castor marshals to
xml, and then compresses the XML (or has standard compression methods built
into it.) I can understand that this might really be outside of the
responsibilites of castor, but I can imagine that a large number of users
(primary in the data storage realm) would be interested in such a feature,
either integrated or available as a separate component that easily
integrates in a general manner with the castor framework.
Thanks,
Nate Pitzer
Software Developer
J.D. Edwards & Company
One Technology Way
Denver, CO 80237
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev