Source Code Cross Referenced for JonasAdminJmx.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » webapp » jonasadmin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.webapp.jonasadmin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * JOnAS: Java(TM) Open Application Server
0003:         * Copyright (C) 1999-2004 Bull S.A.
0004:         * Contact: jonas-team@objectweb.org
0005:         *
0006:         * This library is free software; you can redistribute it and/or
0007:         * modify it under the terms of the GNU Lesser General Public
0008:         * License as published by the Free Software Foundation; either
0009:         * version 2.1 of the License, or any later version.
0010:         *
0011:         * This library is distributed in the hope that it will be useful,
0012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014:         * Lesser General Public License for more details.
0015:         *
0016:         * You should have received a copy of the GNU Lesser General Public
0017:         * License along with this library; if not, write to the Free Software
0018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
0019:         * USA
0020:         *
0021:         * --------------------------------------------------------------------------
0022:         * $Id: JonasAdminJmx.java 9864 2006-11-24 10:14:22Z danesa $
0023:         * --------------------------------------------------------------------------
0024:         */package org.objectweb.jonas.webapp.jonasadmin;
0025:
0026:        import java.io.File;
0027:        import java.util.ArrayList;
0028:        import java.util.Collections;
0029:        import java.util.Iterator;
0030:        import java.util.List;
0031:        import java.util.Set;
0032:
0033:        import javax.management.MalformedObjectNameException;
0034:        import javax.management.ObjectName;
0035:        import javax.naming.Context;
0036:        import javax.naming.NameClassPair;
0037:        import javax.naming.NamingEnumeration;
0038:        import javax.naming.NamingException;
0039:        import javax.servlet.http.HttpServletRequest;
0040:
0041:        import org.apache.struts.util.MessageResources;
0042:        import org.objectweb.jonas.jmx.J2eeObjectName;
0043:        import org.objectweb.jonas.jmx.JonasManagementRepr;
0044:        import org.objectweb.jonas.jmx.JonasObjectName;
0045:        import org.objectweb.jonas.jmx.ManagementException;
0046:        import org.objectweb.jonas.mail.MailServiceImpl;
0047:        import org.objectweb.jonas.jmx.CatalinaObjectName;
0048:        import org.objectweb.jonas.webapp.jonasadmin.common.BeanComparator;
0049:        import org.objectweb.jonas.webapp.jonasadmin.logging.LoggerItem;
0050:        import org.objectweb.jonas.webapp.jonasadmin.mbean.MbeanItem;
0051:        import org.objectweb.jonas.webapp.jonasadmin.service.container.WebAppItem;
0052:
0053:        /**
0054:         * Helper class supporting manipulation of MBeans (accessing MBeans).
0055:         * @author Michel-Ange ANTON<p>
0056:         * Contributors: Adriana Danes
0057:         */
0058:        public class JonasAdminJmx {
0059:
0060:            // ----------------------------------------------------------- Constants
0061:
0062:            private static Object s_Synchro = new Object();
0063:
0064:            // ----------------------------------------------------------- Constructors
0065:
0066:            /**
0067:             * Protected constructor to prevent instantiation.
0068:             */
0069:            protected JonasAdminJmx() {
0070:            }
0071:
0072:            // --------------------------------------------------------- Public Methods
0073:
0074:            /**
0075:             * Replace any occurrence of the specified placeholder in the specified
0076:             * template string with the specified replacement value.
0077:             *
0078:             * @param template Pattern string possibly containing the placeholder
0079:             * @param placeholder Placeholder expression to be replaced
0080:             * @param value Replacement value for the placeholder
0081:             * @return A complete string
0082:             */
0083:            public static String replace(String template, String placeholder,
0084:                    String value) {
0085:                if (template == null) {
0086:                    return (null);
0087:                }
0088:                if ((placeholder == null) || (value == null)) {
0089:                    return (template);
0090:                }
0091:                String sRet = new String(template);
0092:                while (true) {
0093:                    int index = sRet.indexOf(placeholder);
0094:                    if (index < 0) {
0095:                        break;
0096:                    }
0097:                    StringBuffer temp = new StringBuffer(sRet.substring(0,
0098:                            index));
0099:                    temp.append(value);
0100:                    temp.append(sRet.substring(index + placeholder.length()));
0101:                    sRet = temp.toString();
0102:                }
0103:                return (sRet);
0104:
0105:            }
0106:
0107:            /**
0108:             * Return the ObjectName corresponding to the J2EEDomain managed object registered in the
0109:             * current MBeanServer. Normally, we should have only one which has not the property 'clusterName'
0110:             * @return an ObjectName which corresponds to the first J2EEDomain ObjectName pattern
0111:             */
0112:            public static ObjectName getJ2eeDomainObjectName(String serverName) {
0113:                // Lookup for the domain J2EEDomain managed object in the current MBeanServer
0114:                ObjectName onDomains = J2eeObjectName.J2EEDomains();
0115:                synchronized (s_Synchro) {
0116:                    ArrayList al = new ArrayList();
0117:                    Iterator itNames = JonasManagementRepr.queryNames(
0118:                            onDomains, serverName).iterator();
0119:                    while (itNames.hasNext()) {
0120:                        ObjectName item = (ObjectName) itNames.next();
0121:                        if (item.getKeyProperty("clusterName") == null) {
0122:                            return item;
0123:                        }
0124:                    }
0125:                    return null;
0126:                }
0127:            }
0128:
0129:            public static ObjectName getArchiveConfigObjectName(
0130:                    String serverName) {
0131:                ObjectName onUtils = JonasObjectName.ArchiveConfig();
0132:                return getFirstMbean(onUtils, serverName);
0133:            }
0134:
0135:            public static ObjectName getRarConfigObjectName(String serverName) {
0136:                ObjectName onUtils = JonasObjectName.RarConfig();
0137:                return getFirstMbean(onUtils, serverName);
0138:            }
0139:
0140:            /**
0141:             * Return the ObjectName corresponding to the J2EEServer managed object registered in the
0142:             * current MBeanServer and belonging to a domain.
0143:             * We should have one ObjectName corresponding to the current JOnAS server instance.
0144:             * @param p_DomainName The name of the management domain.
0145:             * @return an ObjectName which corresponds to a J2EEServer ObjectName pattern or null if
0146:             * no J2EEServer found for the given management domain
0147:             * (having <code>j2eeType</code> key property equal to <code>J2EEServer</code>)
0148:             * @throws ManagementException if could not connect to the MBean server
0149:             */
0150:            public static ObjectName getJ2eeServerObjectName(
0151:                    String p_DomainName, String serverName)
0152:                    throws ManagementException {
0153:                // Lookup for a J2EEServer managed object in the current MBeanServer
0154:                ObjectName pattern_server_on = J2eeObjectName
0155:                        .J2EEServers(p_DomainName);
0156:                ObjectName server_on = null;
0157:                Iterator it = JonasManagementRepr.queryNames(pattern_server_on,
0158:                        serverName).iterator();
0159:                if (it.hasNext()) {
0160:                    // Got one J2EEServer managed object ; normally should not be more than one
0161:                    server_on = (ObjectName) it.next();
0162:                }
0163:                return server_on;
0164:            }
0165:
0166:            /**
0167:             * Return the ObjectName corresponding to the J2EEServer managed object registered in the
0168:             * current MBeanServer. This method is used by EditTopAction to determine the list of
0169:             * JOnAS servers registered in the current registry (this code is particular to the current
0170:             * domain concept implementation).
0171:             * We should have one ObjectName corresponding to the current JOnAS server instance.
0172:             * @return an ObjectName which corresponds to a J2EEServer ObjectName pattern
0173:             * (having <code>j2eeType</code> key property equal to <code>J2EEServer</code>)
0174:             */
0175:            public static ObjectName getJ2eeServerObjectName(String serverName) {
0176:                // Lookup for a J2EEServer managed object in the current MBeanServer
0177:                ObjectName pattern_server_on = J2eeObjectName.J2EEServers();
0178:                ObjectName server_on = null;
0179:                Iterator it = JonasManagementRepr.queryNames(pattern_server_on,
0180:                        serverName).iterator();
0181:                if (it.hasNext()) {
0182:                    // Got one J2EEServer managed object ; normally should not be more than one
0183:                    server_on = (ObjectName) it.next();
0184:                }
0185:                return server_on;
0186:            }
0187:
0188:            /**
0189:             * Verify if the Mbean gotten by the query in the current MbeanServer exists.
0190:             *
0191:             * @param p_On Query Mbean name to search
0192:             * @return true if MBean exists
0193:             * @throws ManagementException
0194:             */
0195:            public static boolean hasMBeanName(ObjectName p_On,
0196:                    String serverName) throws ManagementException {
0197:                synchronized (s_Synchro) {
0198:                    ArrayList al = new ArrayList();
0199:                    Iterator itNames = JonasManagementRepr.queryNames(p_On,
0200:                            serverName).iterator();
0201:                    if (itNames.hasNext()) {
0202:                        return true;
0203:                    }
0204:                    return false;
0205:                }
0206:            }
0207:
0208:            /**
0209:             * Return the first Mbean name gotten by the query in the current MbeanServer.
0210:             *
0211:             * @param p_On Query Mbean name to search
0212:             * @return The first MBean name or null if not found
0213:             * @throws ManagementException
0214:             */
0215:            public static String getFirstMBeanName(ObjectName p_On,
0216:                    String serverName) throws ManagementException {
0217:                synchronized (s_Synchro) {
0218:                    ArrayList al = new ArrayList();
0219:                    Iterator itNames = JonasManagementRepr.queryNames(p_On,
0220:                            serverName).iterator();
0221:                    if (itNames.hasNext()) {
0222:                        return itNames.next().toString();
0223:                    }
0224:                    return null;
0225:                }
0226:            }
0227:
0228:            /**
0229:             * Return the list of Mbean name gotten by the query in the current MbeanServer.
0230:             *
0231:             * @param p_On Query Mbean name to search
0232:             * @return A list of string Mbean name
0233:             * @throws ManagementException
0234:             */
0235:            public static List getListMBeanName(ObjectName p_On,
0236:                    String serverName) throws ManagementException {
0237:                synchronized (s_Synchro) {
0238:                    ArrayList al = new ArrayList();
0239:                    Iterator itNames = JonasManagementRepr.queryNames(p_On,
0240:                            serverName).iterator();
0241:                    while (itNames.hasNext()) {
0242:                        ObjectName item = (ObjectName) itNames.next();
0243:                        al.add(item.toString());
0244:                    }
0245:                    Collections.sort(al);
0246:                    return al;
0247:                }
0248:            }
0249:
0250:            /**
0251:             * Return the first <code>ObjectName</code> Mbean gotten by the query
0252:             * in the current MbeanServer.
0253:             *
0254:             * @param p_On Query Mbean name to search
0255:             * @return The first <code>ObjectName</code> or null if not found
0256:             * @throws ManagementException
0257:             */
0258:            public static ObjectName getFirstMbean(ObjectName p_On,
0259:                    String serverName) throws ManagementException {
0260:                synchronized (s_Synchro) {
0261:                    Iterator itNames = JonasManagementRepr.queryNames(p_On,
0262:                            serverName).iterator();
0263:                    if (itNames.hasNext()) {
0264:                        return (ObjectName) itNames.next();
0265:                    }
0266:                    return null;
0267:                }
0268:            }
0269:
0270:            /**
0271:             * Return the list of <code>ObjectName</code> Mbean gotten by the query
0272:             * in the current MbeanServer.
0273:             *
0274:             * @param p_On Query Mbeans to search
0275:             * @return The list of <code>ObjectName</code>
0276:             * @throws ManagementException
0277:             */
0278:            public static List getListMbean(ObjectName p_On, String serverName)
0279:                    throws ManagementException {
0280:                synchronized (s_Synchro) {
0281:                    ArrayList al = new ArrayList();
0282:                    Iterator itNames = JonasManagementRepr.queryNames(p_On,
0283:                            serverName).iterator();
0284:                    while (itNames.hasNext()) {
0285:                        al.add(itNames.next());
0286:                    }
0287:                    return al;
0288:                }
0289:            }
0290:
0291:            /**
0292:             * Extract the value of a key property from the MBean name.
0293:             * This method is usefull when we have the String form and not the ObjectName
0294:             * (avoid creating an ObjectName instance).
0295:             * @param pName Name of the key property
0296:             * @param pMBeanName Stringified ObjectName
0297:             * @return The value or null if not found
0298:             */
0299:            public static String extractValueMbeanName(String pName,
0300:                    String pMBeanName) {
0301:                String sValue = null;
0302:                try {
0303:                    String sSearch = pName.trim() + "=";
0304:                    int iPos = pMBeanName.indexOf(sSearch);
0305:                    if (iPos > -1) {
0306:                        sValue = pMBeanName.substring(iPos + sSearch.length());
0307:                        iPos = sValue.indexOf(",");
0308:                        if (iPos > -1) {
0309:                            sValue = sValue.substring(0, iPos);
0310:                        }
0311:                    }
0312:                } catch (NullPointerException e) {
0313:                    // none
0314:                    sValue = null;
0315:                }
0316:                return sValue;
0317:            }
0318:
0319:            /**
0320:             * Extract the filename of complete path.
0321:             *
0322:             * @param p_Path Complete path (directory and filename)
0323:             * @return The filename or null
0324:             */
0325:            public static String extractFilename(String p_Path) {
0326:                String sFilename = null;
0327:                try {
0328:                    int iPosSeparator = p_Path.lastIndexOf("/");
0329:                    if (iPosSeparator < 0) {
0330:                        iPosSeparator = p_Path.lastIndexOf("\\");
0331:                        if (iPosSeparator < 0) {
0332:                            sFilename = new String(p_Path);
0333:                        } else {
0334:                            sFilename = p_Path.substring(iPosSeparator + 1);
0335:                        }
0336:                    } else {
0337:                        sFilename = p_Path.substring(iPosSeparator + 1);
0338:                    }
0339:                    if (sFilename.length() > 0) {
0340:                        int iPos_1 = p_Path.indexOf(DIR_AUTOLOAD + "/"
0341:                                + sFilename);
0342:                        int iPos_2 = p_Path.indexOf(DIR_AUTOLOAD + "\\"
0343:                                + sFilename);
0344:                        if (iPos_1 > -1) {
0345:                            sFilename = DIR_AUTOLOAD + "/" + sFilename;
0346:                        } else if (iPos_2 > -1) {
0347:                            sFilename = DIR_AUTOLOAD + "\\" + sFilename;
0348:                        }
0349:                    } else {
0350:                        sFilename = null;
0351:                    }
0352:                } catch (NullPointerException e) {
0353:                    // none action
0354:                    sFilename = null;
0355:                }
0356:                return sFilename;
0357:            }
0358:
0359:            /**
0360:             *
0361:             */
0362:            private static String DIR_RARS = "rars";
0363:            private static String DIR_AUTOLOAD = "autoload";
0364:            private static String DIR_CONF = "conf";
0365:
0366:            private static ArrayList getFilenames(String p_Directory,
0367:                    String p_Extension) {
0368:                ArrayList al = new ArrayList();
0369:                String sExt = "." + p_Extension.toLowerCase();
0370:                String sFile;
0371:
0372:                File oFile = new File(p_Directory);
0373:                String[] asFiles = oFile.list();
0374:                int iPos;
0375:                if (asFiles != null) {
0376:                    for (int i = 0; i < asFiles.length; i++) {
0377:                        oFile = new File(p_Directory, asFiles[i]);
0378:                        if (oFile.isFile() == true) {
0379:                            sFile = oFile.getName().toLowerCase();
0380:                            iPos = sFile.lastIndexOf(sExt);
0381:                            if (iPos > -1) {
0382:                                if (iPos == (sFile.length() - sExt.length())) {
0383:                                    al.add(oFile.getName());
0384:                                }
0385:                            }
0386:                        }
0387:                    }
0388:                }
0389:                Collections.sort(al);
0390:                return al;
0391:            }
0392:
0393:            private static ArrayList getDirectories(String p_Directory) {
0394:                ArrayList al = new ArrayList();
0395:                String sFile;
0396:
0397:                File oFile = new File(p_Directory);
0398:                String[] asFiles = oFile.list();
0399:
0400:                if (asFiles != null) {
0401:                    for (int i = 0; i < asFiles.length; i++) {
0402:                        oFile = new File(p_Directory, asFiles[i]);
0403:                        if (oFile.isDirectory() == true) {
0404:                            al.add(oFile.getName());
0405:                        }
0406:                    }
0407:                }
0408:                Collections.sort(al);
0409:                return al;
0410:            }
0411:
0412:            private static void appendDirectory(ArrayList p_List, String p_Dir) {
0413:                String sDir = p_Dir + "/";
0414:                for (int i = 0; i < p_List.size(); i++) {
0415:                    p_List.set(i, sDir + p_List.get(i));
0416:                }
0417:            }
0418:
0419:            /**
0420:             * Return the list of JAR filename ready to deploy in the current server.
0421:             *
0422:             * @return The list of JAR filename.
0423:             * @throws ManagementException
0424:             */
0425:            public static ArrayList getJarFilesDeployable(String serverName)
0426:                    throws ManagementException {
0427:                ObjectName on = JonasObjectName.ejbService();
0428:                ArrayList al = (ArrayList) JonasManagementRepr.getAttribute(on,
0429:                        "DeployableJars", serverName);
0430:                String sDir = (String) JonasManagementRepr.getAttribute(on,
0431:                        "EjbjarsDirectory", serverName);
0432:
0433:                String sEarDir = null;
0434:                try {
0435:                    on = JonasObjectName.earService();
0436:                    sEarDir = (String) JonasManagementRepr.getAttribute(on,
0437:                            "AppsDirectory", serverName);
0438:                } catch (Exception e) {
0439:                    // nothing, Ear service not found
0440:                }
0441:                return prepareContainersToDisplay(al, sDir, sEarDir);
0442:            }
0443:
0444:            /**
0445:             * Return the list of RAR filename ready to deploy in the current server.
0446:             *
0447:             * @return The list of RAR filename.
0448:             * @throws ManagementException
0449:             */
0450:            public static ArrayList getRarFilesDeployable(String serverName)
0451:                    throws ManagementException {
0452:                ObjectName on = JonasObjectName.resourceService();
0453:                ArrayList al = (ArrayList) JonasManagementRepr.getAttribute(on,
0454:                        "DeployableRars", serverName);
0455:                String sDir = (String) JonasManagementRepr.getAttribute(on,
0456:                        "RarsDirectory", serverName);
0457:
0458:                String sEarDir = null;
0459:                try {
0460:                    on = JonasObjectName.earService();
0461:                    sEarDir = (String) JonasManagementRepr.getAttribute(on,
0462:                            "AppsDirectory", serverName);
0463:                } catch (Exception e) {
0464:                    // nothing, Ear service not found
0465:                }
0466:                return prepareContainersToDisplay(al, sDir, sEarDir);
0467:            }
0468:
0469:            /**
0470:             * Return the list of EAR filename ready to deploy in the current server.
0471:             *
0472:             * @return The list of EAR filename.
0473:             * @throws ManagementException
0474:             */
0475:            public static ArrayList getEarFilesDeployable(String serverName)
0476:                    throws ManagementException {
0477:                ObjectName on = JonasObjectName.earService();
0478:                ArrayList al = (ArrayList) JonasManagementRepr.getAttribute(on,
0479:                        "DeployableEars", serverName);
0480:                String sDir = (String) JonasManagementRepr.getAttribute(on,
0481:                        "AppsDirectory", serverName);
0482:                return prepareContainersToDisplay(al, sDir, null);
0483:            }
0484:
0485:            /**
0486:             * Return the list of WAR filename ready to deploy in the current server.
0487:             *
0488:             * @return The list of WAR filename.
0489:             * @throws ManagementException
0490:             */
0491:            public static ArrayList getWarFilesDeployable(String serverName)
0492:                    throws ManagementException {
0493:                ObjectName on = JonasObjectName.webContainerService();
0494:                ArrayList al = (ArrayList) JonasManagementRepr.getAttribute(on,
0495:                        "DeployableWars", serverName);
0496:                String sDir = (String) JonasManagementRepr.getAttribute(on,
0497:                        "WebappsDirectory", serverName);
0498:
0499:                String sEarDir = null;
0500:                try {
0501:                    on = JonasObjectName.earService();
0502:                    sEarDir = (String) JonasManagementRepr.getAttribute(on,
0503:                            "AppsDirectory", serverName);
0504:                } catch (Exception e) {
0505:                    // nothing, Ear service not found
0506:                }
0507:                return prepareContainersToDisplay(al, sDir, sEarDir);
0508:            }
0509:
0510:            /**
0511:             * Return the list of deployed JAR filename in the current server.
0512:             *
0513:             * @return The list of JAR filename.
0514:             * @throws ManagementException
0515:             */
0516:            public static ArrayList getJarFilesDeployed(String serverName)
0517:                    throws ManagementException {
0518:                ObjectName on = JonasObjectName.ejbService();
0519:                ArrayList al = (ArrayList) JonasManagementRepr.getAttribute(on,
0520:                        "DeployedJars", serverName);
0521:                String sDir = (String) JonasManagementRepr.getAttribute(on,
0522:                        "EjbjarsDirectory", serverName);
0523:
0524:                String sEarDir = null;
0525:                try {
0526:                    on = JonasObjectName.earService();
0527:                    sEarDir = (String) JonasManagementRepr.getAttribute(on,
0528:                            "AppsDirectory", serverName);
0529:                } catch (Exception e) {
0530:                    // nothing, Ear service not found
0531:                }
0532:                return prepareContainersToDisplay(al, sDir, sEarDir);
0533:            }
0534:
0535:            /**
0536:             * Return the list of deployed EAR filename in the current server.
0537:             *
0538:             * @return The list of EAR filename.
0539:             * @throws ManagementException
0540:             */
0541:            public static ArrayList getEarFilesDeployed(String serverName)
0542:                    throws ManagementException {
0543:                ObjectName on = JonasObjectName.earService();
0544:                ArrayList al = (ArrayList) JonasManagementRepr.getAttribute(on,
0545:                        "DeployedEars", serverName);
0546:                String sDir = (String) JonasManagementRepr.getAttribute(on,
0547:                        "AppsDirectory", serverName);
0548:                return prepareContainersToDisplay(al, sDir, null);
0549:            }
0550:
0551:            /**
0552:             * Return the list of deployed RAR filename in the current server.
0553:             *
0554:             * @return The list of RAR filename.
0555:             * @throws ManagementException
0556:             */
0557:            public static ArrayList getRarFilesDeployed(String serverName)
0558:                    throws ManagementException {
0559:                ObjectName on = JonasObjectName.resourceService();
0560:                ArrayList al = (ArrayList) JonasManagementRepr.getAttribute(on,
0561:                        "DeployedRars", serverName);
0562:                String sDir = (String) JonasManagementRepr.getAttribute(on,
0563:                        "RarsDirectory", serverName);
0564:
0565:                String sEarDir = null;
0566:                try {
0567:                    on = JonasObjectName.earService();
0568:                    sEarDir = (String) JonasManagementRepr.getAttribute(on,
0569:                            "AppsDirectory", serverName);
0570:                } catch (ManagementException e) {
0571:                    // nothing, Ear service not found
0572:                }
0573:                return prepareContainersToDisplay(al, sDir, sEarDir);
0574:            }
0575:
0576:            /**
0577:             * Return the list of deployed WAR filename in the current server.
0578:             *
0579:             * @return The list of WAR filename.
0580:             * @throws ManagementException
0581:             */
0582:            public static ArrayList getWarFilesDeployed(String serverName)
0583:                    throws ManagementException {
0584:                ObjectName on = JonasObjectName.webContainerService();
0585:                ArrayList al = (ArrayList) JonasManagementRepr.getAttribute(on,
0586:                        "DeployedWars", serverName);
0587:                String sDir = (String) JonasManagementRepr.getAttribute(on,
0588:                        "WebappsDirectory", serverName);
0589:
0590:                String sEarDir = null;
0591:                try {
0592:                    on = JonasObjectName.earService();
0593:                    sEarDir = (String) JonasManagementRepr.getAttribute(on,
0594:                            "AppsDirectory", serverName);
0595:                } catch (ManagementException e) {
0596:                    // nothing, Ear service not found
0597:                }
0598:                return prepareContainersToDisplay(al, sDir, sEarDir);
0599:            }
0600:
0601:            /**
0602:             * Prepare a list of containers to diplay.
0603:             * Deleting prefix root container directory, sorting the list.
0604:             * @param p_Containers The list of containers
0605:             * @param p_ContainerDir The root container directory
0606:             * @param p_EarDir The root ear directory or null
0607:             * @return The list of containers ready to display
0608:             */
0609:            public static ArrayList prepareContainersToDisplay(
0610:                    ArrayList p_Containers, String p_ContainerDir,
0611:                    String p_EarDir) {
0612:                int iPos;
0613:                String sPath;
0614:                boolean bAdd;
0615:                ArrayList al = new ArrayList();
0616:                for (int i = 0; i < p_Containers.size(); i++) {
0617:                    // Delete prefix root container directory
0618:                    sPath = p_Containers.get(i).toString();
0619:                    iPos = sPath.indexOf(p_ContainerDir);
0620:                    if (iPos > -1) {
0621:                        sPath = sPath.substring(p_ContainerDir.length());
0622:                    }
0623:                    // Delete suffix slash
0624:                    if (sPath.endsWith("/") == true) {
0625:                        sPath = sPath.substring(0, sPath.length() - 1);
0626:                    }
0627:                    // Flag to filter
0628:                    bAdd = true;
0629:                    // Filter Jar or War include in Ear
0630:                    if (p_EarDir != null) {
0631:                        iPos = sPath.indexOf(p_EarDir);
0632:                        if (iPos > -1) {
0633:                            bAdd = false;
0634:                        }
0635:
0636:                    }
0637:                    if (bAdd == true) {
0638:                        al.add(sPath);
0639:                    }
0640:                }
0641:                // Sort
0642:                Collections.sort(al);
0643:                return al;
0644:            }
0645:
0646:            private static ArrayList getFilesDeployed(ObjectName on,
0647:                    String serverName) throws ManagementException {
0648:                ArrayList alDeployed = new ArrayList();
0649:                String sPath;
0650:                String sFile;
0651:                Iterator itNames = JonasAdminJmx.getListMBeanName(on,
0652:                        serverName).iterator();
0653:                while (itNames.hasNext()) {
0654:                    sPath = JonasAdminJmx.extractValueMbeanName("fname",
0655:                            itNames.next().toString());
0656:                    sFile = JonasAdminJmx.extractFilename(sPath);
0657:                    if (sFile != null) {
0658:                        alDeployed.add(sFile);
0659:                    }
0660:                }
0661:                Collections.sort(alDeployed);
0662:                return alDeployed;
0663:
0664:            }
0665:
0666:            /**
0667:             * Return the list of Mail factory files ready to deploy in the current server.
0668:             *
0669:             * @return The list of Mail factory properties filenames.
0670:             * @throws ManagementException
0671:             */
0672:            public static ArrayList getMailFilesDeployable(String serverName)
0673:                    throws ManagementException {
0674:                ObjectName on = JonasObjectName.mailService();
0675:                return (ArrayList) JonasManagementRepr.getAttribute(on,
0676:                        "MailFactoryPropertiesFiles", serverName);
0677:            }
0678:
0679:            /**
0680:             * Return the list of MimePartDataSource Mail factory files ready to deploy in the current server.
0681:             *
0682:             * @return The list of MimePartDataSource Mail factory properties filenames.
0683:             * @throws ManagementException
0684:             */
0685:            public static ArrayList getMimePartMailFilesDeployable(
0686:                    String serverName) throws ManagementException {
0687:                ObjectName on = JonasObjectName.mailService();
0688:                return (ArrayList) JonasManagementRepr.getAttribute(on,
0689:                        "MimePartMailFactoryPropertiesFiles", serverName);
0690:            }
0691:
0692:            /**
0693:             * Return the list of Session Mail factory files ready to deploy in the current server.
0694:             *
0695:             * @return The list of Session Mail factory properties filenames.
0696:             * @throws ManagementException
0697:             */
0698:            public static ArrayList getSessionMailFilesDeployable(
0699:                    String serverName) throws ManagementException {
0700:                ObjectName on = JonasObjectName.mailService();
0701:                return (ArrayList) JonasManagementRepr.getAttribute(on,
0702:                        "SessionMailFactoryPropertiesFiles", serverName);
0703:            }
0704:
0705:            /**
0706:             * Return the list of deployed MimePartDataSource Mail factories in the current server.
0707:             *
0708:             * @param p_WhereAreYou The container WhereAreYou
0709:             * @return The list of MimePartDataSource Mail factory filename.
0710:             * @throws ManagementException
0711:             */
0712:            public static ArrayList getMimePartMailFilesDeployed(
0713:                    WhereAreYou p_WhereAreYou) throws ManagementException {
0714:                ArrayList alDeployed = new ArrayList();
0715:                String sName;
0716:                String domainName = p_WhereAreYou.getCurrentDomainName();
0717:                String serverName = p_WhereAreYou.getCurrentJonasServerName();
0718:                ObjectName on = J2eeObjectName.JavaMailResources(domainName,
0719:                        serverName, MailServiceImpl.MIMEPART_PROPERTY_TYPE);
0720:                Iterator itNames = JonasManagementRepr.queryNames(on,
0721:                        serverName).iterator();
0722:                while (itNames.hasNext()) {
0723:                    ObjectName it_on = (ObjectName) itNames.next();
0724:                    sName = it_on.getKeyProperty("name");
0725:                    if (sName != null) {
0726:                        alDeployed.add(sName);
0727:                    }
0728:                }
0729:                Collections.sort(alDeployed);
0730:                return alDeployed;
0731:            }
0732:
0733:            /**
0734:             * Return the list of deployed Session Mail factories in the current server.
0735:             *
0736:             * @param p_WhereAreYou The container WhereAreYou
0737:             * @return The list of Session Mail factory filename.
0738:             * @throws ManagementException
0739:             */
0740:            public static ArrayList getSessionMailFilesDeployed(
0741:                    WhereAreYou p_WhereAreYou) throws ManagementException {
0742:                ArrayList alDeployed = new ArrayList();
0743:                String sName;
0744:                String domainName = p_WhereAreYou.getCurrentDomainName();
0745:                String serverName = p_WhereAreYou.getCurrentJonasServerName();
0746:                ObjectName on = J2eeObjectName.JavaMailResources(domainName,
0747:                        serverName, MailServiceImpl.SESSION_PROPERTY_TYPE);
0748:                Iterator itNames = JonasManagementRepr.queryNames(on,
0749:                        serverName).iterator();
0750:                while (itNames.hasNext()) {
0751:                    ObjectName it_on = (ObjectName) itNames.next();
0752:                    sName = it_on.getKeyProperty("name");
0753:                    if (sName != null) {
0754:                        alDeployed.add(sName);
0755:                    }
0756:                }
0757:                Collections.sort(alDeployed);
0758:                return alDeployed;
0759:            }
0760:
0761:            /**
0762:             * Return the list of deployed Mail factories in the current server.
0763:             *
0764:             * @param p_WhereAreYou The container WhereAreYou
0765:             * @return The list of Mail factory filename.
0766:             * @throws ManagementException
0767:             */
0768:            public static ArrayList getMailFilesDeployed(
0769:                    WhereAreYou p_WhereAreYou) throws ManagementException {
0770:                ArrayList alDeployed = getSessionMailFilesDeployed(p_WhereAreYou);
0771:                alDeployed.addAll(getMimePartMailFilesDeployed(p_WhereAreYou));
0772:                Collections.sort(alDeployed);
0773:                return alDeployed;
0774:            }
0775:
0776:            /**
0777:             * Return the list of Datasource properties files ready to deploy in the current server.
0778:             *
0779:             * @return The list of Datasource properties filenames.
0780:             * @throws ManagementException Could not get managzement info from the MBeanServer
0781:             */
0782:            public static ArrayList getDatasourceFilesDeployable(
0783:                    String serverName) throws ManagementException {
0784:                ObjectName on = JonasObjectName.databaseService();
0785:                return (ArrayList) JonasManagementRepr.getAttribute(on,
0786:                        "DataSourcePropertiesFiles", serverName);
0787:            }
0788:
0789:            /**
0790:             * Return the list of deployed Datasources in the current server.
0791:             * @param domainName Current domain name
0792:             * @param serverName Current server name
0793:             * @return The list of Datasource filename.
0794:             * @throws ManagementException Could not get managzement info from the MBeanServer
0795:             */
0796:            public static ArrayList getDatasourceFilesDeployed(
0797:                    String domainName, String serverName)
0798:                    throws ManagementException {
0799:
0800:                ArrayList alDeployed = new ArrayList();
0801:                ObjectName ons = J2eeObjectName.JDBCDataSources(domainName,
0802:                        serverName);
0803:                // iterate ovent the JDBCDataSources within the current server
0804:                Iterator itNames = JonasManagementRepr.queryNames(ons,
0805:                        serverName).iterator();
0806:                String sName = null;
0807:                while (itNames.hasNext()) {
0808:                    ObjectName on = (ObjectName) itNames.next();
0809:                    sName = on.getKeyProperty("name");
0810:                    if (sName != null) {
0811:                        alDeployed.add(sName);
0812:                    }
0813:                }
0814:                Collections.sort(alDeployed);
0815:                return alDeployed;
0816:            }
0817:
0818:            /**
0819:             * Return the list of Datasource dependences for a given datasource name in the current server.
0820:             *
0821:             * @param pDatasourceName The name of the datasource
0822:             * @param domainName Current domain name
0823:             * @param serverName Current server name
0824:             * @return The list of Datasource dependence (a list of names corresponding to EJBs using this datasource).
0825:             * @throws ManagementException Could not get managzement info from the MBeanServer
0826:             * @throws MalformedObjectNameException
0827:             */
0828:            public static ArrayList getDatasourceDependences(
0829:                    String pDatasourceName, String domainName, String serverName)
0830:                    throws ManagementException {
0831:                ObjectName jdbcDatasource = J2eeObjectName.getJDBCDataSource(
0832:                        domainName, serverName, pDatasourceName);
0833:                String[] asParam = new String[1];
0834:                String[] asSignature = new String[1];
0835:                asSignature[0] = "java.lang.String";
0836:                ArrayList al = new ArrayList();
0837:                asParam[0] = (String) JonasManagementRepr.getAttribute(
0838:                        jdbcDatasource, "jndiName", serverName);
0839:                if (JonasManagementRepr.isRegistered(JonasObjectName
0840:                        .ejbService(), serverName)) {
0841:                    String sName;
0842:                    Iterator it = ((java.util.Set) JonasManagementRepr.invoke(
0843:                            JonasObjectName.ejbService(),
0844:                            "getDataSourceDependence", asParam, asSignature,
0845:                            serverName)).iterator();
0846:                    while (it.hasNext()) {
0847:                        sName = JonasAdminJmx.extractValueMbeanName(",name", it
0848:                                .next().toString());
0849:                        if (sName != null) {
0850:                            al.add(sName);
0851:                        }
0852:                    }
0853:                    Collections.sort(al);
0854:                }
0855:                return al;
0856:            }
0857:
0858:            /**
0859:             * Return the list of Mail factory dependences in the current server for a given factory name.
0860:             *
0861:             * @param p_MailFactoryName The name of the mail factory
0862:             * @param p_WhereAreYou The container WhereAreYou
0863:             * @return The list of Mail factory dependences (a list of names corresponding to EJBs using this mail factory).
0864:             * @throws ManagementException
0865:             */
0866:            public static ArrayList getMailFactoryDependences(
0867:                    String p_MailFactoryName, WhereAreYou p_WhereAreYou)
0868:                    throws ManagementException {
0869:                String jndiName = null;
0870:                String domainName = p_WhereAreYou.getCurrentDomainName();
0871:                String serverName = p_WhereAreYou.getCurrentJonasServerName();
0872:                String type = MailServiceImpl.SESSION_PROPERTY_TYPE;
0873:                // create an MBean name with the given MailFactory name
0874:                // - try with a session Mail Factory type
0875:                ObjectName on = J2eeObjectName.JavaMailResource(domainName,
0876:                        p_MailFactoryName, serverName, type);
0877:                //ObjectName on = JonasObjectName.sessionMailFactory(p_MailFactoryName);
0878:                if (JonasManagementRepr.isRegistered(on, serverName) != true) {
0879:                    // in this case, this is a MimePartDataSource mail factory
0880:                    //on = JonasObjectName.mimeMailFactory(p_MailFactoryName);
0881:                    type = MailServiceImpl.MIMEPART_PROPERTY_TYPE;
0882:                    on = J2eeObjectName.JavaMailResource(domainName,
0883:                            p_MailFactoryName, serverName, type);
0884:                }
0885:                jndiName = (String) JonasManagementRepr.getAttribute(on,
0886:                        "Name", serverName);
0887:
0888:                String[] asParam = new String[1];
0889:                String[] asSignature = new String[1];
0890:                asSignature[0] = "java.lang.String";
0891:                ArrayList al = new ArrayList();
0892:                asParam[0] = jndiName;
0893:                if (JonasManagementRepr.isRegistered(JonasObjectName
0894:                        .ejbService(), serverName) == true) {
0895:                    String sName;
0896:                    Iterator it = ((java.util.Set) JonasManagementRepr.invoke(
0897:                            JonasObjectName.ejbService(),
0898:                            "getMailFactoryDependence", asParam, asSignature,
0899:                            serverName)).iterator();
0900:                    while (it.hasNext()) {
0901:                        sName = JonasAdminJmx.extractValueMbeanName(",name", it
0902:                                .next().toString());
0903:                        if (sName != null) {
0904:                            al.add(sName);
0905:                        }
0906:                    }
0907:                    Collections.sort(al);
0908:                }
0909:                return al;
0910:            }
0911:
0912:            /**
0913:             * Return the list of deployed Session Mail Factories in the current server.
0914:             *
0915:             * @param p_WhereAreYou The container WhereAreYou
0916:             * @return The list
0917:             * @throws ManagementException
0918:             */
0919:            public static ArrayList getSessionMailFactoriesDeployed(
0920:                    WhereAreYou p_WhereAreYou) throws ManagementException {
0921:
0922:                ArrayList alDeployed = new ArrayList();
0923:                String sName;
0924:                String domainName = p_WhereAreYou.getCurrentDomainName();
0925:                String serverName = p_WhereAreYou.getCurrentJonasServerName();
0926:                String type = MailServiceImpl.SESSION_PROPERTY_TYPE;
0927:
0928:                ObjectName any_on = J2eeObjectName.JavaMailResources(
0929:                        domainName, serverName, type);
0930:                Iterator itNames = JonasManagementRepr.queryNames(any_on,
0931:                        serverName).iterator();
0932:                while (itNames.hasNext()) {
0933:                    ObjectName on = (ObjectName) itNames.next();
0934:                    sName = on.getKeyProperty("name");
0935:                    if (sName != null) {
0936:                        alDeployed.add(sName);
0937:                    }
0938:                }
0939:
0940:                Collections.sort(alDeployed);
0941:                return alDeployed;
0942:            }
0943:
0944:            /**
0945:             * Return the list of deployed MimePartDatasource Mail Factories in the current server.
0946:             *
0947:             * @param p_WhereAreYou The container WhereAreYou
0948:             * @return The list
0949:             * @throws ManagementException
0950:             */
0951:            public static ArrayList getMimeMailPartFactoriesDeployed(
0952:                    WhereAreYou p_WhereAreYou) throws ManagementException {
0953:                ArrayList alDeployed = new ArrayList();
0954:                String sName;
0955:                String domainName = p_WhereAreYou.getCurrentDomainName();
0956:                String serverName = p_WhereAreYou.getCurrentJonasServerName();
0957:                String type = MailServiceImpl.MIMEPART_PROPERTY_TYPE;
0958:
0959:                ObjectName any_on = J2eeObjectName.JavaMailResources(
0960:                        domainName, serverName, type);
0961:                Iterator itNames = JonasManagementRepr.queryNames(any_on,
0962:                        serverName).iterator();
0963:                while (itNames.hasNext()) {
0964:                    ObjectName on = (ObjectName) itNames.next();
0965:                    sName = on.getKeyProperty("name");
0966:                    if (sName != null) {
0967:                        alDeployed.add(sName);
0968:                    }
0969:                }
0970:                Collections.sort(alDeployed);
0971:                return alDeployed;
0972:            }
0973:
0974:            /**
0975:             * Return the list of Security Memory Factories in the current server.
0976:             *
0977:             * @return The list of Security Memory Factories
0978:             * @throws ManagementException
0979:             * @throws MalformedObjectNameException
0980:             */
0981:            public static ArrayList getSecurityMemoryFactories(String serverName)
0982:                    throws ManagementException, MalformedObjectNameException {
0983:                String sName;
0984:                ArrayList al = new ArrayList();
0985:                Iterator itNames = getListMBeanName(
0986:                        JonasObjectName.allSecurityMemoryFactories(),
0987:                        serverName).iterator();
0988:                while (itNames.hasNext()) {
0989:                    sName = JonasAdminJmx.extractValueMbeanName(",name",
0990:                            itNames.next().toString());
0991:                    if (sName != null) {
0992:                        al.add(sName);
0993:                    }
0994:                }
0995:                Collections.sort(al);
0996:                return al;
0997:            }
0998:
0999:            /**
1000:             * Return the list of Security Datasource Factories in the current server.
1001:             *
1002:             * @return The list of Security Datasource Factories
1003:             * @throws ManagementException
1004:             * @throws MalformedObjectNameException
1005:             */
1006:            public static ArrayList getSecurityDatasourceFactories(
1007:                    String serverName) throws ManagementException,
1008:                    MalformedObjectNameException {
1009:                String sName;
1010:                ArrayList al = new ArrayList();
1011:                Iterator itNames = getListMBeanName(
1012:                        JonasObjectName.allSecurityDatasourceFactories(),
1013:                        serverName).iterator();
1014:                while (itNames.hasNext()) {
1015:                    sName = JonasAdminJmx.extractValueMbeanName(",name",
1016:                            itNames.next().toString());
1017:                    if (sName != null) {
1018:                        al.add(sName);
1019:                    }
1020:                }
1021:                Collections.sort(al);
1022:                return al;
1023:            }
1024:
1025:            /**
1026:             * Return the list of Security Ldap Factories in the current server.
1027:             *
1028:             * @return The list of Security Ldap Factories
1029:             * @throws ManagementException
1030:             * @throws MalformedObjectNameException
1031:             */
1032:            public static ArrayList getSecurityLdapFactories(String serverName)
1033:                    throws ManagementException, MalformedObjectNameException {
1034:                String sName;
1035:                ArrayList al = new ArrayList();
1036:                Iterator itNames = getListMBeanName(
1037:                        JonasObjectName.allSecurityLdapFactories(), serverName)
1038:                        .iterator();
1039:                while (itNames.hasNext()) {
1040:                    sName = JonasAdminJmx.extractValueMbeanName(",name",
1041:                            itNames.next().toString());
1042:                    if (sName != null) {
1043:                        al.add(sName);
1044:                    }
1045:                }
1046:                Collections.sort(al);
1047:                return al;
1048:            }
1049:
1050:            /**
1051:             * Return the SubType of a Security Factory in the current server.
1052:             *
1053:             * @param p_NameFactory The factory name to find
1054:             * @return The SubType or null if not found
1055:             * @throws ManagementException
1056:             * @throws MalformedObjectNameException
1057:             */
1058:            public static String findSecurityFactorySubType(
1059:                    String p_NameFactory, String serverName)
1060:                    throws ManagementException, MalformedObjectNameException {
1061:                String sName;
1062:                String sSubType = null;
1063:                ObjectName on = null;
1064:
1065:                Iterator itNames = getListMBeanName(
1066:                        JonasObjectName.allSecurityFactories(), serverName)
1067:                        .iterator();
1068:                while (itNames.hasNext()) {
1069:                    on = new ObjectName(itNames.next().toString());
1070:                    sName = on.getKeyProperty("name");
1071:                    if (p_NameFactory.equals(sName) == true) {
1072:                        sSubType = on.getKeyProperty("subtype");
1073:                        break;
1074:                    }
1075:                }
1076:                return sSubType;
1077:            }
1078:
1079:            /**
1080:             * Return the list of all users in a resource.
1081:             *
1082:             * @param p_Resource The resource
1083:             * @return The list of users
1084:             * @throws ManagementException
1085:             * @throws MalformedObjectNameException
1086:             */
1087:            public static ArrayList getUsers(String p_Resource,
1088:                    String serverName) throws ManagementException,
1089:                    MalformedObjectNameException {
1090:                String sName;
1091:                ArrayList al = new ArrayList();
1092:                Iterator itNames = getListMBeanName(
1093:                        JonasObjectName.allUsers(p_Resource), serverName)
1094:                        .iterator();
1095:                while (itNames.hasNext()) {
1096:                    sName = JonasAdminJmx.extractValueMbeanName(",name",
1097:                            itNames.next().toString());
1098:                    if (sName != null) {
1099:                        al.add(sName);
1100:                    }
1101:                }
1102:                Collections.sort(al);
1103:                return al;
1104:            }
1105:
1106:            /**
1107:             * Return the list of all roles in a resource.
1108:             *
1109:             * @param p_Resource The resource
1110:             * @return The list of roles
1111:             * @throws ManagementException
1112:             * @throws MalformedObjectNameException
1113:             */
1114:            public static ArrayList getRoles(String p_Resource,
1115:                    String serverName) throws ManagementException,
1116:                    MalformedObjectNameException {
1117:                String sName;
1118:                ArrayList al = new ArrayList();
1119:                Iterator itNames = getListMBeanName(
1120:                        JonasObjectName.allRoles(p_Resource), serverName)
1121:                        .iterator();
1122:                while (itNames.hasNext()) {
1123:                    sName = JonasAdminJmx.extractValueMbeanName(",name",
1124:                            itNames.next().toString());
1125:                    if (sName != null) {
1126:                        al.add(sName);
1127:                    }
1128:                }
1129:                Collections.sort(al);
1130:                return al;
1131:            }
1132:
1133:            /**
1134:             * Return the list of all groups in a resource.
1135:             *
1136:             * @param p_Resource The resource
1137:             * @return The list of groups
1138:             * @throws ManagementException
1139:             * @throws MalformedObjectNameException
1140:             */
1141:            public static ArrayList getGroups(String p_Resource,
1142:                    String serverName) throws ManagementException,
1143:                    MalformedObjectNameException {
1144:                String sName;
1145:                ArrayList al = new ArrayList();
1146:                Iterator itNames = getListMBeanName(
1147:                        JonasObjectName.allGroups(p_Resource), serverName)
1148:                        .iterator();
1149:                while (itNames.hasNext()) {
1150:                    sName = JonasAdminJmx.extractValueMbeanName(",name",
1151:                            itNames.next().toString());
1152:                    if (sName != null) {
1153:                        al.add(sName);
1154:                    }
1155:                }
1156:                Collections.sort(al);
1157:                return al;
1158:            }
1159:
1160:            /**
1161:             * Return a list of names bounded in the registry.
1162:             *
1163:             * @return The list
1164:             * @throws NamingException
1165:             */
1166:            public static ArrayList getRegistryList(String serverName)
1167:                    throws NamingException {
1168:                synchronized (s_Synchro) {
1169:                    ArrayList oNames = new ArrayList();
1170:                    // get the naming context
1171:                    Context ctx = JonasManagementRepr.getContext(serverName);
1172:                    // get all names bounded in the contexr
1173:                    for (NamingEnumeration e = ctx.list(""); e
1174:                            .hasMoreElements();) {
1175:                        oNames.add(((NameClassPair) e.nextElement()).getName());
1176:                    }
1177:                    return oNames;
1178:                }
1179:            }
1180:
1181:            /**
1182:             * Return the Queue destinations list.
1183:             * @return The list
1184:             */
1185:            public static ArrayList getQueuesList(String serverName) {
1186:                synchronized (s_Synchro) {
1187:                    ObjectName jmsServMB = JonasObjectName.jmsService();
1188:                    Set queues = (Set) JonasManagementRepr.getAttribute(
1189:                            jmsServMB, "AllJmsQueueDestinationNames",
1190:                            serverName);
1191:                    ArrayList al = new ArrayList();
1192:                    Iterator itNames = queues.iterator();
1193:                    while (itNames.hasNext()) {
1194:                        al.add(itNames.next());
1195:                    }
1196:                    return al;
1197:                }
1198:            }
1199:
1200:            /**
1201:             * Return the Topic destinations list.
1202:             * @return The list
1203:             */
1204:            public static ArrayList getTopicsList(String serverName) {
1205:                synchronized (s_Synchro) {
1206:                    ObjectName jmsServMB = JonasObjectName.jmsService();
1207:                    Set topics = (Set) JonasManagementRepr.getAttribute(
1208:                            jmsServMB, "AllJmsTopicDestinationNames",
1209:                            serverName);
1210:                    ArrayList al = new ArrayList();
1211:                    Iterator itNames = topics.iterator();
1212:                    while (itNames.hasNext()) {
1213:                        al.add(itNames.next());
1214:                    }
1215:                    return al;
1216:                }
1217:            }
1218:
1219:            /**
1220:             * Return the default Connection Factories.
1221:             *
1222:             * @param p_Resources The messages
1223:             * @return The list
1224:             */
1225:            public static ArrayList getConnectionFactoriesList(
1226:                    MessageResources p_Resources, String serverName) {
1227:                synchronized (s_Synchro) {
1228:                    ObjectName jmsServMB = JonasObjectName.jmsService();
1229:                    String cfName = (String) JonasManagementRepr.getAttribute(
1230:                            jmsServMB, "DefaultConnectionFactoryName",
1231:                            serverName);
1232:                    String tcfName = (String) JonasManagementRepr.getAttribute(
1233:                            jmsServMB, "DefaultTopicConnectionFactoryName",
1234:                            serverName);
1235:                    String qcfName = (String) JonasManagementRepr.getAttribute(
1236:                            jmsServMB, "DefaultQueueConnectionFactoryName",
1237:                            serverName);
1238:                    ArrayList al = new ArrayList();
1239:                    String comment = p_Resources
1240:                            .getMessage("tab.connfact.defaultconnfact");
1241:                    JmsConnFact cf = new JmsConnFact(cfName, comment);
1242:                    al.add(cf);
1243:                    comment = p_Resources
1244:                            .getMessage("tab.connfact.defaulttopicconnfact");
1245:                    cf = new JmsConnFact(tcfName, comment);
1246:                    al.add(cf);
1247:                    comment = p_Resources
1248:                            .getMessage("tab.connfact.defaultqueueconnfact");
1249:                    cf = new JmsConnFact(qcfName, comment);
1250:                    al.add(cf);
1251:                    return al;
1252:                }
1253:            }
1254:
1255:            /**
1256:             * Return the list of all used loggers in this JOnAS server.
1257:             * @param p_Resources The used message resource
1258:             * @param p_WhereAreYou The used WhereAreYou instance
1259:             * @param p_Action True to get the action (to use directly in jsp) or False to get the same action but in forward (write in the file struts-config.xml)
1260:             * @return The list of loggers
1261:             * @throws ManagementException
1262:             * @throws MalformedObjectNameException
1263:             */
1264:            public static ArrayList getLoggers(MessageResources p_Resources,
1265:                    WhereAreYou p_WhereAreYou, boolean p_Action)
1266:                    throws ManagementException, MalformedObjectNameException {
1267:                String serverName = p_WhereAreYou.getCurrentJonasServerName();
1268:                ArrayList al = new ArrayList();
1269:                String sActionForward;
1270:                // Get JONAS logger
1271:                if (p_Action == true) {
1272:                    sActionForward = "EditLoggingJonas.do";
1273:                } else {
1274:                    sActionForward = "ActionEditLoggingJonas";
1275:                }
1276:                String itemName = p_Resources.getMessage("logger.jonas.name");
1277:                String type = LoggerItem.LOGGER_JONAS;
1278:                LoggerItem li = new LoggerItem(itemName, type, sActionForward);
1279:                al.add(li);
1280:                // Get Catalina Logger
1281:                if (p_WhereAreYou.isCatalinaServer() == true) {
1282:                    ObjectName on = CatalinaObjectName
1283:                            .catalinaAccessLogValves(p_WhereAreYou
1284:                                    .getCurrentCatalinaDomainName());
1285:
1286:                    Iterator it = getListMbean(on, serverName).iterator();
1287:                    while (it.hasNext()) {
1288:                        ObjectName oItem = (ObjectName) it.next();
1289:                        if (p_Action) {
1290:                            sActionForward = "EditCatalinaAccessLogger.do?select="
1291:                                    + oItem.toString();
1292:                        } else {
1293:                            sActionForward = "ActionEditCatalinaAccessLogger";
1294:                        }
1295:                        itemName = p_Resources
1296:                                .getMessage("logger.catalina.access.name");
1297:                        String hostName = oItem.getKeyProperty("host");
1298:                        String containerName = null;
1299:                        String containerType = null;
1300:                        String containerLabel = null;
1301:                        if (hostName == null) {
1302:                            type = LoggerItem.LOGGER_CATALINA_ACCESS_ENGINE;
1303:                            containerType = p_Resources
1304:                                    .getMessage("label.loggers.container.engine");
1305:                            containerName = p_Resources
1306:                                    .getMessage("label.loggers.container.engine.name");
1307:                            containerLabel = containerName;
1308:                        } else {
1309:                            String pathName = oItem.getKeyProperty("path");
1310:                            if (pathName != null) {
1311:                                type = LoggerItem.LOGGER_CATALINA_ACCESS_CONTEXT;
1312:                                containerName = pathName;
1313:                                containerType = p_Resources
1314:                                        .getMessage("label.loggers.container.context");
1315:                                containerLabel = WebAppItem
1316:                                        .extractLabelPathContext(
1317:                                                containerName,
1318:                                                p_WhereAreYou
1319:                                                        .getCurrentCatalinaDefaultHostName());
1320:                            } else {
1321:                                type = LoggerItem.LOGGER_CATALINA_ACCESS_HOST;
1322:                                containerName = hostName;
1323:                                containerType = p_Resources
1324:                                        .getMessage("label.loggers.container.host");
1325:                                containerLabel = containerName;
1326:                            }
1327:                        }
1328:                        itemName = itemName.concat(" " + containerLabel);
1329:                        li = new LoggerItem(itemName, type, sActionForward,
1330:                                oItem.toString(), containerType, containerName);
1331:                        al.add(li);
1332:                    }
1333:                }
1334:                // sort
1335:                Collections.sort(al,
1336:                        new BeanComparator(new String[] { "name" }));
1337:                return al;
1338:            }
1339:
1340:            /**
1341:             * Create a list for each family of Mbean.
1342:             *
1343:             * @return An array of lists
1344:             * @throws ManagementException
1345:             */
1346:            public static ArrayList getMbeansLists(String serverName)
1347:                    throws ManagementException {
1348:
1349:                MbeanItem oItem;
1350:
1351:                // Create the new list
1352:                ArrayList al = new ArrayList();
1353:                // Dispath each Mbean in its list
1354:                Iterator it = JonasAdminJmx.getListMbean(null, serverName)
1355:                        .iterator();
1356:                while (it.hasNext()) {
1357:                    oItem = MbeanItem.build((ObjectName) it.next());
1358:                    al.add(oItem);
1359:                }
1360:                return al;
1361:            }
1362:
1363:            /**
1364:             * Create a list for each family of Mbean.
1365:             *
1366:             * @return An array of lists
1367:             * @throws ManagementException
1368:             */
1369:            public static ArrayList[] getFamiliesMbeansLists(String serverName)
1370:                    throws ManagementException {
1371:
1372:                MbeanItem oItem;
1373:
1374:                // Create the new lists
1375:                ArrayList[] als = new ArrayList[3];
1376:                for (int i = 0; i < MbeanItem.SIZE_FAMILIES; i++) {
1377:                    als[i] = new ArrayList();
1378:                }
1379:                // Dispath each Mbean in its list
1380:                Iterator it = JonasAdminJmx.getListMbean(null, serverName)
1381:                        .iterator();
1382:                while (it.hasNext()) {
1383:                    oItem = MbeanItem.build((ObjectName) it.next());
1384:                    als[oItem.getFamily()].add(oItem);
1385:                }
1386:                return als;
1387:            }
1388:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.