KickJava   Java API By Example, From Geeks To Geeks.

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


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 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 JavaDoc;
24
25 public class ScoresPresentation implements HttpPresentation {
26
27
28   public void run(HttpPresentationComms comms)
29           throws HttpPresentationException, KeywordValueException {
30
31     ScoresHTML scores;
32     scores = (ScoresHTML)comms.xmlcFactory.create(ScoresHTML.class);
33
34     HTMLTableRowElement dummyRow = (HTMLTableRowElement)scores.getElementDummyRow();
35     HTMLTableElement table = (HTMLTableElement)scores.getElementScoreTable();
36
37     Poker mainApp = (Poker)comms.session.getSessionData().get("app");
38     GameManager gameManager = mainApp.getGameManager();
39
40
41 /*
42  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run poker_pres )
43  * We need to allow poker_pres to be dynamic , so if the requested url is /poker_pres/..... the response
44  * will be default HTML page
45  */

46 try{
47     Vector JavaDoc topTen = gameManager.getTopTen();
48
49     PokerGame game;
50     for (int i = 0; i < 10; i++) {
51       game = (PokerGame)topTen.elementAt(i);
52       if (!game.getName().equals("")) {
53         scores.setTextNumbers(Integer.toString(i));
54         scores.setTextName(game.getName());
55         scores.setTextCach(Integer.toString(game.getCash()));
56         HTMLAnchorElement a = scores.getElementEmail();
57         a.setHref("MAILTO:" + game.getEmail());
58         scores.setTextHands(Integer.toString(game.getTotalPlayed()));
59       }
60       else {
61         scores.setTextNumbers(Integer.toString(i));
62         scores.setTextName(" ");
63         scores.setTextCach(" ");
64         HTMLAnchorElement a = scores.getElementEmail();
65         a.setHref("MAILTO:a@a.co.yu");
66         scores.setTextHands(" ");
67       }
68       HTMLTableRowElement clonedRow = (HTMLTableRowElement)dummyRow.cloneNode(true);
69       table.insertBefore(clonedRow, table.getLastChild());
70     }
71
72     table.removeChild(dummyRow);
73 }catch (NullPointerException JavaDoc e){}
74     comms.response.writeDOM(scores);
75   }
76
77 }
78
Popular Tags