01: /*
02: * Poker
03: *
04: * Enhydra super-servlet presentation object
05: *
06: */
07:
08: package poker.presentation.main;
09:
10: // Enhydra SuperServlet imports
11: import com.lutris.appserver.server.httpPresentation.HttpPresentation;
12: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
13: import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
14: import com.lutris.util.KeywordValueException;
15:
16: import poker.Poker;
17: import poker.spec.PokerGame;
18: import poker.spec.GameManager;
19:
20: public class StatsPresentation implements HttpPresentation {
21:
22: public void run(HttpPresentationComms comms)
23: throws HttpPresentationException, KeywordValueException {
24:
25: StatsHTML stats;
26: stats = (StatsHTML) comms.xmlcFactory.create(StatsHTML.class);
27:
28: Poker mainApp = (Poker) comms.session.getSessionData().get(
29: "app");
30: GameManager gameManager = mainApp.getGameManager();
31: PokerGame game = (PokerGame) comms.session.getSessionData()
32: .get("game");
33:
34: /*
35: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run poker_pres )
36: * We need to allow poker_pres to be dynamic , so if the requested url is /poker_pres/..... the response
37: * will be default HTML page
38: */
39: try {
40: int rank = gameManager.getRank(game.getCash());
41: int count = gameManager.getCount();
42: String ranking = Integer.toString(rank) + " of "
43: + Integer.toString(count);
44:
45: stats.setTextName(game.getName());
46: stats.setTextRank(ranking);
47: stats.setTextCash(Integer.toString(game.getCash()));
48: stats.setTextTotal(Integer.toString(game.getTotalPlayed()));
49: stats
50: .setTextLargest(Integer.toString(game
51: .getLargestBet()));
52: stats.setTextSmallest(Integer.toString(game
53: .getSmallestBet()));
54: stats.setTextWon(Integer.toString(game.getTotalWon()));
55: stats.setTextLost(Integer.toString(game.getTotalPlayed()
56: - game.getTotalWon()));
57:
58: } catch (NullPointerException e) {
59: }
60:
61: comms.response.writeDOM(stats);
62: }
63:
64: }
|