KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > deploy > BaseDeployAction


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: BaseDeployAction.java,v 1.38 2005/07/25 22:52:32 vivekl Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.deploy;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.Properties JavaDoc;
30
31 import javax.management.ObjectName JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33
34 import org.objectweb.jonas.jmx.J2eeObjectName;
35 import org.objectweb.jonas.jmx.JonasManagementRepr;
36 import org.objectweb.jonas.jmx.JonasObjectName;
37 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
38 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
39 import org.objectweb.jonas.webapp.jonasadmin.JonasTreeBuilder;
40 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
41 import org.objectweb.jonas.webapp.taglib.TreeControl;
42 import org.objectweb.jonas.webapp.taglib.TreeControlNode;
43
44 /**
45  * @author Michel-Ange ANTON
46  */

47
48 abstract public class BaseDeployAction extends JonasBaseAction {
49
50 // --------------------------------------------------------- Protected Methods
51

52     protected int getCurrentJonasDeployment()
53         throws Exception JavaDoc {
54         int iRet = 0;
55         iRet = m_WhereAreYou.getCurrentJonasDeploymentType();
56         return iRet;
57     }
58
59     protected void setCurrentJonasDeployment(HttpServletRequest JavaDoc p_Request)
60         throws Exception JavaDoc {
61         int iDeployment = 0;
62         String JavaDoc sDeployment = p_Request.getParameter("type");
63         if (sDeployment != null) {
64             // Dispatch
65
if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_EAR) == true) {
66                 iDeployment = WhereAreYou.DEPLOYMENT_EAR;
67             }
68             else if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_JAR) == true) {
69                 iDeployment = WhereAreYou.DEPLOYMENT_JAR;
70             }
71             else if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_WAR) == true) {
72                 iDeployment = WhereAreYou.DEPLOYMENT_WAR;
73             }
74             else if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_RAR) == true) {
75                 iDeployment = WhereAreYou.DEPLOYMENT_RAR;
76             }
77             else if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_DATASOURCE) == true) {
78                 iDeployment = WhereAreYou.DEPLOYMENT_DATASOURCE;
79             }
80             else if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_MAILFACTORY) == true) {
81                 iDeployment = WhereAreYou.DEPLOYMENT_MAIL;
82             }
83             else if (sDeployment.equals(WhereAreYou.DOMAIN_DEPLOYMENT_STRING_EAR) == true) {
84                 iDeployment = WhereAreYou.DOMAIN_DEPLOYMENT_EAR;
85             }
86             else if (sDeployment.equals(WhereAreYou.DOMAIN_DEPLOYMENT_STRING_JAR) == true) {
87                 iDeployment = WhereAreYou.DOMAIN_DEPLOYMENT_JAR;
88             }
89             else if (sDeployment.equals(WhereAreYou.DOMAIN_DEPLOYMENT_STRING_WAR) == true) {
90                 iDeployment = WhereAreYou.DOMAIN_DEPLOYMENT_WAR;
91             }
92             else if (sDeployment.equals(WhereAreYou.DOMAIN_DEPLOYMENT_STRING_RAR) == true) {
93                 iDeployment = WhereAreYou.DOMAIN_DEPLOYMENT_RAR;
94             }
95             else {
96                 throw new Exception JavaDoc("Unknown type deployment");
97             }
98             // Storing
99
m_WhereAreYou.setCurrentJonasDeploymentType(iDeployment);
100         }
101     }
102
103     /**
104      * Return the edit forward string.
105      *
106      * @return The edit forward string
107      */

108     protected String JavaDoc getForwardEdit() {
109         String JavaDoc sForward = null;
110         try {
111             switch (getCurrentJonasDeployment()) {
112                 case WhereAreYou.DEPLOYMENT_EAR:
113                 case WhereAreYou.DEPLOYMENT_JAR:
114                 case WhereAreYou.DEPLOYMENT_WAR:
115                 case WhereAreYou.DEPLOYMENT_RAR:
116                     sForward = "Deploy";
117                     break;
118                 case WhereAreYou.DOMAIN_DEPLOYMENT_EAR:
119                 case WhereAreYou.DOMAIN_DEPLOYMENT_JAR:
120                 case WhereAreYou.DOMAIN_DEPLOYMENT_WAR:
121                 case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
122                     sForward = "Domain Deploy";
123                     break;
124                 case WhereAreYou.DEPLOYMENT_DATASOURCE:
125                     sForward = "Deploy Datasource";
126                     break;
127                 case WhereAreYou.DEPLOYMENT_MAIL:
128                     sForward = "Deploy Mail Factory";
129                     break;
130             }
131         }
132         catch (Exception JavaDoc e) {
133             // none
134
}
135         return sForward;
136     }
137     
138     protected boolean isDomain() {
139         boolean result = false;
140         try {
141             switch (getCurrentJonasDeployment()) {
142             case WhereAreYou.DOMAIN_DEPLOYMENT_EAR:
143             case WhereAreYou.DOMAIN_DEPLOYMENT_JAR:
144             case WhereAreYou.DOMAIN_DEPLOYMENT_WAR:
145             case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
146                 result = true;
147                 break;
148             }
149         } catch (Exception JavaDoc e) {
150             // none
151
}
152         return result;
153     }
154     
155     protected String JavaDoc getDomainDeploymentMethodName() {
156         String JavaDoc result = "";
157         try {
158             switch (getCurrentJonasDeployment()) {
159             case WhereAreYou.DOMAIN_DEPLOYMENT_EAR:
160                 result = "deployEar";
161                 break;
162             case WhereAreYou.DOMAIN_DEPLOYMENT_JAR:
163                 result = "deployJar";
164                 break;
165             case WhereAreYou.DOMAIN_DEPLOYMENT_WAR:
166                 result = "deployWar";
167                 break;
168             case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
169                 result = "deployRar";
170                 break;
171             }
172         } catch (Exception JavaDoc e) {
173             // none
174
}
175         return result;
176     }
177     
178     protected String JavaDoc getDomainUploadDeployMethodName() {
179         String JavaDoc result = "";
180         try {
181             switch (getCurrentJonasDeployment()) {
182             case WhereAreYou.DOMAIN_DEPLOYMENT_EAR:
183                 result = "uploadDeployEar";
184                 break;
185             case WhereAreYou.DOMAIN_DEPLOYMENT_JAR:
186                 result = "uploadDeployJar";
187                 break;
188             case WhereAreYou.DOMAIN_DEPLOYMENT_WAR:
189                 result = "uploadDeployWar";
190                 break;
191             case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
192                 result = "uploadDeployRar";
193                 break;
194             }
195         } catch (Exception JavaDoc e) {
196             // none
197
}
198         return result;
199     }
200     
201     /**
202      * Return the list of deployable files in using the type of current
203      * deployment storing in WhereAreYou instance in session.
204      *
205      * @return The list of deployable files
206      * @throws Exception
207      */

208     protected ArrayList JavaDoc getListDeployableFiles()
209         throws Exception JavaDoc {
210         ArrayList JavaDoc al = null;
211         switch (getCurrentJonasDeployment()) {
212             case WhereAreYou.DEPLOYMENT_EAR:
213                 al = JonasAdminJmx.getEarFilesDeployable();
214                 break;
215             case WhereAreYou.DEPLOYMENT_JAR:
216                 al = JonasAdminJmx.getJarFilesDeployable();
217                 break;
218             case WhereAreYou.DEPLOYMENT_WAR:
219                 al = JonasAdminJmx.getWarFilesDeployable();
220                 break;
221             case WhereAreYou.DEPLOYMENT_RAR:
222                 al = JonasAdminJmx.getRarFilesDeployable();
223                 break;
224             case WhereAreYou.DOMAIN_DEPLOYMENT_EAR:
225                 al = JonasAdminJmx.getEarFilesDeployable();
226                 al.addAll(JonasAdminJmx.getEarFilesDeployed());
227                 break;
228             case WhereAreYou.DOMAIN_DEPLOYMENT_JAR:
229                 al = JonasAdminJmx.getJarFilesDeployable();
230                 al.addAll(JonasAdminJmx.getJarFilesDeployed());
231                 break;
232             case WhereAreYou.DOMAIN_DEPLOYMENT_WAR:
233                 al = JonasAdminJmx.getWarFilesDeployable();
234                 al.addAll(JonasAdminJmx.getWarFilesDeployed());
235                 break;
236             case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
237                 al = JonasAdminJmx.getRarFilesDeployable();
238                 al.addAll(JonasAdminJmx.getRarFilesDeployed());
239                 break;
240             case WhereAreYou.DEPLOYMENT_DATASOURCE:
241                 al = JonasAdminJmx.getDatasourceFilesDeployable();
242                 break;
243             case WhereAreYou.DEPLOYMENT_MAIL:
244                 al = JonasAdminJmx.getMailFilesDeployable();
245                 break;
246         }
247         return al;
248     }
249
250     /**
251      * Return the list of deployed files in using the type of current deployment
252      * storing in WhereAreYou instance in session.
253      *
254      * @return The list of deployed files
255      * @throws Exception
256      */

257     protected ArrayList JavaDoc getListDeployedFiles()
258         throws Exception JavaDoc {
259         ArrayList JavaDoc al = null;
260         switch (getCurrentJonasDeployment()) {
261             case WhereAreYou.DEPLOYMENT_EAR:
262                 al = JonasAdminJmx.getEarFilesDeployed();
263                 break;
264             case WhereAreYou.DEPLOYMENT_JAR:
265                 al = JonasAdminJmx.getJarFilesDeployed();
266                 break;
267             case WhereAreYou.DEPLOYMENT_RAR:
268                 al = JonasAdminJmx.getRarFilesDeployed();
269                 break;
270             case WhereAreYou.DEPLOYMENT_WAR:
271                 al = JonasAdminJmx.getWarFilesDeployed();
272                 break;
273             case WhereAreYou.DEPLOYMENT_DATASOURCE:
274                 String JavaDoc domainName = m_WhereAreYou.getCurrentDomainName();
275                 String JavaDoc serverName = m_WhereAreYou.getCurrentJonasServerName();
276                 al = JonasAdminJmx.getDatasourceFilesDeployed(domainName, serverName);
277                 break;
278             case WhereAreYou.DEPLOYMENT_MAIL:
279                 al = JonasAdminJmx.getMailFilesDeployed(m_WhereAreYou);
280                 break;
281         }
282         return al;
283     }
284
285     /**
286      * Undeploy a file in using the type of current deployment
287      * storing in WhereAreYou instance in session.
288      *
289      * @param p_Filename Name of file to undeploy
290      * @throws Exception
291      */

292     protected void undeploy(String JavaDoc p_Filename)
293         throws Exception JavaDoc {
294         String JavaDoc[] asParam = new String JavaDoc[1];
295         asParam[0] = p_Filename;
296         String JavaDoc[] asSignature = new String JavaDoc[1];
297         asSignature[0] = "java.lang.String";
298
299         switch (getCurrentJonasDeployment()) {
300             case WhereAreYou.DEPLOYMENT_EAR:
301                 JonasManagementRepr.invoke(JonasObjectName.earService(), "unDeployEarMBean"
302                     , asParam, asSignature);
303                 break;
304             case WhereAreYou.DEPLOYMENT_JAR:
305                 JonasManagementRepr.invoke(JonasObjectName.ejbService(), "removeContainerMBean", asParam
306                     , asSignature);
307                 break;
308             case WhereAreYou.DEPLOYMENT_RAR:
309                 JonasManagementRepr.invoke(JonasObjectName.resourceService(), "unDeployRarMBean"
310                     , asParam, asSignature);
311                 break;
312             case WhereAreYou.DEPLOYMENT_WAR:
313                 JonasManagementRepr.invoke(JonasObjectName.webContainerService()
314                     , "unRegisterWarMBean", asParam, asSignature);
315                 break;
316             case WhereAreYou.DEPLOYMENT_DATASOURCE:
317                 undeployDataSource(p_Filename);
318                 break;
319             case WhereAreYou.DEPLOYMENT_MAIL:
320                 undeployMailFactory(p_Filename);
321                 break;
322         }
323     }
324
325     /**
326      * Undeploy a datasource file.
327      *
328      * @param p_Filename Name of file to undeploy
329      * @throws Exception
330      */

331     protected void undeployDataSource(String JavaDoc p_Filename)
332         throws Exception JavaDoc {
333         ArrayList JavaDoc al = JonasAdminJmx.getDatasourceDependences(p_Filename
334                 , m_WhereAreYou.getCurrentDomainName()
335                 , m_WhereAreYou.getCurrentJonasServerName());
336         if (al.size() == 0) {
337             String JavaDoc[] asParam = new String JavaDoc[1];
338             asParam[0] = p_Filename;
339             String JavaDoc[] asSignature = new String JavaDoc[1];
340             asSignature[0] = "java.lang.String";
341             JonasManagementRepr.invoke(JonasObjectName.databaseService(), "unloadDataSource"
342                 , asParam, asSignature);
343         }
344         else {
345             throw new Exception JavaDoc(m_Resources.getMessage("error.undeploy.datasource.dependences"
346                 , al.toString()));
347         }
348     }
349
350     /**
351      * Undeploy a mail factory.
352      *
353      * @param p_Filename Name of the factory (same as the props file name configuring it)
354      * @throws Exception
355      */

356     protected void undeployMailFactory(String JavaDoc p_Filename)
357         throws Exception JavaDoc {
358         ArrayList JavaDoc al = JonasAdminJmx.getMailFactoryDependences(p_Filename, m_WhereAreYou);
359         if (al.size() == 0) {
360             String JavaDoc[] asParam = new String JavaDoc[1];
361             asParam[0] = p_Filename;
362             String JavaDoc[] asSignature = new String JavaDoc[1];
363             asSignature[0] = "java.lang.String";
364             JonasManagementRepr.invoke(JonasObjectName.mailService(), "unbindMailFactoryMBean"
365                 , asParam, asSignature);
366         }
367         else {
368             throw new Exception JavaDoc(m_Resources.getMessage("error.undeploy.mailfactory.dependences"
369                 , al.toString()));
370         }
371     }
372
373     /**
374      * Deploy a file in using the type of current deployment
375      * storing in WhereAreYou instance in session.
376      *
377      * @param p_Filename Name of file to deploy
378      * @throws Exception
379      */

380     protected void deploy(String JavaDoc p_Filename)
381         throws Exception JavaDoc {
382         String JavaDoc[] asParam = new String JavaDoc[1];
383         asParam[0] = p_Filename;
384         String JavaDoc[] asSignature = new String JavaDoc[1];
385         asSignature[0] = "java.lang.String";
386
387         switch (getCurrentJonasDeployment()) {
388             case WhereAreYou.DEPLOYMENT_EAR:
389                 JonasManagementRepr.invoke(JonasObjectName.earService(), "deployEarMBean", asParam
390                     , asSignature);
391                 break;
392             case WhereAreYou.DEPLOYMENT_JAR:
393                 JonasManagementRepr.invoke(JonasObjectName.ejbService(), "createContainerMBean", asParam
394                     , asSignature);
395                 break;
396             case WhereAreYou.DEPLOYMENT_RAR:
397                 JonasManagementRepr.invoke(JonasObjectName.resourceService(), "deployRarMBean"
398                     , asParam, asSignature);
399                 break;
400             case WhereAreYou.DEPLOYMENT_WAR:
401                 JonasManagementRepr.invoke(JonasObjectName.webContainerService()
402                     , "registerWarMBean", asParam, asSignature);
403                 break;
404             case WhereAreYou.DEPLOYMENT_DATASOURCE:
405                 deployDataSource(p_Filename);
406                 break;
407             case WhereAreYou.DEPLOYMENT_MAIL:
408                 deployMailFactory(p_Filename);
409                 break;
410         }
411     }
412
413     /**
414      * Deploy a datasource file.
415      *
416      * @param p_Filename Name of file to deploy
417      * @throws Exception
418      */

419     protected void deployDataSource(String JavaDoc p_Filename)
420         throws Exception JavaDoc {
421
422         String JavaDoc[] asParam = new String JavaDoc[1];
423         String JavaDoc[] asSignature = new String JavaDoc[1];
424         asParam[0] = p_Filename;
425         asSignature[0] = "java.lang.String";
426
427         ObjectName JavaDoc onDb = JonasObjectName.databaseService();
428         // Verify if datasource already loaded
429
Boolean JavaDoc oLoaded = (Boolean JavaDoc) JonasManagementRepr.invoke(onDb, "isLoadedDataSource", asParam
430             , asSignature);
431         if (oLoaded.booleanValue() == false) {
432             // Get Datasource properties file
433
Properties JavaDoc oProps = (Properties JavaDoc) JonasManagementRepr.invoke(onDb
434                 , "getDataSourcePropertiesFile", asParam, asSignature);
435             // Load Datasource
436
Object JavaDoc[] aoParam = {
437                 p_Filename, oProps, new Boolean JavaDoc(true)};
438             String JavaDoc[] asSign_3 = {
439                 "java.lang.String", "java.util.Properties", "java.lang.Boolean"};
440             JonasManagementRepr.invoke(onDb, "loadDataSource", aoParam, asSign_3);
441         }
442         else {
443             throw new Exception JavaDoc(m_Resources.getMessage("error.deploy.datasource.isloaded"));
444         }
445     }
446
447     /**
448      * Deploy a mail factory.
449      *
450      * @param p_Filename Name of the mail factory whch is also the name of the file
451      * @throws Exception
452      */

453     protected void deployMailFactory(String JavaDoc p_Filename)
454         throws Exception JavaDoc {
455
456         String JavaDoc[] asParam = new String JavaDoc[1];
457         String JavaDoc[] asSignature = new String JavaDoc[1];
458         asParam[0] = p_Filename;
459         asSignature[0] = "java.lang.String";
460
461         ObjectName JavaDoc onMail = JonasObjectName.mailService();
462         // Get mail factory properties file
463
Properties JavaDoc oProps = (Properties JavaDoc) JonasManagementRepr.invoke(onMail
464             , "getMailFactoryPropertiesFile", asParam, asSignature);
465         // Load mail factory
466
Object JavaDoc[] aoParam = {
467             p_Filename, oProps, new Boolean JavaDoc(true)};
468         String JavaDoc[] asSign_3 = {
469             "java.lang.String", "java.util.Properties", "java.lang.Boolean"};
470         JonasManagementRepr.invoke(onMail, "createMailFactoryMBean", aoParam, asSign_3);
471     }
472
473     /**
474      * Run garbage collector.
475      *
476      * @throws Exception
477      */

478     protected void runGC()
479         throws Exception JavaDoc {
480         ObjectName JavaDoc oObjectName = J2eeObjectName.J2EEServer(m_WhereAreYou.getCurrentDomainName()
481             , m_WhereAreYou.getCurrentJonasServerName());
482         JonasManagementRepr.invoke(oObjectName, "runGC", null, null);
483     }
484
485     /**
486      * Refresh the tree.
487      *
488      * @param p_Request The current HTTP Request
489      * @throws Exception
490      */

491     protected void refreshTree(HttpServletRequest JavaDoc p_Request) throws Exception JavaDoc {
492         // Refresh Service Tree
493
switch (getCurrentJonasDeployment()) {
494             case WhereAreYou.DEPLOYMENT_EAR:
495                 refreshServiceTree(WhereAreYou.DEPLOYMENT_EAR, p_Request);
496                 if (JonasAdminJmx.hasMBeanName(JonasObjectName.ejbService()) == true) {
497                     refreshServiceTree(WhereAreYou.DEPLOYMENT_JAR, p_Request);
498                 }
499                 if (JonasAdminJmx.hasMBeanName(JonasObjectName.webContainerService()) == true) {
500                     refreshServiceTree(WhereAreYou.DEPLOYMENT_WAR, p_Request);
501                 }
502                 if (JonasAdminJmx.hasMBeanName(JonasObjectName.resourceService()) == true) {
503                     refreshServiceTree(WhereAreYou.DEPLOYMENT_RAR, p_Request);
504                 }
505                 break;
506             case WhereAreYou.DEPLOYMENT_JAR:
507                 refreshServiceTree(WhereAreYou.DEPLOYMENT_JAR, p_Request);
508                 break;
509             case WhereAreYou.DEPLOYMENT_WAR:
510                 refreshServiceTree(WhereAreYou.DEPLOYMENT_WAR, p_Request);
511                 break;
512             case WhereAreYou.DEPLOYMENT_RAR:
513                 refreshServiceTree(WhereAreYou.DEPLOYMENT_RAR, p_Request);
514                 refreshJoramTree(p_Request);
515                 break;
516             case WhereAreYou.DEPLOYMENT_DATASOURCE:
517                 refreshServiceTree(WhereAreYou.DEPLOYMENT_DATASOURCE, p_Request);
518                 break;
519             case WhereAreYou.DEPLOYMENT_MAIL:
520                 refreshServiceTree(WhereAreYou.DEPLOYMENT_MAIL, p_Request);
521                 break;
522         }
523         // Refresh MBeans Tree
524
refreshMBeansTree();
525         // Force display to refresh
526
m_WhereAreYou.setTreeToRefresh(true);
527     }
528
529     /**
530      * Refresh the service tree.
531      *
532      * @param p_Deployment The type of deployment
533      * @param p_Request The current HTTP Request
534      * @throws Exception
535      */

536     protected void refreshServiceTree(int p_Deployment, HttpServletRequest JavaDoc p_Request)
537         throws Exception JavaDoc {
538         // Get the domain and server name
539
String JavaDoc sDomainLabel = "domain";
540         String JavaDoc sServerName = m_WhereAreYou.getCurrentJonasServerName();
541         // Get the service name
542
String JavaDoc sCurrentNodeNameServiceItem = null;
543         switch (p_Deployment) {
544             case WhereAreYou.DEPLOYMENT_EAR:
545                 sCurrentNodeNameServiceItem = sDomainLabel + WhereAreYou.NODE_SEPARATOR
546                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
547                     + WhereAreYou.NODE_SEPARATOR + "ear";
548                 break;
549             case WhereAreYou.DEPLOYMENT_JAR:
550                 sCurrentNodeNameServiceItem = sDomainLabel + WhereAreYou.NODE_SEPARATOR
551                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
552                     + WhereAreYou.NODE_SEPARATOR + "ejbContainers";
553                 break;
554             case WhereAreYou.DEPLOYMENT_RAR:
555                 sCurrentNodeNameServiceItem = sDomainLabel + WhereAreYou.NODE_SEPARATOR
556                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
557                     + WhereAreYou.NODE_SEPARATOR + "resourceAdapter";
558                 break;
559             case WhereAreYou.DEPLOYMENT_WAR:
560                 sCurrentNodeNameServiceItem = sDomainLabel + WhereAreYou.NODE_SEPARATOR
561                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
562                     + WhereAreYou.NODE_SEPARATOR + "web";
563                 break;
564             case WhereAreYou.DEPLOYMENT_DATASOURCE:
565                 sCurrentNodeNameServiceItem = sDomainLabel + WhereAreYou.NODE_SEPARATOR
566                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
567                     + WhereAreYou.NODE_SEPARATOR + "database";
568                 break;
569             case WhereAreYou.DEPLOYMENT_MAIL:
570                 sCurrentNodeNameServiceItem = sDomainLabel + WhereAreYou.NODE_SEPARATOR
571                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
572                     + WhereAreYou.NODE_SEPARATOR + "mail";
573                 break;
574             case WhereAreYou.DEPLOYMENT_JMS:
575                 sCurrentNodeNameServiceItem = sDomainLabel + WhereAreYou.NODE_SEPARATOR
576                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
577                     + WhereAreYou.NODE_SEPARATOR + "jms";
578                 break;
579         }
580         // Get current tree
581
TreeControl oControl = m_WhereAreYou.getTreeControl();
582         // Get service node
583
TreeControlNode oServiceNode = oControl.findNode(sCurrentNodeNameServiceItem);
584         // Enable auto-refresh mode
585
oControl.enableAutoRefresh();
586         // Remove old children
587
TreeControlNode[] aoNodes = oServiceNode.findChildren();
588         for (int i = 0; i < aoNodes.length; i++) {
589             aoNodes[i].remove();
590         }
591         // Build node for the Service
592
JonasTreeBuilder oBuilder = new JonasTreeBuilder();
593         String JavaDoc sDomainName = m_WhereAreYou.getCurrentDomainName();
594
595         switch (p_Deployment) {
596             case WhereAreYou.DEPLOYMENT_EAR:
597                 oBuilder.getAppContainers(oServiceNode, m_Resources, sDomainName, sServerName);
598                 refreshWebServiceTree(p_Request);
599                 break;
600             case WhereAreYou.DEPLOYMENT_JAR:
601                 oBuilder.getContainers(oServiceNode, m_Resources, sDomainName, sServerName);
602                 break;
603             case WhereAreYou.DEPLOYMENT_RAR:
604                 oBuilder.getResourceAdapters(oServiceNode, m_Resources, sDomainName, sServerName);
605                 break;
606             case WhereAreYou.DEPLOYMENT_WAR:
607                 oBuilder.getWebContainers(oServiceNode, m_Resources, p_Request);
608                 refreshWebServiceTree(p_Request);
609                 break;
610             case WhereAreYou.DEPLOYMENT_DATASOURCE:
611                 oBuilder.getDatasources(oServiceNode, m_Resources, sDomainName, sServerName);
612                 break;
613             case WhereAreYou.DEPLOYMENT_JMS:
614                 oBuilder.getJmsResources(oServiceNode, m_Resources);
615                 break;
616             case WhereAreYou.DEPLOYMENT_MAIL:
617                 oBuilder.getAllSessionMailFactories(oServiceNode, m_Resources, p_Request);
618                 oBuilder.getAllMimePartDSMailFactories(oServiceNode, m_Resources, p_Request);
619                 break;
620         }
621         // Disable auto-refresh mode
622
oControl.disableAutoRefresh();
623     }
624
625     protected void refreshWebServiceTree(HttpServletRequest JavaDoc p_Request) throws Exception JavaDoc {
626         String JavaDoc sServerName = m_WhereAreYou.getCurrentJonasServerName();
627         String JavaDoc sDomainName = m_WhereAreYou.getCurrentDomainName();
628         // Get current tree
629
TreeControl oControl = m_WhereAreYou.getTreeControl();
630         // Build node and his children
631
JonasTreeBuilder oBuilder = new JonasTreeBuilder();
632
633         // Since (un)deployment of ears and wars can add/remove webservices,
634
// this part of the tree needs to be recreated.
635
String JavaDoc sServicesNodeName = "domain" + WhereAreYou.NODE_SEPARATOR + sServerName + WhereAreYou.NODE_SEPARATOR + "services";
636         // The node representing services in the jonasAdmin tree.
637
TreeControlNode services = oControl.findNode(sServicesNodeName);
638         // If any web services are deployed and services node is present in tree.
639
if(JonasAdminJmx.hasMBeanName(JonasObjectName.wsService()) && services != null){
640             // Rebuild the webservices tree.
641
oBuilder.getServiceWebService(services, m_Resources, p_Request, sDomainName, sServerName);
642         }else{
643             TreeControlNode ws = oControl.findNode(sServicesNodeName + WhereAreYou.NODE_SEPARATOR + "WebService");
644             // If a web service node exists in tree already, remove it from there.
645
if(ws!=null){
646                 ws.remove();
647             }
648         }
649     }
650
651     /**
652      * Refresh the MBeans tree.
653      *
654      * @throws Exception
655      */

656     protected void refreshMBeansTree() throws Exception JavaDoc {
657         // Get current tree
658
TreeControl oControl = m_WhereAreYou.getTreeControl();
659         // MBeans node present ?
660
TreeControlNode oMBeansNode = oControl.findNode("domain*mbeans");
661         TreeControlNode oDomainNode= oMBeansNode.getParent();
662         if (oMBeansNode != null) {
663             // Enable auto-refresh mode
664
oControl.enableAutoRefresh();
665             // Remove node
666
oMBeansNode.remove();
667             // Build node and his children
668
JonasTreeBuilder oBuilder = new JonasTreeBuilder();
669             oBuilder.getMBeans(oDomainNode, m_Resources);
670             // Disable auto-refresh mode
671
oControl.disableAutoRefresh();
672         }
673     }
674
675     /**
676      * Refresh the Joram tree.
677      *
678      * @throws Exception
679      */

680     protected void refreshJoramTree(HttpServletRequest JavaDoc p_Request) throws Exception JavaDoc {
681         // Get current tree
682
TreeControl oControl = m_WhereAreYou.getTreeControl();
683         // Joram node present ?
684
String JavaDoc sNodeName = "domain" + WhereAreYou.NODE_SEPARATOR + "joramplatform";
685         TreeControlNode oJoramNode = oControl.findNode(sNodeName);
686         if (oJoramNode != null) {
687             TreeControlNode parentNode = oJoramNode.getParent();
688             // Enable auto-refresh mode
689
oControl.enableAutoRefresh();
690             /*
691             // Remove node
692             oJoramNode.remove();
693             */

694             // Remove old children
695
TreeControlNode[] aoNodes = oJoramNode.findChildren();
696             for (int i = 0; i < aoNodes.length; i++) {
697                 aoNodes[i].remove();
698             }
699             JonasTreeBuilder oBuilder = new JonasTreeBuilder();
700             /*
701             oBuilder.getJoramPlatform(parentNode, m_Resources, p_Request);
702             */

703             oBuilder.getJoramResources(oJoramNode, null, m_Resources, p_Request);
704             // Disable auto-refresh mode
705
oControl.disableAutoRefresh();
706         } else {
707             // Construct tree if necessary
708
String JavaDoc sDomainName = m_WhereAreYou.getCurrentDomainName();
709             TreeControlNode oDomainNode = oControl.findNode(sDomainName);
710             // Enable auto-refresh mode
711
oControl.enableAutoRefresh();
712             // Build node and his children
713
JonasTreeBuilder oBuilder = new JonasTreeBuilder();
714             oBuilder.getJoramPlatform(oDomainNode, m_Resources, p_Request);
715             // Disable auto-refresh mode
716
oControl.disableAutoRefresh();
717         }
718     }
719
720     /**
721      * Remove a given file
722      * @param fileName Name of file to remove
723      * @return true if file has been removed
724      * @throws Exception if remove fails
725      */

726     protected boolean removeFile(String JavaDoc fileName) throws Exception JavaDoc {
727
728         // J2EE server MBean
729
ObjectName JavaDoc j2eeServer = J2eeObjectName.J2EEServer(m_WhereAreYou.getCurrentDomainName(), m_WhereAreYou.getCurrentJonasServerName());
730
731         // invoke method on the MBean
732
Object JavaDoc[] param = new Object JavaDoc[] {fileName};
733         String JavaDoc[] signature = {"java.lang.String"};
734         return ((Boolean JavaDoc) JonasManagementRepr.invoke(j2eeServer, "removeModuleFile", param, signature)).booleanValue();
735     }
736
737 }
738
Popular Tags