1.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Fri Sep 04 21:14:33 2009 +0200
1.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Sat Sep 05 15:40:39 2009 +0200
1.3 @@ -36,6 +36,7 @@
1.4 import javax.xml.bind.annotation.XmlAccessorType;
1.5 import javax.xml.bind.annotation.XmlAttribute;
1.6 import javax.xml.bind.annotation.XmlElement;
1.7 +import javax.xml.bind.annotation.XmlElements;
1.8 import javax.xml.bind.annotation.XmlRootElement;
1.9 import javax.xml.bind.annotation.adapters.XmlAdapter;
1.10 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
1.11 @@ -114,27 +115,44 @@
1.12 return moves;
1.13 }
1.14
1.15 - private static final class MoveAdapter extends XmlAdapter<String[],List<Move>> {
1.16 + @XmlAccessorType(XmlAccessType.FIELD)
1.17 + private static final class MoveTmp {
1.18 + @XmlAttribute
1.19 + String move;
1.20 + @XmlAttribute
1.21 + int index;
1.22 +
1.23 + private MoveTmp() {
1.24 + }
1.25 +
1.26 + public MoveTmp(String move, int index) {
1.27 + this.move = move;
1.28 + this.index = index;
1.29 + }
1.30 + }
1.31 +
1.32 + private static final class MoveAdapter extends XmlAdapter<MoveTmp[],List<Move>> {
1.33 @Override
1.34 - public List<Move> unmarshal(String[] arr) throws Exception {
1.35 + public List<Move> unmarshal(MoveTmp[] arr) throws Exception {
1.36 List<Move> res = new ArrayList<Move>();
1.37 if (arr != null) {
1.38 - for (String v : arr) {
1.39 - res.add(Move.valueOf(v));
1.40 + for (MoveTmp v : arr) {
1.41 + res.add(Move.valueOf(v.move));
1.42 }
1.43 }
1.44 return res;
1.45 }
1.46
1.47 @Override
1.48 - public String[] marshal(List<Move> arr) throws Exception {
1.49 - List<String> res = new ArrayList<String>();
1.50 + public MoveTmp[] marshal(List<Move> arr) throws Exception {
1.51 + List<MoveTmp> res = new ArrayList<MoveTmp>();
1.52 if (arr != null) {
1.53 + int index = 0;
1.54 for (Move m : arr) {
1.55 - res.add(m.toString());
1.56 + res.add(new MoveTmp(m.toString(), ++index));
1.57 }
1.58 }
1.59 - return res.toArray(new String[0]);
1.60 + return res.toArray(new MoveTmp[0]);
1.61 }
1.62 } // end of MoveAdapter
1.63