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: import org.w3c.dom.html.HTMLTableElement;
16: import org.w3c.dom.html.HTMLTableRowElement;
17: import org.w3c.dom.html.HTMLAnchorElement;
18:
19: import poker.Poker;
20: import poker.spec.PokerGame;
21: import poker.spec.GameManager;
22:
23: import java.util.Vector;
24:
25: public class ScoresPresentation implements HttpPresentation {
26:
27: public void run(HttpPresentationComms comms)
28: throws HttpPresentationException, KeywordValueException {
29:
30: ScoresHTML scores;
31: scores = (ScoresHTML) comms.xmlcFactory
32: .create(ScoresHTML.class);
33:
34: HTMLTableRowElement dummyRow = (HTMLTableRowElement) scores
35: .getElementDummyRow();
36: HTMLTableElement table = (HTMLTableElement) scores
37: .getElementScoreTable();
38:
39: Poker mainApp = (Poker) comms.session.getSessionData().get(
40: "app");
41: GameManager gameManager = mainApp.getGameManager();
42:
43: /*
44: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run poker_pres )
45: * We need to allow poker_pres to be dynamic , so if the requested url is /poker_pres/..... the response
46: * will be default HTML page
47: */
48: try {
49: Vector topTen = gameManager.getTopTen();
50:
51: PokerGame game;
52: for (int i = 0; i < 10; i++) {
53: game = (PokerGame) topTen.elementAt(i);
54: if (!game.getName().equals("")) {
55: scores.setTextNumbers(Integer.toString(i));
56: scores.setTextName(game.getName());
57: scores
58: .setTextCach(Integer.toString(game
59: .getCash()));
60: HTMLAnchorElement a = scores.getElementEmail();
61: a.setHref("MAILTO:" + game.getEmail());
62: scores.setTextHands(Integer.toString(game
63: .getTotalPlayed()));
64: } else {
65: scores.setTextNumbers(Integer.toString(i));
66: scores.setTextName(" ");
67: scores.setTextCach(" ");
68: HTMLAnchorElement a = scores.getElementEmail();
69: a.setHref("MAILTO:a@a.co.yu");
70: scores.setTextHands(" ");
71: }
72: HTMLTableRowElement clonedRow = (HTMLTableRowElement) dummyRow
73: .cloneNode(true);
74: table.insertBefore(clonedRow, table.getLastChild());
75: }
76:
77: table.removeChild(dummyRow);
78: } catch (NullPointerException e) {
79: }
80: comms.response.writeDOM(scores);
81: }
82:
83: }
|