KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > ejosa > piggybank > presentation > enhydra > SmashPage


1 /**
2  * Title: OpenUSS - Open Source University Support System
3  * My Piggy Bank Example
4  * Description: Enhydra Presentation Object
5  * Copyright: Copyright (c) 2003 by B. Lofi Dewanto, T. Menzel
6  * Company: University of Muenster, HTWK Leipzig
7  * @author B. Lofi Dewanto, T. Menzel
8  * @version 1.1
9  */

10 package net.sourceforge.ejosa.piggybank.presentation.enhydra;
11
12 import com.lutris.appserver.server.httpPresentation.*;
13
14 //import com.lutris.xml.xmlc.*;
15

16 import java.io.*;
17
18 import java.util.*;
19
20 import net.sourceforge.ejosa.piggybank.spec.*;
21 import net.sourceforge.ejosa.piggybank.spec.business.*;
22 import net.sourceforge.ejosa.piggybank.spec.system.*;
23
24 import org.openuss.presentation.enhydra.framework.*;
25
26 import org.openuss.utility.*;
27
28 import org.w3c.dom.*;
29 import org.w3c.dom.html.*;
30
31
32 /**
33  * Smash Page
34  *
35  * @author B. Lofi Dewanto, T. Menzel
36  * @version 1.1
37  */

38 public class SmashPage extends FoundationPO {
39     // Page
40
private SmashHTML mPage;
41
42     /**
43      * Default event. Just show the page.
44      */

45     public String JavaDoc handleDefault() throws HttpPresentationException {
46         // Create the page
47
mPage = (SmashHTML) this.getComms().xmlcFactory.create(SmashHTML.class);
48
49         // Look for an error
50
String JavaDoc errorMsg = this.getSessionData().getAndClearUserMessage();
51
52         if (errorMsg == null) {
53             // No error
54
mPage.getElementTStatusbar().getParentNode()
55                  .removeChild(mPage.getElementTStatusbar());
56         } else {
57             // Error, put it in the statusbar
58
mPage.setTextTStatusbar(errorMsg);
59         }
60
61         // Work with the page
62
return showLayout(mPage);
63     }
64
65     /**
66      * Superclass method override.
67      */

68     public boolean loggedInUserRequired() {
69         // This page doesn't need a login
70
return false;
71     }
72
73     /**
74      * Show the page, override the method.
75      */

76     public String JavaDoc showLayout(Object JavaDoc page) throws BasePOException {
77         // Format the statusbar and treebar
78
super.showLayout(mPage);
79
80
81         // Show something
82
showSmash();
83
84         // Return the result
85
return mPage.toDocument();
86     }
87
88     /**
89      * Shows smash.
90      */

91     private void showSmash() throws FoundationPOException {
92         int cur = 0;
93         int sum = 0;
94
95         // This method shows something
96
HTMLTableRowElement templateRow = mPage.getElementTemplateRow();
97         HTMLElement entryTemplate = mPage.getElementTEntry();
98         HTMLElement dateTemplate = mPage.getElementTDate();
99         HTMLElement amountTemplate = mPage.getElementTAmount();
100         HTMLElement balanceTemplate = mPage.getElementTBalance();
101         HTMLElement currencyTemplate = mPage.getElementTCurrency();
102
103         templateRow.removeAttribute("id");
104         entryTemplate.removeAttribute("id");
105         dateTemplate.removeAttribute("id");
106         amountTemplate.removeAttribute("id");
107         balanceTemplate.removeAttribute("id");
108         currencyTemplate.removeAttribute("id");
109
110         Node table = templateRow.getParentNode();
111
112         // Business access
113
// !!!Only access to the specification!!!
114
try {
115             // Get the workflow object
116
CoinManager coinManager = CoinManagerFactory.createCoinManager(
117                                               "net.sourceforge.ejosa.piggybank.business.session.CoinManagerImpl");
118
119             //System.out.println("Coin: create a coin helper with the home interface!");
120
Vector coinList = coinManager.findAllCoins();
121             Coin fc;
122             for (int i = 0; i < coinList.size(); i++) {
123                 fc = (Coin) coinList.elementAt(i);
124                 //System.out.println("Coin number: " + i + " with coin amount " + fc.getAmount());
125
mPage.setTextVEntry("" + (i + 1));
126                 mPage.setTextVDate(fc.getDate());
127                 cur = Integer.parseInt(fc.getAmount());
128                 sum = sum + cur;
129                 mPage.setTextVAmount("" + cur);
130                 mPage.setTextVBalance("" + sum);
131                 mPage.setTextVCurrency("Dollar");
132                 table.appendChild(templateRow.cloneNode(true));
133
134                 coinManager.removeCoin(fc.getId());
135             }
136
137             //System.out.println(coinList.size() + " coins found in the piggy bank!");
138
} catch (Exception JavaDoc ex) {
139             System.out.println("EJB Error: " + ex);
140             ex.printStackTrace();
141         }
142
143         table.removeChild(templateRow);
144
145         mPage.setTextVCash("" + sum);
146     }
147 }
Popular Tags