KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > enhydraManager > presentation > ListPresentation


1 package enhydraManager.presentation;
2
3 import enhydraManager.spec.*;
4 import enhydraManager.EnhydraManager;
5 // Standard imports
6
import java.util.Vector JavaDoc;
7 import java.io.IOException JavaDoc;
8
9 // Enhydra SuperServlet imports
10
import com.lutris.appserver.server.httpPresentation.HttpPresentation;
11 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
12 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
13 import org.w3c.dom.html.*;
14
15 import org.w3c.dom.*;
16
17 public class ListPresentation implements HttpPresentation {
18
19   private static ListHTML list;
20   
21   static String JavaDoc refresh = null;
22   
23   
24   public void run(HttpPresentationComms comms) throws HttpPresentationException, IOException JavaDoc {
25
26     try{
27         
28       
29         if (refresh==null){
30             refresh = EnhydraManager.refresh;
31         }
32         OutputList(comms);
33     }catch(Exception JavaDoc e){
34         e.printStackTrace();
35     }
36     try {
37     } catch (Exception JavaDoc exe){}
38   }
39
40
41   public static void OutputList(HttpPresentationComms comms) throws Exception JavaDoc {
42     
43     String JavaDoc defaultService = comms.request.getParameter("service");
44     list = (ListHTML)comms.xmlcFactory.create(ListHTML.class);
45     
46         if(comms.request.getParameter("message")!=null)
47          {
48          list.setTextMessage(comms.request.getParameter("message"));
49         }
50         else
51         {
52          HTMLParagraphElement remove = list.getElementRemove();
53          remove.getParentNode().removeChild(remove);
54         }
55     
56     try {
57         Integer.parseInt(comms.request.getParameter("refresh"));
58         refresh = comms.request.getParameter("refresh");
59         
60     } catch (Exception JavaDoc e) {
61         defaultService = "Catalina";
62         }
63     
64    ApplicationList applicationList=ApplicationListFactory.getApplicationList("enhydraManager.business.ApplicationListImpl");
65      
66      
67      String JavaDoc []services = applicationList.getServices();
68      
69     
70      
71       HTMLMetaElement metaRefresh = list.getElementRefresh();
72
73
74  
75
76   
77    if (refresh.equals("0")){
78         metaRefresh.getParentNode().removeChild(metaRefresh);
79     }else {
80         metaRefresh.setContent(refresh);
81     }
82     
83     
84      Node hostElementRow =list.getElementTable();
85
86   NodeList listaa=hostElementRow.getChildNodes();
87     
88   Node one = listaa.item(0);
89   Node backupone = one.cloneNode(true);
90     
91     Node two = listaa.item(1);
92     Node backuptwo = two.cloneNode(true);
93     
94     Node tree = listaa.item(2);
95     Node backuptree = tree.cloneNode(true);
96
97
98
99 for(int k=0;k<services.length;k++)
100  {
101    boolean removeFirst=false;
102   
103   
104    list.setTextService(services[k]);
105       
106   
107    Vector JavaDoc[] lists=applicationList.getList(services[k]);
108   
109      Vector JavaDoc hosts=lists[0];
110      Vector JavaDoc appl=lists[1];
111   
112    
113    for(int j=0;j<hosts.size();j++){
114
115
116  
117     Node applicationElementRow = list.getElementAppliactions_row();
118   
119     Node application_row = list.getElementAppliactions_row();
120  
121   
122      String JavaDoc host=(String JavaDoc)hosts.elementAt(j);
123     
124   
125     Vector JavaDoc[] tmp=(Vector JavaDoc[])appl.elementAt(j);
126     Vector JavaDoc appList = tmp[0];
127     Vector JavaDoc activeSessions = tmp[1];
128     Vector JavaDoc isDeployed=tmp[2];
129     Vector JavaDoc isStarted=tmp[3];
130     
131
132     list.setTextHost(host);
133     
134  
135     if (appList.size() == 0) {
136
137
138     }else if (appList.size()==activeSessions.size()){
139  
140         for (int i=0; i<appList.size(); i++) {
141             
142         
143        
144             String JavaDoc appName = (String JavaDoc) appList.elementAt(i);
145             String JavaDoc appStatus= (String JavaDoc) isDeployed.elementAt(i)+" : "+(String JavaDoc) isStarted.elementAt(i);
146    
147    
148             try {
149                 if(appName.length()!=0){
150                   if(appName.equals("/"))
151                     list.setTextAppName("ROOT");
152                   else
153                 list.setTextAppName(appName.substring(1));
154              
155              list.setTextStatus(appStatus);}
156                 else
157                  break;
158             } catch (IllegalArgumentException JavaDoc ex){
159                 list.setTextAppName("Couldn't get Application Name!");
160             }
161             String JavaDoc deployed = "false";
162             String JavaDoc started = "false";
163             
164             if(((String JavaDoc) isDeployed.elementAt(i)).equals("Deployed"))
165             {
166               deployed = "true";
167              
168              }
169             
170             if(((String JavaDoc) isStarted.elementAt(i)).equals("Started"))
171              {
172               started = "true";
173             }
174             
175         
176         
177            HTMLAnchorElement anchorAction = list.getElementAction();
178            anchorAction.setHref("ActionPresentation.po?service="+services[k]+"&host="+host+"&id="+appName.substring(1)+"&started="+started+"&deployed="+deployed);
179            
180           
181           
182             
183             if(started.equals("true"))
184             {
185             HTMLAnchorElement anchorView = list.getElementView();
186             anchorView.setHref("ApplicationPresentation.po?service="+services[k]+"&host="+host+"&id="+ appList.elementAt(i));
187             anchorView.setTitle("Click to view Application sessions in more detail!");
188             
189              try {
190                 list.setTextView(((Integer JavaDoc)activeSessions.elementAt(i)).toString());
191             } catch (IllegalArgumentException JavaDoc ex){
192                 list.setTextView("Couldn't get active session count!");
193             }
194             
195             
196             }else{
197              HTMLAnchorElement anchorView = list.getElementView();
198             anchorView.setHref("");
199             list.setTextView("0");
200             }
201            
202            
203             
204             
205             if(started.equals("true")){
206             HTMLAnchorElement anchorSummary = list.getElementSummary();
207             anchorSummary.setHref("AppDetailPresentation.po?service="+services[k]+"&host="+host+"&id="+ appList.elementAt(i));
208              anchorSummary.setTitle("Click to view Application Sessions detail summary page!");
209             }else{
210             HTMLAnchorElement anchorSummary = list.getElementSummary();
211             anchorSummary.setHref("");
212             
213           }
214           
215             list.setTextSummary("Summary");
216             
217             applicationElementRow.getParentNode().insertBefore(applicationElementRow.cloneNode(true),
218                                                                    applicationElementRow);
219              
220         }
221      
222
223    
224         }
225       
226       Node www =null;
227      if(removeFirst)
228       {
229         www=hostElementRow.cloneNode(true);
230         www.removeChild(www.getLastChild());
231         www.removeChild(www.getFirstChild());
232      }
233      else
234      {
235         www=hostElementRow.cloneNode(true);
236         www.removeChild(www.getLastChild());
237      }
238         
239         
240         hostElementRow.getParentNode().insertBefore(www,hostElementRow);
241  
242    
243   removeFirst=true;
244   
245   NodeList lista=hostElementRow.getChildNodes();
246   
247      
248      
249      int num=lista.getLength()-2;
250      
251      for(int t=1;t<num;t++)
252       {
253         try{
254          hostElementRow.removeChild(lista.item(2));
255             } catch (Exception JavaDoc exxxx){
256                 exxxx.printStackTrace();
257             }
258         }
259      
260       hostElementRow.insertBefore(backuptree,hostElementRow.getLastChild());
261   
262        }
263    
264      
265      }
266         hostElementRow.getParentNode().removeChild(hostElementRow);
267         
268         
269         HTMLSelectElement select = list.getElementServiceList();
270         HTMLOptionElement templateOption = list.getElementTemplateServiceList();
271         
272     Node pathSelect = templateOption.getParentNode();
273     templateOption.removeAttribute("id");
274         
275         String JavaDoc selected=null;
276         
277         
278         
279         for (int num = 0; num < services.length; num++)
280            {
281     
282         String JavaDoc current = services[num];
283         HTMLOptionElement clonedOption = (HTMLOptionElement) templateOption.cloneNode(true);
284         clonedOption.setValue(current);
285         Node optionTextNode = clonedOption.getOwnerDocument().createTextNode(current);
286         clonedOption.appendChild(optionTextNode);
287         select.add(clonedOption,null);
288         if (comms.request.getParameter("service") != null&&comms.request.getParameter("service").equals(current))
289         {
290         selected = current;
291         select.setSelectedIndex(num+1);
292         
293         }
294             }
295             select.remove(templateOption.getIndex());
296             
297             
298             
299             
300            if(selected==null)
301            {
302             selected = services[0];
303            }
304           
305            
306         
307         HTMLSelectElement selectHost = list.getElementHostList();
308         HTMLOptionElement templateHostOption = list.getElementTemplateHostList();
309         
310     Node pathSelectHost = templateHostOption.getParentNode();
311     templateHostOption.removeAttribute("id");
312         
313      Vector JavaDoc[] temp = applicationList.getList(selected);
314         
315         
316         Vector JavaDoc hosts = temp[0];
317         
318         for (int num = 0; num < hosts.size(); num++)
319            {
320     
321         String JavaDoc current = (String JavaDoc)hosts.elementAt(num);
322         HTMLOptionElement clonedOption = (HTMLOptionElement) templateHostOption.cloneNode(true);
323         clonedOption.setValue(current);
324         Node optionTextNode = clonedOption.getOwnerDocument().createTextNode(current);
325         clonedOption.appendChild(optionTextNode);
326         selectHost.add(clonedOption,null);
327         
328           }
329          selectHost.remove(templateHostOption.getIndex());
330      comms.response.writeDOM(list);
331
332   }
333 }
334
335
Popular Tags