1.1 --- a/pom.xml Sun Sep 05 22:34:43 2010 +0200
1.2 +++ b/pom.xml Sat Sep 11 17:04:51 2010 +0200
1.3 @@ -35,6 +35,7 @@
1.4 <freemarkerVersion>1.60</freemarkerVersion>
1.5 <emailerVersion>1.1</emailerVersion>
1.6 <statisticsVersion>1.8</statisticsVersion>
1.7 + <wsdorVersion>1.0</wsdorVersion>
1.8 </properties>
1.9 <modules>
1.10 <module>quoridor</module>
1.11 @@ -43,8 +44,9 @@
1.12 <module>statistics</module>
1.13 <module>freemarkerdor</module>
1.14 <module>emailer</module>
1.15 + <module>wsdor</module>
1.16 </modules>
1.17 <name>Quoridor related projects</name>
1.18 <description>Master project that agregates all quoridor related functionality.
1.19 </description>
1.20 -</project>
1.21 +</project>
1.22 \ No newline at end of file
2.1 --- a/webidor/pom.xml Sun Sep 05 22:34:43 2010 +0200
2.2 +++ b/webidor/pom.xml Sat Sep 11 17:04:51 2010 +0200
2.3 @@ -73,6 +73,11 @@
2.4 <version>${quoridorVersion}</version>
2.5 <type>jar</type>
2.6 </dependency>
2.7 + <dependency>
2.8 + <groupId>${project.groupId}</groupId>
2.9 + <artifactId>wsdor</artifactId>
2.10 + <version>1.0</version>
2.11 + </dependency>
2.12 </dependencies>
2.13 <build>
2.14 <plugins>
3.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/CommentedMove.java Sun Sep 05 22:34:43 2010 +0200
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,104 +0,0 @@
3.4 -package cz.xelfi.quoridor.webidor;
3.5 -
3.6 -import cz.xelfi.quoridor.IllegalPositionException;
3.7 -import cz.xelfi.quoridor.Move;
3.8 -import java.util.ArrayList;
3.9 -import java.util.List;
3.10 -import javax.xml.bind.annotation.XmlAttribute;
3.11 -import javax.xml.bind.annotation.XmlElement;
3.12 -
3.13 -public final class CommentedMove {
3.14 - Move move;
3.15 - int index;
3.16 - List<Note> comments;
3.17 -
3.18 - private CommentedMove() {
3.19 - super();
3.20 - }
3.21 -
3.22 - CommentedMove(Move move, int index) {
3.23 - super();
3.24 - this.move = move;
3.25 - this.index = index;
3.26 - }
3.27 -
3.28 - public Move getMove() {
3.29 - return move;
3.30 - }
3.31 -
3.32 - @XmlAttribute(name="move")
3.33 - String getMoveText() {
3.34 - return move.toString();
3.35 - }
3.36 -
3.37 - void setMoveText(String m) throws IllegalPositionException {
3.38 - move = Move.valueOf(m);
3.39 - }
3.40 -
3.41 - @XmlAttribute
3.42 - int getIndex() {
3.43 - return index;
3.44 - }
3.45 -
3.46 - void setIndex(int i) {
3.47 - index = i;
3.48 - }
3.49 -
3.50 - void addNote(Note n) {
3.51 - if (comments == null) {
3.52 - comments = new ArrayList<Note>();
3.53 - }
3.54 - comments.add(n);
3.55 - }
3.56 -
3.57 - @XmlElement(name="comment", required=false)
3.58 - public final List<Note> getComments() {
3.59 - return comments;
3.60 - }
3.61 -
3.62 - final void setComments(List<Note> l) {
3.63 - this.comments = l;
3.64 - }
3.65 -
3.66 - @Override
3.67 - public String toString() {
3.68 - StringBuilder sb = new StringBuilder();
3.69 - sb.append("Move[").append(move).append("@").append(index);
3.70 - if (comments != null) {
3.71 - sb.append(", ");
3.72 - sb.append(comments);
3.73 - }
3.74 - sb.append("]");
3.75 - return sb.toString();
3.76 - }
3.77 -
3.78 - @Override
3.79 - public boolean equals(Object obj) {
3.80 - if (obj == null) {
3.81 - return false;
3.82 - }
3.83 - if (getClass() != obj.getClass()) {
3.84 - return false;
3.85 - }
3.86 - final CommentedMove other = (CommentedMove) obj;
3.87 - if (this.move != other.move && (this.move == null || !this.move.equals(other.move))) {
3.88 - return false;
3.89 - }
3.90 - if (this.index != other.index) {
3.91 - return false;
3.92 - }
3.93 - if (this.comments != other.comments && (this.comments == null || !this.comments.equals(other.comments))) {
3.94 - return false;
3.95 - }
3.96 - return true;
3.97 - }
3.98 -
3.99 - @Override
3.100 - public int hashCode() {
3.101 - int hash = 5;
3.102 - hash = 43 * hash + (this.move != null ? this.move.hashCode() : 0);
3.103 - hash = 43 * hash + this.index;
3.104 - hash = 43 * hash + (this.comments != null ? this.comments.hashCode() : 0);
3.105 - return hash;
3.106 - }
3.107 -}
4.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Sun Sep 05 22:34:43 2010 +0200
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,213 +0,0 @@
4.4 -/*
4.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4.6 - *
4.7 - * The contents of this file are subject to the terms of either the GNU
4.8 - * General Public License Version 2 only ("GPL") or the Common
4.9 - * Development and Distribution License("CDDL") (collectively, the
4.10 - * "License"). You may not use this file except in compliance with the
4.11 - * License. You can obtain a copy of the License at
4.12 - * http://www.netbeans.org/cddl-gplv2.html
4.13 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
4.14 - * specific language governing permissions and limitations under the
4.15 - * License. When distributing the software, include this License Header
4.16 - * Notice in each file and include the License file at
4.17 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
4.18 - * particular file as subject to the "Classpath" exception as provided
4.19 - * by Sun in the GPL Version 2 section of the License file that
4.20 - * accompanied this code. If applicable, add the following below the
4.21 - * License Header, with the fields enclosed by brackets [] replaced by
4.22 - * your own identifying information:
4.23 - * "Portions Copyrighted [year] [name of copyright owner]"
4.24 - *
4.25 - * Contributor(s):
4.26 - *
4.27 - * Portions Copyrighted 2009 Jaroslav Tulach
4.28 - */
4.29 -
4.30 -package cz.xelfi.quoridor.webidor;
4.31 -
4.32 -import cz.xelfi.quoridor.Board;
4.33 -import cz.xelfi.quoridor.IllegalPositionException;
4.34 -import cz.xelfi.quoridor.Move;
4.35 -import cz.xelfi.quoridor.Player;
4.36 -import java.util.ArrayList;
4.37 -import java.util.Date;
4.38 -import java.util.List;
4.39 -import javax.xml.bind.annotation.XmlAccessType;
4.40 -import javax.xml.bind.annotation.XmlAccessorType;
4.41 -import javax.xml.bind.annotation.XmlAttribute;
4.42 -import javax.xml.bind.annotation.XmlElement;
4.43 -import javax.xml.bind.annotation.XmlElementWrapper;
4.44 -import javax.xml.bind.annotation.XmlRootElement;
4.45 -import javax.xml.bind.annotation.adapters.XmlAdapter;
4.46 -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
4.47 -
4.48 -/**
4.49 - *
4.50 - * @author Jaroslav Tulach <jtulach@netbeans.org>
4.51 - */
4.52 -@XmlRootElement
4.53 -@XmlAccessorType(XmlAccessType.FIELD)
4.54 -public final class Game extends Object {
4.55 - @XmlElement
4.56 - private GameId id;
4.57 - @XmlElement
4.58 - @XmlJavaTypeAdapter(BoardAdapter.class)
4.59 - private Board board;
4.60 - @XmlElementWrapper(name="moves")
4.61 - @XmlElement(name="item")
4.62 - private List<CommentedMove> moves;
4.63 - private Integer move;
4.64 -
4.65 - Game() {
4.66 - }
4.67 -
4.68 - public Game(String first, String second) {
4.69 - this.id = new GameId(first, second);
4.70 - this.board = Board.empty();
4.71 - }
4.72 -
4.73 - public Game(GameId id) {
4.74 - this.id = id;
4.75 - this.board = Board.empty();
4.76 - }
4.77 -
4.78 - public GameId getId() {
4.79 - return id;
4.80 - }
4.81 -
4.82 - public Board getBoard() {
4.83 - return board;
4.84 - }
4.85 -
4.86 - @XmlAttribute
4.87 - final String getCurrentPlayer() {
4.88 - Player w = board.getWinner();
4.89 - if(w==null){
4.90 - if (board.getCurrentPlayer() == board.getPlayers().get(0)) {
4.91 - return id.getWhite();
4.92 - } else {
4.93 - return id.getBlack();
4.94 - }
4.95 - }else{
4.96 - if (w == board.getPlayers().get(0)) {
4.97 - return id.getWhite();
4.98 - } else {
4.99 - return id.getBlack();
4.100 - }
4.101 - }
4.102 - }
4.103 -
4.104 - public void apply(String player, Move m, Date when) throws IllegalPositionException {
4.105 - Player p = null;
4.106 - if (id.getWhite().equals(player)) {
4.107 - p = getBoard().getPlayers().get(0);
4.108 - } else {
4.109 - if (id.getBlack().equals(player)) {
4.110 - p = getBoard().getPlayers().get(1);
4.111 - }
4.112 - }
4.113 - if (p != getBoard().getCurrentPlayer()) {
4.114 - throw new IllegalArgumentException("Wrong player: " + player);
4.115 - }
4.116 -
4.117 - board = getBoard().apply(m);
4.118 - if (when == null) {
4.119 - when = new Date(id.getModified());
4.120 - }
4.121 - final GameStatus status = GameStatus.valueOf(board);
4.122 - id = new GameId(
4.123 - id.getId(), id.getWhite(), id.getBlack(),
4.124 - new Date(id.getStarted()), when, status,
4.125 - id.getComments(), !status.isInProgress());
4.126 - getMoves().add(new CommentedMove(m, getMoves().size() + 1));
4.127 - }
4.128 -
4.129 - public void comment(String player, String comment, Date date) {
4.130 - Note n = new Note(comment, date, player);
4.131 - id = new GameId(
4.132 - id.getId(), id.getWhite(), id.getBlack(),
4.133 - new Date(id.getStarted()), new Date(id.getModified()),
4.134 - GameStatus.valueOf(board), id.getComments() + 1, id.isFinished()
4.135 - );
4.136 - getMoves().get(getMoves().size() - 1).addNote(n);
4.137 - }
4.138 -
4.139 -
4.140 - public List<CommentedMove> getMoves() {
4.141 - if (moves == null) {
4.142 - moves = new ArrayList<CommentedMove>();
4.143 - }
4.144 - return moves;
4.145 - }
4.146 -
4.147 - @XmlAttribute
4.148 - public int getCurrentMove() {
4.149 - return move == null ? getMoves().size() : move;
4.150 - }
4.151 -
4.152 - public Game snapshot(int move) throws IllegalPositionException {
4.153 - Board b = Board.empty();
4.154 - int cnt = 0;
4.155 - for (CommentedMove m : getMoves()) {
4.156 - if (move-- <= 0) {
4.157 - break;
4.158 - }
4.159 - b = b.apply(m.getMove());
4.160 - cnt++;
4.161 - }
4.162 -
4.163 - Game g = new Game(
4.164 - new GameId(
4.165 - id.getId(), id.getWhite(), id.getBlack(),
4.166 - new Date(id.getStarted()), new Date(id.getModified()),
4.167 - GameStatus.history, id.getComments(), id.isFinished()
4.168 - )
4.169 - );
4.170 - g.board = b;
4.171 - g.move = cnt;
4.172 - g.moves = new ArrayList<CommentedMove>(getMoves());
4.173 - return g;
4.174 - }
4.175 -/*
4.176 - private static final class MoveAdapter extends XmlAdapter<CommentedMove[],List<Move>> {
4.177 - @Override
4.178 - public List<Move> unmarshal(CommentedMove[] arr) throws Exception {
4.179 - List<Move> res = new ArrayList<Move>();
4.180 - if (arr != null) {
4.181 - for (CommentedMove v : arr) {
4.182 - res.add(Move.valueOf(v.move));
4.183 - }
4.184 - }
4.185 - return res;
4.186 - }
4.187 -
4.188 - @Override
4.189 - public CommentedMove[] marshal(List<Move> arr) throws Exception {
4.190 - List<CommentedMove> res = new ArrayList<CommentedMove>();
4.191 - if (arr != null) {
4.192 - int index = 0;
4.193 - for (Move m : arr) {
4.194 - res.add(new CommentedMove(m.toString(), ++index));
4.195 - }
4.196 - }
4.197 - return res.toArray(new CommentedMove[0]);
4.198 - }
4.199 - } // end of MoveAdapter
4.200 -*/
4.201 - private static final class BoardAdapter extends XmlAdapter<String,Board> {
4.202 -
4.203 - @Override
4.204 - public Board unmarshal(String v) throws Exception {
4.205 - return v == null ? null : Board.valueOf(v);
4.206 -// return v == null ? null : new Board(v);
4.207 - }
4.208 -
4.209 - @Override
4.210 - public String marshal(Board v) throws Exception {
4.211 - return v == null ? null : v.toString();
4.212 -// return v == null ? null : Board.board2HashCode(v);
4.213 - }
4.214 -
4.215 - }
4.216 -}
5.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java Sun Sep 05 22:34:43 2010 +0200
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,136 +0,0 @@
5.4 -/*
5.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5.6 - *
5.7 - * The contents of this file are subject to the terms of either the GNU
5.8 - * General Public License Version 2 only ("GPL") or the Common
5.9 - * Development and Distribution License("CDDL") (collectively, the
5.10 - * "License"). You may not use this file except in compliance with the
5.11 - * License. You can obtain a copy of the License at
5.12 - * http://www.netbeans.org/cddl-gplv2.html
5.13 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
5.14 - * specific language governing permissions and limitations under the
5.15 - * License. When distributing the software, include this License Header
5.16 - * Notice in each file and include the License file at
5.17 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
5.18 - * particular file as subject to the "Classpath" exception as provided
5.19 - * by Sun in the GPL Version 2 section of the License file that
5.20 - * accompanied this code. If applicable, add the following below the
5.21 - * License Header, with the fields enclosed by brackets [] replaced by
5.22 - * your own identifying information:
5.23 - * "Portions Copyrighted [year] [name of copyright owner]"
5.24 - *
5.25 - * Contributor(s):
5.26 - *
5.27 - * Portions Copyrighted 2009 Jaroslav Tulach
5.28 - */
5.29 -
5.30 -package cz.xelfi.quoridor.webidor;
5.31 -
5.32 -import java.util.Comparator;
5.33 -import java.util.Date;
5.34 -import java.util.UUID;
5.35 -import javax.xml.bind.annotation.XmlAccessType;
5.36 -import javax.xml.bind.annotation.XmlAccessorType;
5.37 -import javax.xml.bind.annotation.XmlAttribute;
5.38 -import javax.xml.bind.annotation.XmlID;
5.39 -import javax.xml.bind.annotation.XmlRootElement;
5.40 -
5.41 -/** Basic identification of a game.
5.42 - *
5.43 - * @author Jaroslav Tulach <jtulach@netbeans.org>
5.44 - */
5.45 -@XmlRootElement
5.46 -@XmlAccessorType(XmlAccessType.FIELD)
5.47 -public class GameId {
5.48 - public static final Comparator<GameId> NEWEST_FIRST = new NewestFirst();
5.49 -
5.50 - @XmlAttribute
5.51 - private String white;
5.52 - @XmlAttribute
5.53 - private String black;
5.54 - @XmlAttribute
5.55 - private long started;
5.56 - @XmlAttribute
5.57 - private long modified;
5.58 - @XmlAttribute
5.59 - private GameStatus status;
5.60 - @XmlID @XmlAttribute
5.61 - private String id;
5.62 - @XmlAttribute
5.63 - private int comments;
5.64 - @XmlAttribute
5.65 - private boolean finished;
5.66 -
5.67 - GameId() {
5.68 - }
5.69 -
5.70 - public GameId(String first, String second) {
5.71 - this(first, second, new Date());
5.72 - }
5.73 - private GameId(String first, String second, Date d) {
5.74 - this(
5.75 - UUID.randomUUID().toString(),
5.76 - first, second, d, d, GameStatus.whiteMove, 0, false
5.77 - );
5.78 - }
5.79 -
5.80 - public GameId(
5.81 - String id, String first, String second,
5.82 - Date started, Date last, GameStatus result,
5.83 - int comments, boolean finished
5.84 - ) {
5.85 - this.white = first;
5.86 - this.black = second;
5.87 - this.id = id;
5.88 - this.started = started.getTime();
5.89 - this.modified = last.getTime();
5.90 - this.status = result;
5.91 - this.comments = comments;
5.92 - this.finished = finished;
5.93 - }
5.94 -
5.95 - public String getId() {
5.96 - return id;
5.97 - }
5.98 -
5.99 - public String getWhite() {
5.100 - return white;
5.101 - }
5.102 -
5.103 - public String getBlack() {
5.104 - return black;
5.105 - }
5.106 -
5.107 - public long getStarted() {
5.108 - return started;
5.109 - }
5.110 -
5.111 - public long getModified() {
5.112 - return modified;
5.113 - }
5.114 -
5.115 - public GameStatus getStatus() {
5.116 - return status;
5.117 - }
5.118 -
5.119 - public int getComments() {
5.120 - return comments;
5.121 - }
5.122 -
5.123 - public boolean isFinished() {
5.124 - return finished;
5.125 - }
5.126 -
5.127 - private static final class NewestFirst implements Comparator<GameId> {
5.128 - public int compare(GameId o1, GameId o2) {
5.129 - if (o1 == o2) {
5.130 - return 0;
5.131 - }
5.132 - long diff = o2.getModified() - o1.getModified();
5.133 - if (diff != 0) {
5.134 - return diff < 0 ? -1 : 1;
5.135 - }
5.136 - return o1.getId().compareTo(o2.getId());
5.137 - }
5.138 - }
5.139 -}
6.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameStatus.java Sun Sep 05 22:34:43 2010 +0200
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,61 +0,0 @@
6.4 -/*
6.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
6.6 - *
6.7 - * The contents of this file are subject to the terms of either the GNU
6.8 - * General Public License Version 2 only ("GPL") or the Common
6.9 - * Development and Distribution License("CDDL") (collectively, the
6.10 - * "License"). You may not use this file except in compliance with the
6.11 - * License. You can obtain a copy of the License at
6.12 - * http://www.netbeans.org/cddl-gplv2.html
6.13 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
6.14 - * specific language governing permissions and limitations under the
6.15 - * License. When distributing the software, include this License Header
6.16 - * Notice in each file and include the License file at
6.17 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
6.18 - * particular file as subject to the "Classpath" exception as provided
6.19 - * by Sun in the GPL Version 2 section of the License file that
6.20 - * accompanied this code. If applicable, add the following below the
6.21 - * License Header, with the fields enclosed by brackets [] replaced by
6.22 - * your own identifying information:
6.23 - * "Portions Copyrighted [year] [name of copyright owner]"
6.24 - *
6.25 - * Contributor(s):
6.26 - *
6.27 - * Portions Copyrighted 2009 Jaroslav Tulach
6.28 - */
6.29 -
6.30 -package cz.xelfi.quoridor.webidor;
6.31 -
6.32 -import cz.xelfi.quoridor.Board;
6.33 -
6.34 -/** Possible states of the game.
6.35 - *
6.36 - * @author Jaroslav Tulach <jtulach@netbeans.org>
6.37 - */
6.38 -public enum GameStatus {
6.39 - whiteMove,
6.40 - blackMove,
6.41 - whiteWon,
6.42 - blackWon,
6.43 - history;
6.44 -
6.45 - /** Creates appropriate status of the game based on the state
6.46 - * on the board.
6.47 - *
6.48 - * @param board the board
6.49 - * @return status describing the situation on the board
6.50 - */
6.51 - public static GameStatus valueOf(Board board) {
6.52 - if (board.getWinner() != null) {
6.53 - return board.getWinner() == board.getPlayers().get(0) ? GameStatus.whiteWon : GameStatus.blackWon;
6.54 - } else {
6.55 - return board.getCurrentPlayer() == board.getPlayers().get(0) ? GameStatus.whiteMove : GameStatus.blackMove;
6.56 - }
6.57 - }
6.58 -
6.59 - /** @return true if the game is in progress
6.60 - */
6.61 - public boolean isInProgress() {
6.62 - return this == whiteMove || this == blackMove;
6.63 - }
6.64 -}
7.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/JAXBContextResolver.java Sun Sep 05 22:34:43 2010 +0200
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,70 +0,0 @@
7.4 -/*
7.5 - *
7.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
7.7 - *
7.8 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
7.9 - *
7.10 - * The contents of this file are subject to the terms of either the GNU
7.11 - * General Public License Version 2 only ("GPL") or the Common Development
7.12 - * and Distribution License("CDDL") (collectively, the "License"). You
7.13 - * may not use this file except in compliance with the License. You can obtain
7.14 - * a copy of the License at https://jersey.dev.java.net/CDDL+GPL.html
7.15 - * or jersey/legal/LICENSE.txt. See the License for the specific
7.16 - * language governing permissions and limitations under the License.
7.17 - *
7.18 - * When distributing the software, include this License Header Notice in each
7.19 - * file and include the License file at jersey/legal/LICENSE.txt.
7.20 - * Sun designates this particular file as subject to the "Classpath" exception
7.21 - * as provided by Sun in the GPL Version 2 section of the License file that
7.22 - * accompanied this code. If applicable, add the following below the License
7.23 - * Header, with the fields enclosed by brackets [] replaced by your own
7.24 - * identifying information: "Portions Copyrighted [year]
7.25 - * [name of copyright owner]"
7.26 - *
7.27 - * Contributor(s):
7.28 - *
7.29 - * If you wish your version of this file to be governed by only the CDDL or
7.30 - * only the GPL Version 2, indicate your decision by adding "[Contributor]
7.31 - * elects to include this software in this distribution under the [CDDL or GPL
7.32 - * Version 2] license." If you don't indicate a single choice of license, a
7.33 - * recipient has the option to distribute your version of this file under
7.34 - * either the CDDL, the GPL Version 2 or to extend the choice of license to
7.35 - * its licensees as provided above. However, if you add GPL Version 2 code
7.36 - * and therefore, elected the GPL Version 2 license, then the option applies
7.37 - * only if the new code is made subject to such option by the copyright
7.38 - * holder.
7.39 - */
7.40 -
7.41 -package cz.xelfi.quoridor.webidor;
7.42 -
7.43 -import com.sun.jersey.api.json.JSONConfiguration;
7.44 -import com.sun.jersey.api.json.JSONJAXBContext;
7.45 -import java.util.Arrays;
7.46 -import java.util.HashSet;
7.47 -import java.util.Set;
7.48 -import javax.ws.rs.ext.ContextResolver;
7.49 -import javax.ws.rs.ext.Provider;
7.50 -import javax.xml.bind.JAXBContext;
7.51 -
7.52 -/**
7.53 - *
7.54 - * @author japod
7.55 - */
7.56 -@Provider
7.57 -public final class JAXBContextResolver implements ContextResolver<JAXBContext> {
7.58 -
7.59 - private final JAXBContext context;
7.60 -
7.61 - private final Set<Class> types;
7.62 -
7.63 - private final Class[] cTypes = {Game.class, GameId.class, GameStatus.class };
7.64 -
7.65 - public JAXBContextResolver() throws Exception {
7.66 - this.types = new HashSet(Arrays.asList(cTypes));
7.67 - this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), cTypes);
7.68 - }
7.69 -
7.70 - public JAXBContext getContext(Class<?> objectType) {
7.71 - return (types.contains(objectType)) ? context : null;
7.72 - }
7.73 -}
7.74 \ No newline at end of file
8.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/Note.java Sun Sep 05 22:34:43 2010 +0200
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,79 +0,0 @@
8.4 -package cz.xelfi.quoridor.webidor;
8.5 -
8.6 -import java.util.Date;
8.7 -import javax.xml.bind.annotation.XmlAccessType;
8.8 -import javax.xml.bind.annotation.XmlAccessorType;
8.9 -import javax.xml.bind.annotation.XmlAttribute;
8.10 -import javax.xml.bind.annotation.XmlValue;
8.11 -
8.12 -/**
8.13 - *
8.14 - * @author Jaroslav Tulach <jtulach@netbeans.org>
8.15 - */
8.16 -@XmlAccessorType(XmlAccessType.FIELD)
8.17 -public class Note {
8.18 - @XmlValue
8.19 - private String comment;
8.20 - @XmlAttribute
8.21 - private Date when;
8.22 - @XmlAttribute
8.23 - private String who;
8.24 -
8.25 - private Note() {
8.26 - }
8.27 -
8.28 - public Note(String comment, Date when, String who) {
8.29 - this.comment = comment;
8.30 - this.when = new Date(when.getTime());
8.31 - this.who = who;
8.32 - }
8.33 -
8.34 - public String getComment() {
8.35 - return comment;
8.36 - }
8.37 -
8.38 - public Date getWhen() {
8.39 - return (Date) when.clone();
8.40 - }
8.41 -
8.42 - public String getWho() {
8.43 - return who;
8.44 - }
8.45 -
8.46 - @Override
8.47 - public String toString() {
8.48 - return "Note[" + who + "@" + when + ": " + comment + "]";
8.49 - }
8.50 -
8.51 - @Override
8.52 - public boolean equals(Object obj) {
8.53 - if (obj == null) {
8.54 - return false;
8.55 - }
8.56 - if (getClass() != obj.getClass()) {
8.57 - return false;
8.58 - }
8.59 - final Note other = (Note) obj;
8.60 - if ((this.comment == null) ? (other.comment != null) : !this.comment.equals(other.comment)) {
8.61 - return false;
8.62 - }
8.63 - if (this.when != other.when && (this.when == null || !this.when.equals(other.when))) {
8.64 - return false;
8.65 - }
8.66 - if ((this.who == null) ? (other.who != null) : !this.who.equals(other.who)) {
8.67 - return false;
8.68 - }
8.69 - return true;
8.70 - }
8.71 -
8.72 - @Override
8.73 - public int hashCode() {
8.74 - int hash = 7;
8.75 - hash = 59 * hash + (this.comment != null ? this.comment.hashCode() : 0);
8.76 - hash = 59 * hash + (this.when != null ? this.when.hashCode() : 0);
8.77 - hash = 59 * hash + (this.who != null ? this.who.hashCode() : 0);
8.78 - return hash;
8.79 - }
8.80 -
8.81 -
8.82 -}
9.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/User.java Sun Sep 05 22:34:43 2010 +0200
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,128 +0,0 @@
9.4 -/*
9.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9.6 - *
9.7 - * The contents of this file are subject to the terms of either the GNU
9.8 - * General Public License Version 2 only ("GPL") or the Common
9.9 - * Development and Distribution License("CDDL") (collectively, the
9.10 - * "License"). You may not use this file except in compliance with the
9.11 - * License. You can obtain a copy of the License at
9.12 - * http://www.netbeans.org/cddl-gplv2.html
9.13 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
9.14 - * specific language governing permissions and limitations under the
9.15 - * License. When distributing the software, include this License Header
9.16 - * Notice in each file and include the License file at
9.17 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
9.18 - * particular file as subject to the "Classpath" exception as provided
9.19 - * by Sun in the GPL Version 2 section of the License file that
9.20 - * accompanied this code. If applicable, add the following below the
9.21 - * License Header, with the fields enclosed by brackets [] replaced by
9.22 - * your own identifying information:
9.23 - * "Portions Copyrighted [year] [name of copyright owner]"
9.24 - *
9.25 - * Contributor(s):
9.26 - *
9.27 - * Portions Copyrighted 2009 Jaroslav Tulach
9.28 - */
9.29 -
9.30 -package cz.xelfi.quoridor.webidor;
9.31 -
9.32 -import java.util.ArrayList;
9.33 -import java.util.List;
9.34 -import java.util.Set;
9.35 -import java.util.TreeSet;
9.36 -import javax.xml.bind.annotation.XmlAccessType;
9.37 -import javax.xml.bind.annotation.XmlAccessorType;
9.38 -import javax.xml.bind.annotation.XmlAttribute;
9.39 -import javax.xml.bind.annotation.XmlElement;
9.40 -import javax.xml.bind.annotation.XmlRootElement;
9.41 -import javax.xml.bind.annotation.XmlValue;
9.42 -
9.43 -/**
9.44 - *
9.45 - * @author Jaroslav Tulach <jtulach@netbeans.org>
9.46 - */
9.47 -@XmlRootElement
9.48 -@XmlAccessorType(XmlAccessType.NONE)
9.49 -public final class User extends Object {
9.50 - @XmlAttribute
9.51 - private String id;
9.52 - @XmlElement(name="property")
9.53 - private List<Property> properties;
9.54 - private transient Set<String> permissions;
9.55 -
9.56 - User() {
9.57 - }
9.58 -
9.59 - public User(String id) {
9.60 - this.id = id;
9.61 - }
9.62 -
9.63 - public void addProperty(String name, String value) {
9.64 - if (properties == null) {
9.65 - properties = new ArrayList<Property>();
9.66 - }
9.67 - properties.add(new Property(name, value));
9.68 - }
9.69 -
9.70 - public void addPermission(String permission) {
9.71 - if (permissions == null) {
9.72 - permissions = new TreeSet<String>();
9.73 - }
9.74 - permissions.add(permission);
9.75 - }
9.76 -
9.77 - public String getProperty(String name) {
9.78 - if (properties == null) {
9.79 - return null;
9.80 - }
9.81 - for (Property p : properties) {
9.82 - if (p.name.equals(name)) {
9.83 - return p.value;
9.84 - }
9.85 - }
9.86 - return null;
9.87 - }
9.88 -
9.89 - public boolean hasPermission(String permission) {
9.90 - if (permissions == null) {
9.91 - return false;
9.92 - }
9.93 - return permissions.contains(permission);
9.94 - }
9.95 -
9.96 - public static boolean canSee(GameId gId, String userId) {
9.97 - if (!gId.isFinished()) {
9.98 - return true;
9.99 - }
9.100 - if (userId.equals(gId.getWhite())) {
9.101 - return true;
9.102 - }
9.103 - if (userId.equals(gId.getBlack())) {
9.104 - return true;
9.105 - }
9.106 - return false;
9.107 - }
9.108 -
9.109 - public boolean canSee(GameId gId){
9.110 - return canSee(gId, id);
9.111 - }
9.112 -
9.113 - public String getId() {
9.114 - return id;
9.115 - }
9.116 -
9.117 - public static final class Property {
9.118 - @XmlAttribute
9.119 - private String name;
9.120 - @XmlValue
9.121 - private String value;
9.122 -
9.123 - private Property() {
9.124 - }
9.125 -
9.126 - Property(String name, String value) {
9.127 - this.name = name;
9.128 - this.value = value;
9.129 - }
9.130 - }
9.131 -}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/wsdor/pom.xml Sat Sep 11 17:04:51 2010 +0200
10.3 @@ -0,0 +1,91 @@
10.4 +<?xml version="1.0" encoding="UTF-8"?>
10.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
10.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
10.7 + <modelVersion>4.0.0</modelVersion>
10.8 + <parent>
10.9 + <artifactId>all-quoridor</artifactId>
10.10 + <groupId>cz.xelfi.quoridor</groupId>
10.11 + <version>1.0</version>
10.12 + </parent>
10.13 + <groupId>cz.xelfi.quoridor</groupId>
10.14 + <artifactId>wsdor</artifactId>
10.15 + <packaging>bundle</packaging>
10.16 + <version>${wsdorVersion}</version>
10.17 + <name>wsdor</name>
10.18 + <url>http://maven.apache.org</url>
10.19 + <build>
10.20 + <plugins>
10.21 + <plugin>
10.22 + <groupId>org.apache.felix</groupId>
10.23 + <artifactId>maven-bundle-plugin</artifactId>
10.24 + <version>2.0.1</version>
10.25 + <extensions>true</extensions>
10.26 + <configuration>
10.27 + <instructions>
10.28 + <Export-Package>cz.xelfi.quoridor.webidor</Export-Package>
10.29 + <Private-Package>cz.xelfi.quoridor.webidor.*</Private-Package>
10.30 + </instructions>
10.31 + </configuration>
10.32 + </plugin>
10.33 + <plugin>
10.34 + <groupId>org.apache.maven.plugins</groupId>
10.35 + <artifactId>maven-compiler-plugin</artifactId>
10.36 + <version>2.0.2</version>
10.37 + <configuration>
10.38 + <source>1.5</source>
10.39 + <target>1.5</target>
10.40 + </configuration>
10.41 + </plugin>
10.42 + <plugin>
10.43 + <groupId>org.apache.maven.plugins</groupId>
10.44 + <artifactId>maven-javadoc-plugin</artifactId>
10.45 + <version>2.5</version>
10.46 + <!--
10.47 + <configuration>
10.48 + <excludePackageNames>org.netbeans.modules.openide.util</excludePackageNames>
10.49 + <overview>${basedir}/src/main/java/org/openide/util/lookup/doc-files/index.html</overview>
10.50 + </configuration>
10.51 + -->
10.52 + </plugin>
10.53 + </plugins>
10.54 + </build>
10.55 + <dependencies>
10.56 + <dependency>
10.57 + <groupId>junit</groupId>
10.58 + <artifactId>junit</artifactId>
10.59 + <version>3.8.1</version>
10.60 + <scope>test</scope>
10.61 + </dependency>
10.62 + <dependency>
10.63 + <groupId>${project.groupId}</groupId>
10.64 + <artifactId>quoridor</artifactId>
10.65 + <version>${quoridorVersion}</version>
10.66 + </dependency>
10.67 + <dependency>
10.68 + <groupId>com.sun.jersey</groupId>
10.69 + <artifactId>jersey-core</artifactId>
10.70 + <version>1.1.0-ea</version>
10.71 + </dependency>
10.72 + <dependency>
10.73 + <groupId>com.sun.jersey</groupId>
10.74 + <artifactId>jersey-server</artifactId>
10.75 + <version>1.1.0-ea</version>
10.76 + </dependency>
10.77 + <dependency>
10.78 + <groupId>com.sun.jersey</groupId>
10.79 + <artifactId>jersey-json</artifactId>
10.80 + <version>1.1.0-ea</version>
10.81 + <type>jar</type>
10.82 + <exclusions>
10.83 + <exclusion>
10.84 + <artifactId>jaxb-api</artifactId>
10.85 + <groupId>javax.xml.bind</groupId>
10.86 + </exclusion>
10.87 + <exclusion>
10.88 + <artifactId>stax-api</artifactId>
10.89 + <groupId>stax</groupId>
10.90 + </exclusion>
10.91 + </exclusions>
10.92 + </dependency>
10.93 + </dependencies>
10.94 +</project>
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/wsdor/src/main/java/cz/xelfi/quoridor/webidor/CommentedMove.java Sat Sep 11 17:04:51 2010 +0200
11.3 @@ -0,0 +1,104 @@
11.4 +package cz.xelfi.quoridor.webidor;
11.5 +
11.6 +import cz.xelfi.quoridor.IllegalPositionException;
11.7 +import cz.xelfi.quoridor.Move;
11.8 +import java.util.ArrayList;
11.9 +import java.util.List;
11.10 +import javax.xml.bind.annotation.XmlAttribute;
11.11 +import javax.xml.bind.annotation.XmlElement;
11.12 +
11.13 +public final class CommentedMove {
11.14 + Move move;
11.15 + int index;
11.16 + List<Note> comments;
11.17 +
11.18 + private CommentedMove() {
11.19 + super();
11.20 + }
11.21 +
11.22 + CommentedMove(Move move, int index) {
11.23 + super();
11.24 + this.move = move;
11.25 + this.index = index;
11.26 + }
11.27 +
11.28 + public Move getMove() {
11.29 + return move;
11.30 + }
11.31 +
11.32 + @XmlAttribute(name="move")
11.33 + String getMoveText() {
11.34 + return move.toString();
11.35 + }
11.36 +
11.37 + void setMoveText(String m) throws IllegalPositionException {
11.38 + move = Move.valueOf(m);
11.39 + }
11.40 +
11.41 + @XmlAttribute
11.42 + int getIndex() {
11.43 + return index;
11.44 + }
11.45 +
11.46 + void setIndex(int i) {
11.47 + index = i;
11.48 + }
11.49 +
11.50 + void addNote(Note n) {
11.51 + if (comments == null) {
11.52 + comments = new ArrayList<Note>();
11.53 + }
11.54 + comments.add(n);
11.55 + }
11.56 +
11.57 + @XmlElement(name="comment", required=false)
11.58 + public final List<Note> getComments() {
11.59 + return comments;
11.60 + }
11.61 +
11.62 + final void setComments(List<Note> l) {
11.63 + this.comments = l;
11.64 + }
11.65 +
11.66 + @Override
11.67 + public String toString() {
11.68 + StringBuilder sb = new StringBuilder();
11.69 + sb.append("Move[").append(move).append("@").append(index);
11.70 + if (comments != null) {
11.71 + sb.append(", ");
11.72 + sb.append(comments);
11.73 + }
11.74 + sb.append("]");
11.75 + return sb.toString();
11.76 + }
11.77 +
11.78 + @Override
11.79 + public boolean equals(Object obj) {
11.80 + if (obj == null) {
11.81 + return false;
11.82 + }
11.83 + if (getClass() != obj.getClass()) {
11.84 + return false;
11.85 + }
11.86 + final CommentedMove other = (CommentedMove) obj;
11.87 + if (this.move != other.move && (this.move == null || !this.move.equals(other.move))) {
11.88 + return false;
11.89 + }
11.90 + if (this.index != other.index) {
11.91 + return false;
11.92 + }
11.93 + if (this.comments != other.comments && (this.comments == null || !this.comments.equals(other.comments))) {
11.94 + return false;
11.95 + }
11.96 + return true;
11.97 + }
11.98 +
11.99 + @Override
11.100 + public int hashCode() {
11.101 + int hash = 5;
11.102 + hash = 43 * hash + (this.move != null ? this.move.hashCode() : 0);
11.103 + hash = 43 * hash + this.index;
11.104 + hash = 43 * hash + (this.comments != null ? this.comments.hashCode() : 0);
11.105 + return hash;
11.106 + }
11.107 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/wsdor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Sat Sep 11 17:04:51 2010 +0200
12.3 @@ -0,0 +1,213 @@
12.4 +/*
12.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
12.6 + *
12.7 + * The contents of this file are subject to the terms of either the GNU
12.8 + * General Public License Version 2 only ("GPL") or the Common
12.9 + * Development and Distribution License("CDDL") (collectively, the
12.10 + * "License"). You may not use this file except in compliance with the
12.11 + * License. You can obtain a copy of the License at
12.12 + * http://www.netbeans.org/cddl-gplv2.html
12.13 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12.14 + * specific language governing permissions and limitations under the
12.15 + * License. When distributing the software, include this License Header
12.16 + * Notice in each file and include the License file at
12.17 + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
12.18 + * particular file as subject to the "Classpath" exception as provided
12.19 + * by Sun in the GPL Version 2 section of the License file that
12.20 + * accompanied this code. If applicable, add the following below the
12.21 + * License Header, with the fields enclosed by brackets [] replaced by
12.22 + * your own identifying information:
12.23 + * "Portions Copyrighted [year] [name of copyright owner]"
12.24 + *
12.25 + * Contributor(s):
12.26 + *
12.27 + * Portions Copyrighted 2009 Jaroslav Tulach
12.28 + */
12.29 +
12.30 +package cz.xelfi.quoridor.webidor;
12.31 +
12.32 +import cz.xelfi.quoridor.Board;
12.33 +import cz.xelfi.quoridor.IllegalPositionException;
12.34 +import cz.xelfi.quoridor.Move;
12.35 +import cz.xelfi.quoridor.Player;
12.36 +import java.util.ArrayList;
12.37 +import java.util.Date;
12.38 +import java.util.List;
12.39 +import javax.xml.bind.annotation.XmlAccessType;
12.40 +import javax.xml.bind.annotation.XmlAccessorType;
12.41 +import javax.xml.bind.annotation.XmlAttribute;
12.42 +import javax.xml.bind.annotation.XmlElement;
12.43 +import javax.xml.bind.annotation.XmlElementWrapper;
12.44 +import javax.xml.bind.annotation.XmlRootElement;
12.45 +import javax.xml.bind.annotation.adapters.XmlAdapter;
12.46 +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
12.47 +
12.48 +/**
12.49 + *
12.50 + * @author Jaroslav Tulach <jtulach@netbeans.org>
12.51 + */
12.52 +@XmlRootElement
12.53 +@XmlAccessorType(XmlAccessType.FIELD)
12.54 +public final class Game extends Object {
12.55 + @XmlElement
12.56 + private GameId id;
12.57 + @XmlElement
12.58 + @XmlJavaTypeAdapter(BoardAdapter.class)
12.59 + private Board board;
12.60 + @XmlElementWrapper(name="moves")
12.61 + @XmlElement(name="item")
12.62 + private List<CommentedMove> moves;
12.63 + private Integer move;
12.64 +
12.65 + Game() {
12.66 + }
12.67 +
12.68 + public Game(String first, String second) {
12.69 + this.id = new GameId(first, second);
12.70 + this.board = Board.empty();
12.71 + }
12.72 +
12.73 + public Game(GameId id) {
12.74 + this.id = id;
12.75 + this.board = Board.empty();
12.76 + }
12.77 +
12.78 + public GameId getId() {
12.79 + return id;
12.80 + }
12.81 +
12.82 + public Board getBoard() {
12.83 + return board;
12.84 + }
12.85 +
12.86 + @XmlAttribute
12.87 + final String getCurrentPlayer() {
12.88 + Player w = board.getWinner();
12.89 + if(w==null){
12.90 + if (board.getCurrentPlayer() == board.getPlayers().get(0)) {
12.91 + return id.getWhite();
12.92 + } else {
12.93 + return id.getBlack();
12.94 + }
12.95 + }else{
12.96 + if (w == board.getPlayers().get(0)) {
12.97 + return id.getWhite();
12.98 + } else {
12.99 + return id.getBlack();
12.100 + }
12.101 + }
12.102 + }
12.103 +
12.104 + public void apply(String player, Move m, Date when) throws IllegalPositionException {
12.105 + Player p = null;
12.106 + if (id.getWhite().equals(player)) {
12.107 + p = getBoard().getPlayers().get(0);
12.108 + } else {
12.109 + if (id.getBlack().equals(player)) {
12.110 + p = getBoard().getPlayers().get(1);
12.111 + }
12.112 + }
12.113 + if (p != getBoard().getCurrentPlayer()) {
12.114 + throw new IllegalArgumentException("Wrong player: " + player);
12.115 + }
12.116 +
12.117 + board = getBoard().apply(m);
12.118 + if (when == null) {
12.119 + when = new Date(id.getModified());
12.120 + }
12.121 + final GameStatus status = GameStatus.valueOf(board);
12.122 + id = new GameId(
12.123 + id.getId(), id.getWhite(), id.getBlack(),
12.124 + new Date(id.getStarted()), when, status,
12.125 + id.getComments(), !status.isInProgress());
12.126 + getMoves().add(new CommentedMove(m, getMoves().size() + 1));
12.127 + }
12.128 +
12.129 + public void comment(String player, String comment, Date date) {
12.130 + Note n = new Note(comment, date, player);
12.131 + id = new GameId(
12.132 + id.getId(), id.getWhite(), id.getBlack(),
12.133 + new Date(id.getStarted()), new Date(id.getModified()),
12.134 + GameStatus.valueOf(board), id.getComments() + 1, id.isFinished()
12.135 + );
12.136 + getMoves().get(getMoves().size() - 1).addNote(n);
12.137 + }
12.138 +
12.139 +
12.140 + public List<CommentedMove> getMoves() {
12.141 + if (moves == null) {
12.142 + moves = new ArrayList<CommentedMove>();
12.143 + }
12.144 + return moves;
12.145 + }
12.146 +
12.147 + @XmlAttribute
12.148 + public int getCurrentMove() {
12.149 + return move == null ? getMoves().size() : move;
12.150 + }
12.151 +
12.152 + public Game snapshot(int move) throws IllegalPositionException {
12.153 + Board b = Board.empty();
12.154 + int cnt = 0;
12.155 + for (CommentedMove m : getMoves()) {
12.156 + if (move-- <= 0) {
12.157 + break;
12.158 + }
12.159 + b = b.apply(m.getMove());
12.160 + cnt++;
12.161 + }
12.162 +
12.163 + Game g = new Game(
12.164 + new GameId(
12.165 + id.getId(), id.getWhite(), id.getBlack(),
12.166 + new Date(id.getStarted()), new Date(id.getModified()),
12.167 + GameStatus.history, id.getComments(), id.isFinished()
12.168 + )
12.169 + );
12.170 + g.board = b;
12.171 + g.move = cnt;
12.172 + g.moves = new ArrayList<CommentedMove>(getMoves());
12.173 + return g;
12.174 + }
12.175 +/*
12.176 + private static final class MoveAdapter extends XmlAdapter<CommentedMove[],List<Move>> {
12.177 + @Override
12.178 + public List<Move> unmarshal(CommentedMove[] arr) throws Exception {
12.179 + List<Move> res = new ArrayList<Move>();
12.180 + if (arr != null) {
12.181 + for (CommentedMove v : arr) {
12.182 + res.add(Move.valueOf(v.move));
12.183 + }
12.184 + }
12.185 + return res;
12.186 + }
12.187 +
12.188 + @Override
12.189 + public CommentedMove[] marshal(List<Move> arr) throws Exception {
12.190 + List<CommentedMove> res = new ArrayList<CommentedMove>();
12.191 + if (arr != null) {
12.192 + int index = 0;
12.193 + for (Move m : arr) {
12.194 + res.add(new CommentedMove(m.toString(), ++index));
12.195 + }
12.196 + }
12.197 + return res.toArray(new CommentedMove[0]);
12.198 + }
12.199 + } // end of MoveAdapter
12.200 +*/
12.201 + private static final class BoardAdapter extends XmlAdapter<String,Board> {
12.202 +
12.203 + @Override
12.204 + public Board unmarshal(String v) throws Exception {
12.205 + return v == null ? null : Board.valueOf(v);
12.206 +// return v == null ? null : new Board(v);
12.207 + }
12.208 +
12.209 + @Override
12.210 + public String marshal(Board v) throws Exception {
12.211 + return v == null ? null : v.toString();
12.212 +// return v == null ? null : Board.board2HashCode(v);
12.213 + }
12.214 +
12.215 + }
12.216 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/wsdor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java Sat Sep 11 17:04:51 2010 +0200
13.3 @@ -0,0 +1,136 @@
13.4 +/*
13.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
13.6 + *
13.7 + * The contents of this file are subject to the terms of either the GNU
13.8 + * General Public License Version 2 only ("GPL") or the Common
13.9 + * Development and Distribution License("CDDL") (collectively, the
13.10 + * "License"). You may not use this file except in compliance with the
13.11 + * License. You can obtain a copy of the License at
13.12 + * http://www.netbeans.org/cddl-gplv2.html
13.13 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13.14 + * specific language governing permissions and limitations under the
13.15 + * License. When distributing the software, include this License Header
13.16 + * Notice in each file and include the License file at
13.17 + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
13.18 + * particular file as subject to the "Classpath" exception as provided
13.19 + * by Sun in the GPL Version 2 section of the License file that
13.20 + * accompanied this code. If applicable, add the following below the
13.21 + * License Header, with the fields enclosed by brackets [] replaced by
13.22 + * your own identifying information:
13.23 + * "Portions Copyrighted [year] [name of copyright owner]"
13.24 + *
13.25 + * Contributor(s):
13.26 + *
13.27 + * Portions Copyrighted 2009 Jaroslav Tulach
13.28 + */
13.29 +
13.30 +package cz.xelfi.quoridor.webidor;
13.31 +
13.32 +import java.util.Comparator;
13.33 +import java.util.Date;
13.34 +import java.util.UUID;
13.35 +import javax.xml.bind.annotation.XmlAccessType;
13.36 +import javax.xml.bind.annotation.XmlAccessorType;
13.37 +import javax.xml.bind.annotation.XmlAttribute;
13.38 +import javax.xml.bind.annotation.XmlID;
13.39 +import javax.xml.bind.annotation.XmlRootElement;
13.40 +
13.41 +/** Basic identification of a game.
13.42 + *
13.43 + * @author Jaroslav Tulach <jtulach@netbeans.org>
13.44 + */
13.45 +@XmlRootElement
13.46 +@XmlAccessorType(XmlAccessType.FIELD)
13.47 +public class GameId {
13.48 + public static final Comparator<GameId> NEWEST_FIRST = new NewestFirst();
13.49 +
13.50 + @XmlAttribute
13.51 + private String white;
13.52 + @XmlAttribute
13.53 + private String black;
13.54 + @XmlAttribute
13.55 + private long started;
13.56 + @XmlAttribute
13.57 + private long modified;
13.58 + @XmlAttribute
13.59 + private GameStatus status;
13.60 + @XmlID @XmlAttribute
13.61 + private String id;
13.62 + @XmlAttribute
13.63 + private int comments;
13.64 + @XmlAttribute
13.65 + private boolean finished;
13.66 +
13.67 + GameId() {
13.68 + }
13.69 +
13.70 + public GameId(String first, String second) {
13.71 + this(first, second, new Date());
13.72 + }
13.73 + private GameId(String first, String second, Date d) {
13.74 + this(
13.75 + UUID.randomUUID().toString(),
13.76 + first, second, d, d, GameStatus.whiteMove, 0, false
13.77 + );
13.78 + }
13.79 +
13.80 + public GameId(
13.81 + String id, String first, String second,
13.82 + Date started, Date last, GameStatus result,
13.83 + int comments, boolean finished
13.84 + ) {
13.85 + this.white = first;
13.86 + this.black = second;
13.87 + this.id = id;
13.88 + this.started = started.getTime();
13.89 + this.modified = last.getTime();
13.90 + this.status = result;
13.91 + this.comments = comments;
13.92 + this.finished = finished;
13.93 + }
13.94 +
13.95 + public String getId() {
13.96 + return id;
13.97 + }
13.98 +
13.99 + public String getWhite() {
13.100 + return white;
13.101 + }
13.102 +
13.103 + public String getBlack() {
13.104 + return black;
13.105 + }
13.106 +
13.107 + public long getStarted() {
13.108 + return started;
13.109 + }
13.110 +
13.111 + public long getModified() {
13.112 + return modified;
13.113 + }
13.114 +
13.115 + public GameStatus getStatus() {
13.116 + return status;
13.117 + }
13.118 +
13.119 + public int getComments() {
13.120 + return comments;
13.121 + }
13.122 +
13.123 + public boolean isFinished() {
13.124 + return finished;
13.125 + }
13.126 +
13.127 + private static final class NewestFirst implements Comparator<GameId> {
13.128 + public int compare(GameId o1, GameId o2) {
13.129 + if (o1 == o2) {
13.130 + return 0;
13.131 + }
13.132 + long diff = o2.getModified() - o1.getModified();
13.133 + if (diff != 0) {
13.134 + return diff < 0 ? -1 : 1;
13.135 + }
13.136 + return o1.getId().compareTo(o2.getId());
13.137 + }
13.138 + }
13.139 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/wsdor/src/main/java/cz/xelfi/quoridor/webidor/GameStatus.java Sat Sep 11 17:04:51 2010 +0200
14.3 @@ -0,0 +1,61 @@
14.4 +/*
14.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
14.6 + *
14.7 + * The contents of this file are subject to the terms of either the GNU
14.8 + * General Public License Version 2 only ("GPL") or the Common
14.9 + * Development and Distribution License("CDDL") (collectively, the
14.10 + * "License"). You may not use this file except in compliance with the
14.11 + * License. You can obtain a copy of the License at
14.12 + * http://www.netbeans.org/cddl-gplv2.html
14.13 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
14.14 + * specific language governing permissions and limitations under the
14.15 + * License. When distributing the software, include this License Header
14.16 + * Notice in each file and include the License file at
14.17 + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
14.18 + * particular file as subject to the "Classpath" exception as provided
14.19 + * by Sun in the GPL Version 2 section of the License file that
14.20 + * accompanied this code. If applicable, add the following below the
14.21 + * License Header, with the fields enclosed by brackets [] replaced by
14.22 + * your own identifying information:
14.23 + * "Portions Copyrighted [year] [name of copyright owner]"
14.24 + *
14.25 + * Contributor(s):
14.26 + *
14.27 + * Portions Copyrighted 2009 Jaroslav Tulach
14.28 + */
14.29 +
14.30 +package cz.xelfi.quoridor.webidor;
14.31 +
14.32 +import cz.xelfi.quoridor.Board;
14.33 +
14.34 +/** Possible states of the game.
14.35 + *
14.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
14.37 + */
14.38 +public enum GameStatus {
14.39 + whiteMove,
14.40 + blackMove,
14.41 + whiteWon,
14.42 + blackWon,
14.43 + history;
14.44 +
14.45 + /** Creates appropriate status of the game based on the state
14.46 + * on the board.
14.47 + *
14.48 + * @param board the board
14.49 + * @return status describing the situation on the board
14.50 + */
14.51 + public static GameStatus valueOf(Board board) {
14.52 + if (board.getWinner() != null) {
14.53 + return board.getWinner() == board.getPlayers().get(0) ? GameStatus.whiteWon : GameStatus.blackWon;
14.54 + } else {
14.55 + return board.getCurrentPlayer() == board.getPlayers().get(0) ? GameStatus.whiteMove : GameStatus.blackMove;
14.56 + }
14.57 + }
14.58 +
14.59 + /** @return true if the game is in progress
14.60 + */
14.61 + public boolean isInProgress() {
14.62 + return this == whiteMove || this == blackMove;
14.63 + }
14.64 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/wsdor/src/main/java/cz/xelfi/quoridor/webidor/JAXBContextResolver.java Sat Sep 11 17:04:51 2010 +0200
15.3 @@ -0,0 +1,70 @@
15.4 +/*
15.5 + *
15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
15.7 + *
15.8 + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
15.9 + *
15.10 + * The contents of this file are subject to the terms of either the GNU
15.11 + * General Public License Version 2 only ("GPL") or the Common Development
15.12 + * and Distribution License("CDDL") (collectively, the "License"). You
15.13 + * may not use this file except in compliance with the License. You can obtain
15.14 + * a copy of the License at https://jersey.dev.java.net/CDDL+GPL.html
15.15 + * or jersey/legal/LICENSE.txt. See the License for the specific
15.16 + * language governing permissions and limitations under the License.
15.17 + *
15.18 + * When distributing the software, include this License Header Notice in each
15.19 + * file and include the License file at jersey/legal/LICENSE.txt.
15.20 + * Sun designates this particular file as subject to the "Classpath" exception
15.21 + * as provided by Sun in the GPL Version 2 section of the License file that
15.22 + * accompanied this code. If applicable, add the following below the License
15.23 + * Header, with the fields enclosed by brackets [] replaced by your own
15.24 + * identifying information: "Portions Copyrighted [year]
15.25 + * [name of copyright owner]"
15.26 + *
15.27 + * Contributor(s):
15.28 + *
15.29 + * If you wish your version of this file to be governed by only the CDDL or
15.30 + * only the GPL Version 2, indicate your decision by adding "[Contributor]
15.31 + * elects to include this software in this distribution under the [CDDL or GPL
15.32 + * Version 2] license." If you don't indicate a single choice of license, a
15.33 + * recipient has the option to distribute your version of this file under
15.34 + * either the CDDL, the GPL Version 2 or to extend the choice of license to
15.35 + * its licensees as provided above. However, if you add GPL Version 2 code
15.36 + * and therefore, elected the GPL Version 2 license, then the option applies
15.37 + * only if the new code is made subject to such option by the copyright
15.38 + * holder.
15.39 + */
15.40 +
15.41 +package cz.xelfi.quoridor.webidor;
15.42 +
15.43 +import com.sun.jersey.api.json.JSONConfiguration;
15.44 +import com.sun.jersey.api.json.JSONJAXBContext;
15.45 +import java.util.Arrays;
15.46 +import java.util.HashSet;
15.47 +import java.util.Set;
15.48 +import javax.ws.rs.ext.ContextResolver;
15.49 +import javax.ws.rs.ext.Provider;
15.50 +import javax.xml.bind.JAXBContext;
15.51 +
15.52 +/**
15.53 + *
15.54 + * @author japod
15.55 + */
15.56 +@Provider
15.57 +public final class JAXBContextResolver implements ContextResolver<JAXBContext> {
15.58 +
15.59 + private final JAXBContext context;
15.60 +
15.61 + private final Set<Class> types;
15.62 +
15.63 + private final Class[] cTypes = {Game.class, GameId.class, GameStatus.class };
15.64 +
15.65 + public JAXBContextResolver() throws Exception {
15.66 + this.types = new HashSet(Arrays.asList(cTypes));
15.67 + this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), cTypes);
15.68 + }
15.69 +
15.70 + public JAXBContext getContext(Class<?> objectType) {
15.71 + return (types.contains(objectType)) ? context : null;
15.72 + }
15.73 +}
15.74 \ No newline at end of file
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/wsdor/src/main/java/cz/xelfi/quoridor/webidor/Note.java Sat Sep 11 17:04:51 2010 +0200
16.3 @@ -0,0 +1,79 @@
16.4 +package cz.xelfi.quoridor.webidor;
16.5 +
16.6 +import java.util.Date;
16.7 +import javax.xml.bind.annotation.XmlAccessType;
16.8 +import javax.xml.bind.annotation.XmlAccessorType;
16.9 +import javax.xml.bind.annotation.XmlAttribute;
16.10 +import javax.xml.bind.annotation.XmlValue;
16.11 +
16.12 +/**
16.13 + *
16.14 + * @author Jaroslav Tulach <jtulach@netbeans.org>
16.15 + */
16.16 +@XmlAccessorType(XmlAccessType.FIELD)
16.17 +public class Note {
16.18 + @XmlValue
16.19 + private String comment;
16.20 + @XmlAttribute
16.21 + private Date when;
16.22 + @XmlAttribute
16.23 + private String who;
16.24 +
16.25 + private Note() {
16.26 + }
16.27 +
16.28 + public Note(String comment, Date when, String who) {
16.29 + this.comment = comment;
16.30 + this.when = new Date(when.getTime());
16.31 + this.who = who;
16.32 + }
16.33 +
16.34 + public String getComment() {
16.35 + return comment;
16.36 + }
16.37 +
16.38 + public Date getWhen() {
16.39 + return (Date) when.clone();
16.40 + }
16.41 +
16.42 + public String getWho() {
16.43 + return who;
16.44 + }
16.45 +
16.46 + @Override
16.47 + public String toString() {
16.48 + return "Note[" + who + "@" + when + ": " + comment + "]";
16.49 + }
16.50 +
16.51 + @Override
16.52 + public boolean equals(Object obj) {
16.53 + if (obj == null) {
16.54 + return false;
16.55 + }
16.56 + if (getClass() != obj.getClass()) {
16.57 + return false;
16.58 + }
16.59 + final Note other = (Note) obj;
16.60 + if ((this.comment == null) ? (other.comment != null) : !this.comment.equals(other.comment)) {
16.61 + return false;
16.62 + }
16.63 + if (this.when != other.when && (this.when == null || !this.when.equals(other.when))) {
16.64 + return false;
16.65 + }
16.66 + if ((this.who == null) ? (other.who != null) : !this.who.equals(other.who)) {
16.67 + return false;
16.68 + }
16.69 + return true;
16.70 + }
16.71 +
16.72 + @Override
16.73 + public int hashCode() {
16.74 + int hash = 7;
16.75 + hash = 59 * hash + (this.comment != null ? this.comment.hashCode() : 0);
16.76 + hash = 59 * hash + (this.when != null ? this.when.hashCode() : 0);
16.77 + hash = 59 * hash + (this.who != null ? this.who.hashCode() : 0);
16.78 + return hash;
16.79 + }
16.80 +
16.81 +
16.82 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/wsdor/src/main/java/cz/xelfi/quoridor/webidor/User.java Sat Sep 11 17:04:51 2010 +0200
17.3 @@ -0,0 +1,128 @@
17.4 +/*
17.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
17.6 + *
17.7 + * The contents of this file are subject to the terms of either the GNU
17.8 + * General Public License Version 2 only ("GPL") or the Common
17.9 + * Development and Distribution License("CDDL") (collectively, the
17.10 + * "License"). You may not use this file except in compliance with the
17.11 + * License. You can obtain a copy of the License at
17.12 + * http://www.netbeans.org/cddl-gplv2.html
17.13 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
17.14 + * specific language governing permissions and limitations under the
17.15 + * License. When distributing the software, include this License Header
17.16 + * Notice in each file and include the License file at
17.17 + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17.18 + * particular file as subject to the "Classpath" exception as provided
17.19 + * by Sun in the GPL Version 2 section of the License file that
17.20 + * accompanied this code. If applicable, add the following below the
17.21 + * License Header, with the fields enclosed by brackets [] replaced by
17.22 + * your own identifying information:
17.23 + * "Portions Copyrighted [year] [name of copyright owner]"
17.24 + *
17.25 + * Contributor(s):
17.26 + *
17.27 + * Portions Copyrighted 2009 Jaroslav Tulach
17.28 + */
17.29 +
17.30 +package cz.xelfi.quoridor.webidor;
17.31 +
17.32 +import java.util.ArrayList;
17.33 +import java.util.List;
17.34 +import java.util.Set;
17.35 +import java.util.TreeSet;
17.36 +import javax.xml.bind.annotation.XmlAccessType;
17.37 +import javax.xml.bind.annotation.XmlAccessorType;
17.38 +import javax.xml.bind.annotation.XmlAttribute;
17.39 +import javax.xml.bind.annotation.XmlElement;
17.40 +import javax.xml.bind.annotation.XmlRootElement;
17.41 +import javax.xml.bind.annotation.XmlValue;
17.42 +
17.43 +/**
17.44 + *
17.45 + * @author Jaroslav Tulach <jtulach@netbeans.org>
17.46 + */
17.47 +@XmlRootElement
17.48 +@XmlAccessorType(XmlAccessType.NONE)
17.49 +public final class User extends Object {
17.50 + @XmlAttribute
17.51 + private String id;
17.52 + @XmlElement(name="property")
17.53 + private List<Property> properties;
17.54 + private transient Set<String> permissions;
17.55 +
17.56 + User() {
17.57 + }
17.58 +
17.59 + public User(String id) {
17.60 + this.id = id;
17.61 + }
17.62 +
17.63 + public void addProperty(String name, String value) {
17.64 + if (properties == null) {
17.65 + properties = new ArrayList<Property>();
17.66 + }
17.67 + properties.add(new Property(name, value));
17.68 + }
17.69 +
17.70 + public void addPermission(String permission) {
17.71 + if (permissions == null) {
17.72 + permissions = new TreeSet<String>();
17.73 + }
17.74 + permissions.add(permission);
17.75 + }
17.76 +
17.77 + public String getProperty(String name) {
17.78 + if (properties == null) {
17.79 + return null;
17.80 + }
17.81 + for (Property p : properties) {
17.82 + if (p.name.equals(name)) {
17.83 + return p.value;
17.84 + }
17.85 + }
17.86 + return null;
17.87 + }
17.88 +
17.89 + public boolean hasPermission(String permission) {
17.90 + if (permissions == null) {
17.91 + return false;
17.92 + }
17.93 + return permissions.contains(permission);
17.94 + }
17.95 +
17.96 + public static boolean canSee(GameId gId, String userId) {
17.97 + if (!gId.isFinished()) {
17.98 + return true;
17.99 + }
17.100 + if (userId.equals(gId.getWhite())) {
17.101 + return true;
17.102 + }
17.103 + if (userId.equals(gId.getBlack())) {
17.104 + return true;
17.105 + }
17.106 + return false;
17.107 + }
17.108 +
17.109 + public boolean canSee(GameId gId){
17.110 + return canSee(gId, id);
17.111 + }
17.112 +
17.113 + public String getId() {
17.114 + return id;
17.115 + }
17.116 +
17.117 + public static final class Property {
17.118 + @XmlAttribute
17.119 + private String name;
17.120 + @XmlValue
17.121 + private String value;
17.122 +
17.123 + private Property() {
17.124 + }
17.125 +
17.126 + Property(String name, String value) {
17.127 + this.name = name;
17.128 + this.value = value;
17.129 + }
17.130 + }
17.131 +}