Java Mailing List Archive

http://www.junlu.com/

Home » user.castor »

[castor-user] Specific problem with using castor

michael schabus

2010-03-26

Replies: Find Java Web Hosting

Author LoginPost Reply
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


©2008 junlu.com - Jax Systems, LLC, U.S.A.