Roland-
I'm glad to see you found a solution (I've been away from my e-mail so
I'm catching up on past conversations now), but FYI I have mapped nested
HashMaps using Castor in the past. It looks a little ugly, but here is
an example mapping:
<field name="thresholds" collection="map">
<bind-xml name="threshold" location="detection-thresholds">
<class name="org.exolab.castor.mapping.MapItem">
<field name="key" type="string">
<bind-xml name="feature" node="attribute" />
</field>
<field name="value" type="org.exolab.castor.mapping.MapItem"
collection="hashtable">
<bind-xml name="thresh-item">
<class name="org.exolab.castor.mapping.MapItem">
<field name="key" type="string">
<bind-xml name="type" node="attribute" />
</field>
<field name="value">
<bind-xml name="value" node="attribute" />
</field>
</class>
</bind-xml>
</field>
</class>
</bind-xml>
</field>
Going back to it, I noticed that I declared the inner map as a HashTable
rather than a HashMap, and I think I did that because I was getting some
ClassCastExceptions or something. I don't remember all the issues now,
but I have been using this mapping for a while now, so I know it works.
Stephen
[EMAIL PROTECTED] wrote:
Hi Alok,
thanks for your help.
I did not get it to work with the HashSets inside the Hashtable.
But I defined a new class which has a String variable and a Hashset
variable. This way I can easily build the HashTable after marshalling.
Greetings,
Roland
PS: Happy new year.
-----Ursprüngliche Nachricht-----
Von: Alok Kumar(RPM) [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 29. Dezember 2005 06:38
An: [email protected]
Betreff: RE: [castor-user] Defining a Hashtable in the XML mapping
Hi,
You define LinkedHashMap as java.util.map and LinkedList as collection in
your mapping file. Then it will get marshalled.
While unmarshalling it will return map and collection, typecast into
LinkedHashMap and LinkedList respectively.
Regards
Alok Kumar
From: Xinjun Chen [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 29, 2005 11:04 AM
To: [email protected]
Subject: Re: [castor-user] Defining a Hashtable in the XML mapping
Hi Roland,
I have the same problem of marshalling and unmarshalling Hashtable, have you
successfully done it?
Regards,
Xinjun
On 12/23/05, Ralf Joachim <[EMAIL PROTECTED]> wrote:
Hi Roland,
I'm not one of the Castor XML experts but as far as I know this should
be possible. I would suggest you to start with marshalling a sample
object first without mapping and then by using a mapping that you modify
step by step until your xml document looks like you want it to. I would
expect the unmarshalling of this document to work also with the same
mapping then.
Having said that I guess your mapping should not be to far away of what
it should be.
Regards
Ralf
Castor JDO, committer
[EMAIL PROTECTED] schrieb:
Hi all,
I want to use Castor XML to fill a Hashtable in my class from an XML file.
This Hashtable should map Strings to Hashsets which contain also Strings.
Unfortunately, I could not find an example for this.
Here is what I currently have in the mapping file:
<field name="myHashtable" collection="hashtable">
<bind-xml name="myHashtable" node="element">
<class name="org.exolab.castor.mapping.MapItem">
<field name="key" type="java.lang.String">
<bind-xml name="key" node="element"/>
</field>
<field name="value" type="java.util.HashSet">
<bind-xml name="value" node="element"/>
</field>
</class>
</bind-xml>
</field>
And this is in the source XML:
<myHashtable xsi:type="java: java.lang.String"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<key key="mykey" xsi:type="java:java.util.Hashset "
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<value xsi:type="java:java.lang.String"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance">myvalue</value>
</key>
</myHashtable>
Any ideas how this code should look like? Is this even possible with
Castor
XML?
Thanks in advance for your help.
Greetings,
Roland
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
--
Syscon Ingenieurbüro für
Meß- und Datentechnik GmbH
Ralf Joachim
Raiffeisenstraße 11
D-72127 Kusterdingen
Germany
Tel. +49 7071 3690 52
Mobil: +49 173 9630135
Fax +49 7071 3690 98
Email: [EMAIL PROTECTED]
Web: www.syscon-world.de
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------