David,
what happens if you - when marshalling things out - disable production
of xsi:type instructions ?
Werner
david_geary wrote:
> I have a Java class containing a hash map field (that represents generic
> data). The values in the map could be common types such as string, date,
> boolean, integer etc.
>
> I also want to define an XML schema (ie the schema and Java are pre-existing
> - im trying to write a mapping file between the two).
>
> The java class looks like this
>
> public class ExtensionDataSet
> {
> private int mId;
> private String mKey;
> private HashMap<String, Object> mDataMap;
>
> public int getId()
> {return mId;}
> public void setId(int id)
> {mId = id;}
> public String getKey()
> {return mKey;}
> public void setKey(String key)
> {mKey = key;}
> public HashMap<String, Object> getDataMap()
> {return mDataMap;}
> public void setDataMap(HashMap<String, Object> dataMap)
> {mDataMap = dataMap;}
> }
>
> Using this mapping file
>
> <mapping>
> <class name="com.abc.ExtensionDataSet">
> <map-to xml="extension" ns-uri="http://www.abc.com/schemas/core"/>
>
> <field name="id" type="int">
> <bind-xml name="id" node="attribute"/>
> </field>
>
> <field name="key" type="string">
> <bind-xml name="key" node="attribute"/>
> </field>
>
> <field name="dataMap" collection="map">
> <bind-xml name="extension-field" node="element" />
> </field>
> </class>
>
> <class name="org.exolab.castor.mapping.MapItem">
> <map-to xml="extension-field"
> ns-uri="http://www.abc.com/schemas/core"/>
>
> <field name="key" type="other">
> <bind-xml name="key" node="attribute"/>
> </field>
>
> <field name="value" type="string">
> <bind-xml node="element"/>
> </field>
> </class>
>
>
> </mapping>
>
> I can get a castor to marshal the class to of the form:
>
> <core:extension xmlns:core="http://www.abc.com/ecm/schemas/core" id="5"
> key="testkey">
> <core:extension-field key="key1">
> <core:value>value1</core:value>
> </core:extension-field>
> <core:extension-field key="key3">
> <core:value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="date">2008-12-17T18:18:33.066Z</core:value>
> </core:extension-field>
> <core:extension-field key="key2">
> <core:value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="java:java.lang.Integer">1</core:value>
> </core:extension-field></core:extension>
>
> However this isn't generic enough for our needs - we don't want any mention
> of java in the generated XML (the point of going to XML is to be
> implementation language neutral - see
> http://jira.codehaus.org/browse/CASTOR-769 )
>
> My question is how to do this without references to the java types but
> maintaining the type information in the XML. I can see two ways to do this
>
> 1) Use XML types in the xsi:types part of the generated XML above. Castor
> already has standard mapping between XML and Java types so is it possible to
> set a flag in castor to tell it not to refer to java in the XML and use its
> standard mapping instead? ie like it seems to do for date?
>
> 2) Use a choice construct in the XSD we will write that allows values in the
> XML document to be either <string-value>, <boolean-value> etc and therefore
> the types would be enforced in the XML schema for these - ie we would want
> to generate XML of the form:
>
> <core:extension xmlns:core="http://www.abc.com/ecm/schemas/core" id="5"
> key="testkey">
> <core:extension-field key="key1">
> <core:string-value>value1</core:string-value>
> </core:extension-field>
> <core:extension-field key="key3">
> <core:date-value>2008-12-17T18:18:33.066Z</core:date-value>
> </core:extension-field>
> <core:extension-field key="key2">
> <core:integer-value>1</core:integer-value>
> </core:extension-field></core:extension>
>
> I actually prefer the second option here and am wondering is there ANY way
> to do this in Castor - ie the <bind-xml name> part of the mapping for the
> values in the hash map would be different depending on the type of the value
> object.
>
> If this isn't possible right now - are there any obvious extension points i
> should be looking at in castor? All the logic seems to be in the Marshaller
> and Unmarshaller classes?
>
> Thanks for any help
>
> Dave
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email