Hello Ralf!
Thanks for that hint, did not find that tutorial during my searches.
I gave it a quick try, cause I'm still at work and this is one of my
private projects :)
I changed my mapping accordingly and also added a test to marshal a
PlayerList.
<mapping>
<class name="PlayerList">
<map-to xml="stats" />
<field name="players" type="Player" collection="array">
<bind-xml name="player_stats" />
</field>
</class>
<class name="org.fadev.oms.hons.dl.player.dao.Player">
<field name="id" type="int">
<bind-xml name="aid" node="attribute" />
</field>
<field name="stats" collection="map">
<bind-xml name="stat" />
<class name="org.exolab.castor.mapping.MapItem">
<field name="key" type="java.lang.String">
<bind-xml name="name" node="attribute"
/>
</field>
<field name="value" type="java.lang.String">
<bind-xml name="stat" node="element"/>
</field>
</class>
</field>
</class>
</mapping>
The result of the marshalling is:
<?xml version="1.0" encoding="UTF-8"?>
<stats>
<player_stats aid="123456">
<stat><key>acc_pub_skill</key><value>1500</value></stat>
<stat><key>nickname</key><value>Tester1</value></stat>
</player_stats>
</stats>
which is not what I expect and during unmarshalling I get the
following Exception:
...
Caused by: org.xml.sax.SAXException: Illegal Text data found as child of: stat
value: "Tester1"
...
I have currently no clue what is happening there, but maybe I
misunderstood the node attribute in the mapping or something else ...
Maybe anyone has another hint for me?
Btw: Is there a Overview-Page for How-Tos on the castor page? At least
I did not find one yet.
As I wrote in my first mail, the HashMap would just be acceptable but
it is definitely not what I like: the best solution would be to map a
<stat name='X'>...</stat> to an attribute X ... dunno if this is
possible at all.
I'm not a friend of generated code (eg JAXB) and therefore the mapping
offered by Castor would be best-practice for me.
Quoting Ralf Joachim <[email protected]>:
Hello Micheal,
have you already had a look at:
http://www.castor.org/how-to-map-a-hashtable.html
Regards
Ralf
[email protected] schrieb:
Hello Folks!
I managed to get Castor 1.3.1 running with Spring 3.0.1.RELEASE-A.
So far so good.
Finally I tried to rewrite my running very simple example to
fulfill my needs.
There is a game (still in Beta) called Heroes of Newerth witch
offers a simple XML interface to gain statistics via a
http-request. For my first tests I simplified the structure:
<?xml version="1.0" encoding="UTF-8" ?>
<stats>
<player_stats aid='123456'>
<stat name='nickname'>Tester1</stat>
<stat name='acc_pub_skill'>1500</stat>
</player_stats>
<player_stats aid='654321'>
<stat name='nickname'>Tester2</stat>
<stat name='acc_pub_skill'>1600</stat>
</player_stats>
</stats>
In the full version there are at least 40 more statistic values available.
So I set up 2 classes representing the content of this XML:
public class PlayerList {
private Player[] players;
public PlayerList() {
}
}
import java.util.HashMap;
public class Player {
private int id;
private String name;
private int pubSkill;
private HashMap<String, String> stats;
public Player() {
}
}
There I want to keep it simple I removed the setter and getter
methods in this mail (not in the code :))
I really tried nearly everything to get this working, spent hours
on the net to find a hint or something to help me out.
I also tried to fill the tons of <stat> tags to the HashMap with
the result that I had a map like the following:
playerList:
[ id: 123456, stats: [ {Tester1/Tester1}, {1500:1500} ] ]
[ id: 654321, stats: [ {Tester2/Tester2}, {1600:1600} ] ]
So that was also not very helpful at all, at least I need to have
the name of the stat and the value in the map, would not be the
best solution, but it would work for me.
I deleted the mapping.xml for this result, my bad :(
Then I tried to get the data directly to the attribute name:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.org/mapping.dtd">
<mapping>
<class name="PlayerList">
<map-to xml="stats" />
<field name="players" type="Player" collection="array">
<bind-xml name="player_stats" />
</field>
</class>
<class name="org.fadev.oms.hons.dl.player.dao.Player">
<field name="id" type="int">
<bind-xml name="aid" node="attribute" />
</field>
<field name="name" type="java.lang.String">
<bind-xml name="nickname" node="attribute"/>
</field>
<field name="pubSkill" type="int">
<bind-xml name="acc_pub_skill" node="element"/>
</field>
</class>
</mapping>
There I get the following result:
playerList:
[ id: 123456, name: null, pubSkill: 0, stats: null ]
[ id: 654321, name: null, pubSkill: 0, stats: null ]
Has anyone an idea how to get that XML format settled to Objects
with Castor?
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
--
Syscon Ingenieurbüro für Meß- und Datentechnik GmbH
Ralf Joachim
Raiffeisenstraße 11
72127 Kusterdingen
Germany
Tel. +49 7071 3690 52
Mobil: +49 173 9630135
Fax +49 7071 3690 98
Internet: www.syscon.eu
E-Mail: [email protected]
Sitz der Gesellschaft: D-72127 Kusterdingen
Registereintrag: Amtsgericht Stuttgart, HRB 382295
Geschäftsleitung: Jens Joachim, Ralf Joachim
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email