KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > poker > presentation > main > StatsPresentation


1 /*
2  * Poker
3  *
4  * Enhydra super-servlet presentation object
5  *
6  */

7
8 package poker.presentation.main;
9
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
21 public class StatsPresentation implements HttpPresentation {
22
23
24   public void run(HttpPresentationComms comms)
25       throws HttpPresentationException, KeywordValueException {
26
27     StatsHTML stats;
28     stats = (StatsHTML)comms.xmlcFactory.create(StatsHTML.class);
29
30     Poker mainApp = (Poker)comms.session.getSessionData().get("app");
31     GameManager gameManager = mainApp.getGameManager();
32     PokerGame game = (PokerGame)comms.session.getSessionData().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 JavaDoc ranking = Integer.toString(rank) + " of " + Integer.toString(count);
43
44     stats.setTextName(game.getName());
45     stats.setTextRank(ranking);
46     stats.setTextCash(Integer.toString(game.getCash()));
47     stats.setTextTotal(Integer.toString(game.getTotalPlayed()));
48     stats.setTextLargest(Integer.toString(game.getLargestBet()));
49     stats.setTextSmallest(Integer.toString(game.getSmallestBet()));
50     stats.setTextWon(Integer.toString(game.getTotalWon()));
51     stats.setTextLost(Integer.toString(game.getTotalPlayed() - game.getTotalWon()));
52
53 }catch (NullPointerException JavaDoc e){}
54
55     comms.response.writeDOM(stats);
56   }
57
58 }
59
Popular Tags