desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/Quoridor.java
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
6 package cz.xelfi.quoridor.desktop.sample;
8 import com.sun.jersey.api.client.Client;
9 import com.sun.jersey.api.client.GenericType;
10 import com.sun.jersey.api.client.WebResource;
11 import cz.xelfi.quoridor.webidor.Game;
12 import cz.xelfi.quoridor.webidor.GameId;
13 import java.util.List;
14 import javax.ws.rs.core.MediaType;
15 import org.openide.util.Lookup;
17 /** Class that connects to the server and answers queries.
19 * @author Jaroslav Tulach
21 abstract class Quoridor {
23 public static Quoridor getDefault() {
24 Quoridor q = Lookup.getDefault().lookup(Quoridor.class);
25 return q == null ? new Impl() : q;
28 public abstract List<GameId> listGames();
29 public abstract Game getGame(String id);
31 private static class Impl extends Quoridor {
32 private final WebResource wr;
35 Client c = new Client();
36 wr = c.resource("http://quoridor.xelfi.cz/api/");
40 public List<GameId> listGames() {
41 GenericType<List<GameId>> gType = new GenericType<List<GameId>>() {};
42 List<GameId> ids = wr.path("games").accept(MediaType.TEXT_XML).get(gType);
48 public Game getGame(String id) {
49 Game g = wr.path("games").path(id).accept(MediaType.TEXT_XML).get(Game.class);