KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > phoneList > presentation > DoActionPresentation


1 package phoneList.presentation;
2
3 import com.lutris.appserver.server.httpPresentation.*;
4
5 import phoneList.spec.*;
6
7 public class DoActionPresentation implements HttpPresentation {
8
9     public void run(HttpPresentationComms comms) throws Exception JavaDoc {
10         String JavaDoc first = null;
11         try {
12             first = comms.request.getParameter("first");
13         } catch (Exception JavaDoc e) {
14         }
15         String JavaDoc last = null;
16         try {
17             last = comms.request.getParameter("last");
18         } catch (Exception JavaDoc e) {
19         }
20         String JavaDoc phone = null;
21         try {
22             phone = comms.request.getParameter("phone");
23         } catch (Exception JavaDoc e) {
24         }
25         String JavaDoc id = null;
26         try {
27             id = comms.request.getParameter("id");
28         } catch (Exception JavaDoc e) {
29         }
30         String JavaDoc action = null;
31         try {
32             action = comms.request.getParameter("action");
33         } catch (Exception JavaDoc e) {
34         }
35        
36         PhoneList phoneList = PhoneListFactory.getPhoneList("phoneList.business.PhoneListImpl");
37         String JavaDoc okTarget = comms.request.getAppFileURIPath("ListPresentation.po");
38         String JavaDoc errTarget = comms.request.getAppFileURIPath("ErrorPresentation.po");
39         ClientPageRedirectException err =
40                                     new ClientPageRedirectException(errTarget);
41   
42         if (action.equals("delete")) {
43             if ((id == null) || (id.length() == 0)) {
44                 err.addArgument("err", "Error: no id specified.");
45                 throw err;
46             }
47        try{
48             phoneList.deletePerson(id);
49       /*
50        * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run phoneBookClient_pres )
51        * We need to allow phoneBookClient_pres to be functional
52        */

53        } catch(NullPointerException JavaDoc ex) {
54         err.addArgument("err", "Error: You cannot delete person while runing phoneBookClient_pres!");
55        throw err;
56        }
57         } else if (action.equals("edit")) {
58             if ((id == null) || (id.length() == 0)) {
59                 err.addArgument("err", "Error: no id specified.");
60                 throw err;
61             }
62             if ((first == null) || (first.length() == 0)) {
63                 err.addArgument("err", "Error: no first name specified.");
64                 throw err;
65             }
66             if ((last == null) || (last.length() == 0)) {
67                 err.addArgument("err", "Error: no last name specified.");
68                 throw err;
69             }
70             if ((phone == null) || (phone.length() == 0)) {
71                 err.addArgument("err", "Error: no phone number specified.");
72                 throw err;
73             }
74           try{
75             phoneList.modifyPerson(id, first, last, phone);
76          //same thing
77
} catch(NullPointerException JavaDoc ex) {
78            err.addArgument("err", "Error: You cannot modify person while runing phoneBookClient_pres!");
79         throw err;
80         }
81        
82         } else if (action.equals("create")) {
83             if ((first == null) || (first.length() == 0)) {
84                 err.addArgument("err", "Error: no first name specified.");
85                 throw err;
86             }
87             if ((last == null) || (last.length() == 0)) {
88                 err.addArgument("err", "Error: no last name specified.");
89                 throw err;
90             }
91             if ((phone == null) || (phone.length() == 0)) {
92                 err.addArgument("err", "Error: no phone number specified.");
93                 throw err;
94             }
95           try{
96             phoneList.addPerson(first, last, phone);
97           //same thing
98
} catch(NullPointerException JavaDoc ex) {
99            err.addArgument("err", "Error: You cannot add person while runing phoneBookClient_pres!");
100         throw err;
101         }
102
103  
104         } else {
105             // Shouldn't happen.
106
}
107
108     
109     
110         throw new ClientPageRedirectException(okTarget);
111     }
112
113 }
114
115
Popular Tags