1 25 26 package org.objectweb.jonas.webapp.jonasadmin; 27 28 import java.io.File ; 29 import java.util.ArrayList ; 30 import java.util.Collections ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Set ; 34 35 import javax.management.MalformedObjectNameException ; 36 import javax.management.ObjectName ; 37 import javax.naming.Context ; 38 import javax.naming.NameClassPair ; 39 import javax.naming.NamingEnumeration ; 40 import javax.naming.NamingException ; 41 import javax.servlet.http.HttpServletRequest ; 42 43 import org.apache.struts.util.MessageResources; 44 import org.objectweb.jonas.jmx.J2eeObjectName; 45 import org.objectweb.jonas.jmx.JonasManagementRepr; 46 import org.objectweb.jonas.jmx.JonasObjectName; 47 import org.objectweb.jonas.jmx.ManagementException; 48 import org.objectweb.jonas.mail.MailServiceImpl; 49 import org.objectweb.jonas.jmx.CatalinaObjectName; 50 import org.objectweb.jonas.webapp.jonasadmin.common.BeanComparator; 51 import org.objectweb.jonas.webapp.jonasadmin.logging.LoggerItem; 52 import org.objectweb.jonas.webapp.jonasadmin.mbean.MbeanItem; 53 import org.objectweb.jonas.webapp.jonasadmin.service.container.WebAppItem; 54 55 60 public class JonasAdminJmx { 61 62 64 private static Object s_Synchro = new Object (); 65 66 68 71 protected JonasAdminJmx() { 72 } 73 74 76 85 public static String replace(String template, String placeholder, String value) { 86 if (template == null) { 87 return (null); 88 } 89 if ((placeholder == null) || (value == null)) { 90 return (template); 91 } 92 String sRet = new String (template); 93 while (true) { 94 int index = sRet.indexOf(placeholder); 95 if (index < 0) { 96 break; 97 } 98 StringBuffer temp = new StringBuffer (sRet.substring(0, index)); 99 temp.append(value); 100 temp.append(sRet.substring(index + placeholder.length())); 101 sRet = temp.toString(); 102 } 103 return (sRet); 104 105 } 106 107 112 public static ObjectName getJ2eeDomainObjectName() { 113 ObjectName onDomains = J2eeObjectName.J2EEDomains(); 115 return getFirstMbean(onDomains); 116 } 117 118 126 public static ObjectName getJ2eeServerObjectName(String p_DomainName) { 127 ObjectName pattern_server_on = J2eeObjectName.J2EEServers(p_DomainName); 129 ObjectName server_on = null; 130 Iterator it = JonasManagementRepr.queryNames(pattern_server_on).iterator(); 131 if (it.hasNext()) { 132 server_on = (ObjectName ) it.next(); 134 } 135 return server_on; 136 } 137 138 147 public static ObjectName getJ2eeServerObjectName() { 148 ObjectName pattern_server_on = J2eeObjectName.J2EEServers(); 150 ObjectName server_on = null; 151 Iterator it = JonasManagementRepr.queryNames(pattern_server_on).iterator(); 152 if (it.hasNext()) { 153 server_on = (ObjectName ) it.next(); 155 } 156 return server_on; 157 } 158 159 166 public static ArrayList getListRemoteJonasServerItem(HttpServletRequest p_Request) 167 throws Exception { 168 synchronized (s_Synchro) { 169 ArrayList oServers = new ArrayList (); 170 String sCurrentRMIConnectorName = JonasManagementRepr.getCurrentRMIConnectorName(); 172 173 Set setRmiConnector = JonasManagementRepr.getRMIConnectorsNames(); 175 if (setRmiConnector.size() > 0) { 176 Iterator oIt = setRmiConnector.iterator(); 177 while (oIt.hasNext()) { 178 JonasServerItem oItem = new JonasServerItem(); 179 oItem.setNameRmiConnector(oIt.next().toString()); 180 JonasManagementRepr.setCurrentRMIConnectorName(oItem.getNameRmiConnector()); 182 ObjectName server_on = getJ2eeServerObjectName(); 184 if (server_on != null) { 185 String serverName = server_on.getKeyProperty("name"); 186 oItem.setNameServer(serverName); 187 oServers.add(oItem); 188 } 189 } 190 try { 191 JonasManagementRepr.setCurrentRMIConnectorName(sCurrentRMIConnectorName); 193 } 194 catch (Exception e) { 195 if (oServers.size() > 0) { 197 JonasServerItem oItem = (JonasServerItem) oServers.get(0); 198 JonasManagementRepr.setCurrentRMIConnectorName(oItem.getNameRmiConnector()); 199 } 200 } 201 } 202 return oServers; 203 } 204 } 205 206 213 public static boolean hasMBeanName(ObjectName p_On) 214 throws ManagementException { 215 synchronized (s_Synchro) { 216 ArrayList al = new ArrayList (); 217 Iterator itNames = JonasManagementRepr.queryNames(p_On).iterator(); 218 if (itNames.hasNext()) { 219 return true; 220 } 221 return false; 222 } 223 } 224 225 232 public static String getFirstMBeanName(ObjectName p_On) 233 throws ManagementException { 234 synchronized (s_Synchro) { 235 ArrayList al = new ArrayList (); 236 Iterator itNames = JonasManagementRepr.queryNames(p_On).iterator(); 237 if (itNames.hasNext()) { 238 return itNames.next().toString(); 239 } 240 return null; 241 } 242 } 243 244 251 public static List getListMBeanName(ObjectName p_On) 252 throws ManagementException { 253 synchronized (s_Synchro) { 254 ArrayList al = new ArrayList (); 255 Iterator itNames = JonasManagementRepr.queryNames(p_On).iterator(); 256 while (itNames.hasNext()) { 257 ObjectName item = (ObjectName ) itNames.next(); 258 al.add(item.toString()); 259 } 260 Collections.sort(al); 261 return al; 262 } 263 } 264 265 273 public static ObjectName getFirstMbean(ObjectName p_On) 274 throws ManagementException { 275 synchronized (s_Synchro) { 276 ArrayList al = new ArrayList (); 277 Iterator itNames = JonasManagementRepr.queryNames(p_On).iterator(); 278 if (itNames.hasNext()) { 279 return (ObjectName ) itNames.next(); 280 } 281 return null; 282 } 283 } 284 285 293 public static List getListMbean(ObjectName p_On) 294 throws ManagementException { 295 synchronized (s_Synchro) { 296 ArrayList al = new ArrayList (); 297 Iterator itNames = JonasManagementRepr.queryNames(p_On).iterator(); 298 while (itNames.hasNext()) { 299 al.add(itNames.next()); 300 } 301 return al; 302 } 303 } 304 305 313 public static String extractValueMbeanName(String pName, String pMBeanName) { 314 String sValue = null; 315 try { 316 String sSearch = pName.trim() + "="; 317 int iPos = pMBeanName.indexOf(sSearch); 318 if (iPos > -1) { 319 sValue = pMBeanName.substring(iPos + sSearch.length()); 320 iPos = sValue.indexOf(","); 321 if (iPos > -1) { 322 sValue = sValue.substring(0, iPos); 323 } 324 } 325 } catch (NullPointerException e) { 326 sValue = null; 328 } 329 return sValue; 330 } 331 332 338 public static String extractFilename(String p_Path) { 339 String sFilename = null; 340 try { 341 int iPosSeparator = p_Path.lastIndexOf("/"); 342 if (iPosSeparator < 0) { 343 iPosSeparator = p_Path.lastIndexOf("\\"); 344 if (iPosSeparator < 0) { 345 sFilename = new String (p_Path); 346 } 347 else { 348 sFilename = p_Path.substring(iPosSeparator + 1); 349 } 350 } 351 else { 352 sFilename = p_Path.substring(iPosSeparator + 1); 353 } 354 if (sFilename.length() > 0) { 355 int iPos_1 = p_Path.indexOf(DIR_AUTOLOAD + "/" + sFilename); 356 int iPos_2 = p_Path.indexOf(DIR_AUTOLOAD + "\\" + sFilename); 357 if (iPos_1 > -1) { 358 sFilename = DIR_AUTOLOAD + "/" + sFilename; 359 } 360 else if (iPos_2 > -1) { 361 sFilename = DIR_AUTOLOAD + "\\" + sFilename; 362 } 363 } 364 else { 365 sFilename = null; 366 } 367 } 368 catch (NullPointerException e) { 369 sFilename = null; 371 } 372 return sFilename; 373 } 374 375 378 private static String DIR_RARS = "rars"; 379 private static String DIR_AUTOLOAD = "autoload"; 380 private static String DIR_CONF = "conf"; 381 382 private static ArrayList getFilenames(String p_Directory, String p_Extension) { 383 ArrayList al = new ArrayList (); 384 String sExt = "." + p_Extension.toLowerCase(); 385 String sFile; 386 387 File oFile = new File (p_Directory); 388 String [] asFiles = oFile.list(); 389 int iPos; 390 if (asFiles != null) { 391 for (int i = 0; i < asFiles.length; i++) { 392 oFile = new File (p_Directory, asFiles[i]); 393 if (oFile.isFile() == true) { 394 sFile = oFile.getName().toLowerCase(); 395 iPos = sFile.lastIndexOf(sExt); 396 if (iPos > -1) { 397 if (iPos == (sFile.length() - sExt.length())) { 398 al.add(oFile.getName()); 399 } 400 } 401 } 402 } 403 } 404 Collections.sort(al); 405 return al; 406 } 407 408 private static ArrayList getDirectories(String p_Directory) { 409 ArrayList al = new ArrayList (); 410 String sFile; 411 412 File oFile = new File (p_Directory); 413 String [] asFiles = oFile.list(); 414 415 if (asFiles != null) { 416 for (int i = 0; i < asFiles.length; i++) { 417 oFile = new File (p_Directory, asFiles[i]); 418 if (oFile.isDirectory() == true) { 419 al.add(oFile.getName()); 420 } 421 } 422 } 423 Collections.sort(al); 424 return al; 425 } 426 427 private static void appendDirectory(ArrayList p_List, String p_Dir) { 428 String sDir = p_Dir + "/"; 429 for (int i = 0; i < p_List.size(); i++) { 430 p_List.set(i, sDir + p_List.get(i)); 431 } 432 } 433 434 440 public static ArrayList getJarFilesDeployable() 441 throws ManagementException { 442 ObjectName on = JonasObjectName.ejbService(); 443 ArrayList al = (ArrayList ) JonasManagementRepr.getAttribute(on, "DeployableJars"); 444 String sDir = (String ) JonasManagementRepr.getAttribute(on, "EjbjarsDirectory"); 445 446 String sEarDir = null; 447 try { 448 on = JonasObjectName.earService(); 449 sEarDir = (String ) JonasManagementRepr.getAttribute(on, "AppsDirectory"); 450 } 451 catch (Exception e) { 452 } 454 return prepareContainersToDisplay(al, sDir, sEarDir); 455 } 456 457 463 public static ArrayList getRarFilesDeployable() 464 throws ManagementException { 465 ObjectName on = JonasObjectName.resourceService(); 466 ArrayList al = (ArrayList ) JonasManagementRepr.getAttribute(on, "DeployableRars"); 467 String sDir = (String ) JonasManagementRepr.getAttribute(on, "RarsDirectory"); 468 469 String sEarDir = null; 470 try { 471 on = JonasObjectName.earService(); 472 sEarDir = (String ) JonasManagementRepr.getAttribute(on, "AppsDirectory"); 473 } 474 catch (Exception e) { 475 } 477 return prepareContainersToDisplay(al, sDir, sEarDir); 478 } 479 480 486 public static ArrayList getEarFilesDeployable() 487 throws ManagementException { 488 ObjectName on = JonasObjectName.earService(); 489 ArrayList al = (ArrayList ) JonasManagementRepr.getAttribute(on, "DeployableEars"); 490 String sDir = (String ) JonasManagementRepr.getAttribute(on, "AppsDirectory"); 491 return prepareContainersToDisplay(al, sDir, null); 492 } 493 494 500 public static ArrayList getWarFilesDeployable() 501 throws ManagementException { 502 ObjectName on = JonasObjectName.webContainerService(); 503 ArrayList al = (ArrayList ) JonasManagementRepr.getAttribute(on, "DeployableWars"); 504 String sDir = (String ) JonasManagementRepr.getAttribute(on, "WebappsDirectory"); 505 506 String sEarDir = null; 507 try { 508 on = JonasObjectName.earService(); 509 sEarDir = (String ) JonasManagementRepr.getAttribute(on, "AppsDirectory"); 510 } 511 catch (Exception e) { 512 } 514 return prepareContainersToDisplay(al, sDir, sEarDir); 515 } 516 517 523 public static ArrayList getJarFilesDeployed() 524 throws ManagementException { 525 ObjectName on = JonasObjectName.ejbService(); 526 ArrayList al = (ArrayList ) JonasManagementRepr.getAttribute(on, "DeployedJars"); 527 String sDir = (String ) JonasManagementRepr.getAttribute(on, "EjbjarsDirectory"); 528 529 String sEarDir = null; 530 try { 531 on = JonasObjectName.earService(); 532 sEarDir = (String ) JonasManagementRepr.getAttribute(on, "AppsDirectory"); 533 } 534 catch (Exception e) { 535 } 537 return prepareContainersToDisplay(al, sDir, sEarDir); 538 } 539 540 546 public static ArrayList getEarFilesDeployed() 547 throws ManagementException { 548 ObjectName on = JonasObjectName.earService(); 549 ArrayList al = (ArrayList ) JonasManagementRepr.getAttribute(on, "DeployedEars"); 550 String sDir = (String ) JonasManagementRepr.getAttribute(on, "AppsDirectory"); 551 return prepareContainersToDisplay(al, sDir, null); 552 } 553 554 560 public static ArrayList getRarFilesDeployed() 561 throws ManagementException { 562 ObjectName on = JonasObjectName.resourceService(); 563 ArrayList al = (ArrayList ) JonasManagementRepr.getAttribute(on, "DeployedRars"); 564 String sDir = (String ) JonasManagementRepr.getAttribute(on, "RarsDirectory"); 565 566 String sEarDir = null; 567 try { 568 on = JonasObjectName.earService(); 569 sEarDir = (String ) JonasManagementRepr.getAttribute(on, "AppsDirectory"); 570 } 571 catch (ManagementException e) { 572 } 574 return prepareContainersToDisplay(al, sDir, sEarDir); 575 } 576 577 583 public static ArrayList getWarFilesDeployed() 584 throws ManagementException { 585 ObjectName on = JonasObjectName.webContainerService(); 586 ArrayList al = (ArrayList ) JonasManagementRepr.getAttribute(on, "DeployedWars"); 587 String sDir = (String ) JonasManagementRepr.getAttribute(on, "WebappsDirectory"); 588 589 String sEarDir = null; 590 try { 591 on = JonasObjectName.earService(); 592 sEarDir = (String ) JonasManagementRepr.getAttribute(on, "AppsDirectory"); 593 } 594 catch (ManagementException e) { 595 } 597 return prepareContainersToDisplay(al, sDir, sEarDir); 598 } 599 600 608 public static ArrayList prepareContainersToDisplay(ArrayList p_Containers 609 , String p_ContainerDir, String p_EarDir) { 610 int iPos; 611 String sPath; 612 boolean bAdd; 613 ArrayList al = new ArrayList (); 614 for (int i = 0; i < p_Containers.size(); i++) { 615 sPath = p_Containers.get(i).toString(); 617 iPos = sPath.indexOf(p_ContainerDir); 618 if (iPos > -1) { 619 sPath = sPath.substring(p_ContainerDir.length()); 620 } 621 if (sPath.endsWith("/") == true) { 623 sPath = sPath.substring(0, sPath.length() - 1); 624 } 625 bAdd = true; 627 if (p_EarDir != null) { 629 iPos = sPath.indexOf(p_EarDir); 630 if (iPos > -1) { 631 bAdd = false; 632 } 633 634 } 635 if (bAdd == true) { 636 al.add(sPath); 637 } 638 } 639 Collections.sort(al); 641 return al; 642 } 643 644 private static ArrayList getFilesDeployed(ObjectName on) 645 throws ManagementException { 646 ArrayList alDeployed = new ArrayList (); 647 String sPath; 648 String sFile; 649 Iterator itNames = JonasAdminJmx.getListMBeanName(on).iterator(); 650 while (itNames.hasNext()) { 651 sPath = JonasAdminJmx.extractValueMbeanName("fname", itNames.next().toString()); 652 sFile = JonasAdminJmx.extractFilename(sPath); 653 if (sFile != null) { 654 alDeployed.add(sFile); 655 } 656 } 657 Collections.sort(alDeployed); 658 return alDeployed; 659 660 } 661 662 668 public static ArrayList getMailFilesDeployable() 669 throws ManagementException { 670 ObjectName on = JonasObjectName.mailService(); 671 return (ArrayList ) JonasManagementRepr.getAttribute(on, "MailFactoryPropertiesFiles"); 672 } 673 674 680 public static ArrayList getMimePartMailFilesDeployable() 681 throws ManagementException { 682 ObjectName on = JonasObjectName.mailService(); 683 return (ArrayList ) JonasManagementRepr.getAttribute(on 684 , "MimePartMailFactoryPropertiesFiles"); 685 } 686 687 693 public static ArrayList getSessionMailFilesDeployable() 694 throws ManagementException { 695 ObjectName on = JonasObjectName.mailService(); 696 return (ArrayList ) JonasManagementRepr.getAttribute(on, "SessionMailFactoryPropertiesFiles"); 697 } 698 699 706 public static ArrayList getMimePartMailFilesDeployed(WhereAreYou p_WhereAreYou) 707 throws ManagementException { 708 ArrayList alDeployed = new ArrayList (); 709 String sName; 710 String domainName = p_WhereAreYou.getCurrentDomainName(); 711 String serverName = p_WhereAreYou.getCurrentJonasServerName(); 712 ObjectName on = J2eeObjectName.JavaMailResources(domainName, serverName 713 , MailServiceImpl.MIMEPART_PROPERTY_TYPE); 714 Iterator itNames = JonasManagementRepr.queryNames(on).iterator(); 715 while (itNames.hasNext()) { 716 ObjectName it_on = (ObjectName ) itNames.next(); 717 sName = it_on.getKeyProperty("name"); 718 if (sName != null) { 719 alDeployed.add(sName); 720 } 721 } 722 Collections.sort(alDeployed); 723 return alDeployed; 724 } 725 726 733 public static ArrayList getSessionMailFilesDeployed(WhereAreYou p_WhereAreYou) 734 throws ManagementException { 735 ArrayList alDeployed = new ArrayList (); 736 String sName; 737 String domainName = p_WhereAreYou.getCurrentDomainName(); 738 String serverName = p_WhereAreYou.getCurrentJonasServerName(); 739 ObjectName on = J2eeObjectName.JavaMailResources(domainName, serverName 740 , MailServiceImpl.SESSION_PROPERTY_TYPE); 741 Iterator itNames = JonasManagementRepr.queryNames(on).iterator(); 742 while (itNames.hasNext()) { 743 ObjectName it_on = (ObjectName ) itNames.next(); 744 sName = it_on.getKeyProperty("name"); 745 if (sName != null) { 746 alDeployed.add(sName); 747 } 748 } 749 Collections.sort(alDeployed); 750 return alDeployed; 751 } 752 753 760 public static ArrayList getMailFilesDeployed(WhereAreYou p_WhereAreYou) 761 throws ManagementException { 762 ArrayList alDeployed = getSessionMailFilesDeployed(p_WhereAreYou); 763 alDeployed.addAll(getMimePartMailFilesDeployed(p_WhereAreYou)); 764 Collections.sort(alDeployed); 765 return alDeployed; 766 } 767 768 774 public static ArrayList getDatasourceFilesDeployable() 775 throws ManagementException { 776 ObjectName on = JonasObjectName.databaseService(); 777 return (ArrayList ) JonasManagementRepr.getAttribute(on, "DataSourcePropertiesFiles"); 778 } 779 780 787 public static ArrayList getDatasourceFilesDeployed(String domainName, String serverName) 788 throws ManagementException { 789 790 ArrayList alDeployed = new ArrayList (); 791 ObjectName ons = J2eeObjectName.JDBCDataSources(domainName, serverName); 792 Iterator itNames = JonasManagementRepr.queryNames(ons).iterator(); 794 String sName = null; 795 while (itNames.hasNext()) { 796 ObjectName on = (ObjectName ) itNames.next(); 797 sName = on.getKeyProperty("name"); 798 if (sName != null) { 799 alDeployed.add(sName); 800 } 801 } 802 Collections.sort(alDeployed); 803 return alDeployed; 804 } 805 806 816 public static ArrayList getDatasourceDependences(String pDatasourceName, String domainName, String serverName) 817 throws ManagementException { 818 ObjectName jdbcDatasource = J2eeObjectName.getJDBCDataSource(domainName, serverName, pDatasourceName); 819 String [] asParam = new String [1]; 820 String [] asSignature = new String [1]; 821 asSignature[0] = "java.lang.String"; 822 ArrayList al = new ArrayList (); 823 asParam[0] = (String ) JonasManagementRepr.getAttribute(jdbcDatasource, "jndiName"); 824 if (JonasManagementRepr.isRegistered(JonasObjectName.ejbService())) { 825 String sName; 826 Iterator it = ((java.util.Set ) JonasManagementRepr.invoke(JonasObjectName.ejbService() 827 , "getDataSourceDependence", asParam, asSignature)).iterator(); 828 while (it.hasNext()) { 829 sName = JonasAdminJmx.extractValueMbeanName(",name", it.next().toString()); 830 if (sName != null) { 831 al.add(sName); 832 } 833 } 834 Collections.sort(al); 835 } 836 return al; 837 } 838 839 847 public static ArrayList getMailFactoryDependences(String p_MailFactoryName 848 , WhereAreYou p_WhereAreYou) 849 throws ManagementException { 850 String jndiName = null; 851 String domainName = p_WhereAreYou.getCurrentDomainName(); 852 String serverName = p_WhereAreYou.getCurrentJonasServerName(); 853 String type = MailServiceImpl.SESSION_PROPERTY_TYPE; 854 ObjectName on = J2eeObjectName.JavaMailResource(domainName, p_MailFactoryName, serverName 857 , type); 858 if (JonasManagementRepr.isRegistered(on) != true) { 860 type = MailServiceImpl.MIMEPART_PROPERTY_TYPE; 863 on = J2eeObjectName.JavaMailResource(domainName, p_MailFactoryName, serverName, type); 864 } 865 jndiName = (String ) JonasManagementRepr.getAttribute(on, "Name"); 866 867 String [] asParam = new String [1]; 868 String [] asSignature = new String [1]; 869 asSignature[0] = "java.lang.String"; 870 ArrayList al = new ArrayList (); 871 asParam[0] = jndiName; 872 if (JonasManagementRepr.isRegistered(JonasObjectName.ejbService()) == true) { 873 String sName; 874 Iterator it = ((java.util.Set ) JonasManagementRepr.invoke(JonasObjectName.ejbService() 875 , "getMailFactoryDependence", asParam, asSignature)).iterator(); 876 while (it.hasNext()) { 877 sName = JonasAdminJmx.extractValueMbeanName(",name", it.next().toString()); 878 if (sName != null) { 879 al.add(sName); 880 } 881 } 882 Collections.sort(al); 883 } 884 return al; 885 } 886 887 894 public static ArrayList getSessionMailFactoriesDeployed(WhereAreYou p_WhereAreYou) 895 throws ManagementException { 896 897 ArrayList alDeployed = new ArrayList (); 898 String sName; 899 String domainName = p_WhereAreYou.getCurrentDomainName(); 900 String serverName = p_WhereAreYou.getCurrentJonasServerName(); 901 String type = MailServiceImpl.SESSION_PROPERTY_TYPE; 902 903 ObjectName any_on = J2eeObjectName.JavaMailResources(domainName, serverName, type); 904 Iterator itNames = JonasManagementRepr.queryNames(any_on).iterator(); 905 while (itNames.hasNext()) { 906 ObjectName on = (ObjectName ) itNames.next(); 907 sName = on.getKeyProperty("name"); 908 if (sName != null) { 909 alDeployed.add(sName); 910 } 911 } 912 913 Collections.sort(alDeployed); 914 return alDeployed; 915 } 916 917 924 public static ArrayList getMimeMailPartFactoriesDeployed(WhereAreYou p_WhereAreYou) 925 throws ManagementException { 926 ArrayList alDeployed = new ArrayList (); 927 String sName; 928 String domainName = p_WhereAreYou.getCurrentDomainName(); 929 String serverName = p_WhereAreYou.getCurrentJonasServerName(); 930 String type = MailServiceImpl.MIMEPART_PROPERTY_TYPE; 931 932 ObjectName any_on = J2eeObjectName.JavaMailResources(domainName, serverName, type); 933 Iterator itNames = JonasManagementRepr.queryNames(any_on).iterator(); 934 while (itNames.hasNext()) { 935 ObjectName on = (ObjectName ) itNames.next(); 936 sName = on.getKeyProperty("name"); 937 if (sName != null) { 938 alDeployed.add(sName); 939 } 940 } 941 Collections.sort(alDeployed); 942 return alDeployed; 943 } 944 945 952 public static ArrayList getSecurityMemoryFactories() 953 throws ManagementException, MalformedObjectNameException { 954 String sName; 955 ArrayList al = new ArrayList (); 956 Iterator itNames = getListMBeanName(JonasObjectName.allSecurityMemoryFactories()).iterator(); 957 while (itNames.hasNext()) { 958 sName = JonasAdminJmx.extractValueMbeanName(",name", itNames.next().toString()); 959 if (sName != null) { 960 al.add(sName); 961 } 962 } 963 Collections.sort(al); 964 return al; 965 } 966 967 974 public static ArrayList getSecurityDatasourceFactories() 975 throws ManagementException, MalformedObjectNameException { 976 String sName; 977 ArrayList al = new ArrayList (); 978 Iterator itNames = getListMBeanName(JonasObjectName.allSecurityDatasourceFactories()). 979 iterator(); 980 while (itNames.hasNext()) { 981 sName = JonasAdminJmx.extractValueMbeanName(",name", itNames.next().toString()); 982 if (sName != null) { 983 al.add(sName); 984 } 985 } 986 Collections.sort(al); 987 return al; 988 } 989 990 997 public static ArrayList getSecurityLdapFactories() 998 throws ManagementException, MalformedObjectNameException { 999 String sName; 1000 ArrayList al = new ArrayList (); 1001 Iterator itNames = getListMBeanName(JonasObjectName.allSecurityLdapFactories()).iterator(); 1002 while (itNames.hasNext()) { 1003 sName = JonasAdminJmx.extractValueMbeanName(",name", itNames.next().toString()); 1004 if (sName != null) { 1005 al.add(sName); 1006 } 1007 } 1008 Collections.sort(al); 1009 return al; 1010 } 1011 1012 1020 public static String findSecurityFactorySubType(String p_NameFactory) 1021 throws ManagementException, MalformedObjectNameException { 1022 String sName; 1023 String sSubType = null; 1024 ObjectName on = null; 1025 1026 Iterator itNames = getListMBeanName(JonasObjectName.allSecurityFactories()).iterator(); 1027 while (itNames.hasNext()) { 1028 on = new ObjectName (itNames.next().toString()); 1029 sName = on.getKeyProperty("name"); 1030 if (p_NameFactory.equals(sName) == true) { 1031 sSubType = on.getKeyProperty("subtype"); 1032 break; 1033 } 1034 } 1035 return sSubType; 1036 } 1037 1038 1046 public static ArrayList getUsers(String p_Resource) 1047 throws ManagementException, MalformedObjectNameException { 1048 String sName; 1049 ArrayList al = new ArrayList (); 1050 Iterator itNames = getListMBeanName(JonasObjectName.allUsers(p_Resource)).iterator(); 1051 while (itNames.hasNext()) { 1052 sName = JonasAdminJmx.extractValueMbeanName(",name", itNames.next().toString()); 1053 if (sName != null) { 1054 al.add(sName); 1055 } 1056 } 1057 Collections.sort(al); 1058 return al; 1059 } 1060 1061 1069 public static ArrayList getRoles(String p_Resource) 1070 throws ManagementException, MalformedObjectNameException { 1071 String sName; 1072 ArrayList al = new ArrayList (); 1073 Iterator itNames = getListMBeanName(JonasObjectName.allRoles(p_Resource)).iterator(); 1074 while (itNames.hasNext()) { 1075 sName = JonasAdminJmx.extractValueMbeanName(",name", itNames.next().toString()); 1076 if (sName != null) { 1077 al.add(sName); 1078 } 1079 } 1080 Collections.sort(al); 1081 return al; 1082 } 1083 1084 1092 public static ArrayList getGroups(String p_Resource) 1093 throws ManagementException, MalformedObjectNameException { 1094 String sName; 1095 ArrayList al = new ArrayList (); 1096 Iterator itNames = getListMBeanName(JonasObjectName.allGroups(p_Resource)).iterator(); 1097 while (itNames.hasNext()) { 1098 sName = JonasAdminJmx.extractValueMbeanName(",name", itNames.next().toString()); 1099 if (sName != null) { 1100 al.add(sName); 1101 } 1102 } 1103 Collections.sort(al); 1104 return al; 1105 } 1106 1107 1113 public static ArrayList getRegistryList() 1114 throws NamingException { 1115 synchronized (s_Synchro) { 1116 ArrayList oNames = new ArrayList (); 1117 Context ctx = JonasManagementRepr.getContext(); 1119 for (NamingEnumeration e = ctx.list(""); e.hasMoreElements(); ) { 1121 oNames.add(((NameClassPair ) e.nextElement()).getName()); 1122 } 1123 return oNames; 1124 } 1125 } 1126 1127 1131 public static ArrayList getQueuesList() { 1132 synchronized (s_Synchro) { 1133 ObjectName jmsServMB = JonasObjectName.jmsService(); 1134 Set queues = (Set ) JonasManagementRepr.getAttribute(jmsServMB 1135 , "AllJmsQueueDestinationNames"); 1136 ArrayList al = new ArrayList (); 1137 Iterator itNames = queues.iterator(); 1138 while (itNames.hasNext()) { 1139 al.add(itNames.next()); 1140 } 1141 return al; 1142 } 1143 } 1144 1145 1149 public static ArrayList getTopicsList() { 1150 synchronized (s_Synchro) { 1151 ObjectName jmsServMB = JonasObjectName.jmsService(); 1152 Set topics = (Set ) JonasManagementRepr.getAttribute(jmsServMB 1153 , "AllJmsTopicDestinationNames"); 1154 ArrayList al = new ArrayList (); 1155 Iterator itNames = topics.iterator(); 1156 while (itNames.hasNext()) { 1157 al.add(itNames.next()); 1158 } 1159 return al; 1160 } 1161 } 1162 1163 1169 public static ArrayList getConnectionFactoriesList(MessageResources p_Resources) { 1170 synchronized (s_Synchro) { 1171 ObjectName jmsServMB = JonasObjectName.jmsService(); 1172 String cfName = (String ) JonasManagementRepr.getAttribute(jmsServMB 1173 , "DefaultConnectionFactoryName"); 1174 String tcfName = (String ) JonasManagementRepr.getAttribute(jmsServMB 1175 , "DefaultTopicConnectionFactoryName"); 1176 String qcfName = (String ) JonasManagementRepr.getAttribute(jmsServMB 1177 , "DefaultQueueConnectionFactoryName"); 1178 ArrayList al = new ArrayList (); 1179 String comment = p_Resources.getMessage("tab.connfact.defaultconnfact"); 1180 JmsConnFact cf = new JmsConnFact(cfName, comment); 1181 al.add(cf); 1182 comment = p_Resources.getMessage("tab.connfact.defaulttopicconnfact"); 1183 cf = new JmsConnFact(tcfName, comment); 1184 al.add(cf); 1185 comment = p_Resources.getMessage("tab.connfact.defaultqueueconnfact"); 1186 cf = new JmsConnFact(qcfName, comment); 1187 al.add(cf); 1188 return al; 1189 } 1190 } 1191 1192 1200 public static ArrayList getLoggers(MessageResources p_Resources, WhereAreYou p_WhereAreYou 1201 , boolean p_Action) 1202 throws ManagementException { 1203 ArrayList al = new ArrayList (); 1204 String sActionForward; 1205 if (p_Action == true) { 1207 sActionForward = "EditLoggingJonas.do"; 1208 } 1209 else { 1210 sActionForward = "ActionEditLoggingJonas"; 1211 } 1212 String itemName = p_Resources.getMessage("logger.jonas.name"); 1213 String type = LoggerItem.LOGGER_JONAS; 1214 LoggerItem li = new LoggerItem(itemName, type, sActionForward); 1215 al.add(li); 1216 if (p_WhereAreYou.isCatalinaServer() == true) { 1218 ObjectName on = CatalinaObjectName.catalinaAccessLogValves(p_WhereAreYou. 1219 getCurrentCatalinaDomainName()); 1220 1221 Iterator it = getListMbean(on).iterator(); 1222 while (it.hasNext()) { 1223 ObjectName oItem = (ObjectName ) it.next(); 1224 if (p_Action) { 1225 sActionForward = "EditCatalinaAccessLogger.do?select=" + oItem.toString(); 1226 } 1227 else { 1228 sActionForward = "ActionEditCatalinaAccessLogger"; 1229 } 1230 itemName = p_Resources.getMessage("logger.catalina.access.name"); 1231 String hostName = oItem.getKeyProperty("host"); 1232 String containerName = null; 1233 String containerType = null; 1234 String containerLabel = null; 1235 if (hostName == null) { 1236 type = LoggerItem.LOGGER_CATALINA_ACCESS_ENGINE; 1237 containerType = p_Resources.getMessage("label.loggers.container.engine"); 1238 containerName = p_Resources.getMessage("label.loggers.container.engine.name"); 1239 containerLabel = containerName; 1240 } else { 1241 String pathName = oItem.getKeyProperty("path"); 1242 if (pathName != null) { 1243 type = LoggerItem.LOGGER_CATALINA_ACCESS_CONTEXT; 1244 containerName = pathName; 1245 containerType = p_Resources.getMessage("label.loggers.container.context"); 1246 containerLabel = WebAppItem.extractLabelPathContext(containerName); 1247 } else { 1248 type = LoggerItem.LOGGER_CATALINA_ACCESS_HOST; 1249 containerName = hostName; 1250 containerType = p_Resources.getMessage("label.loggers.container.host"); 1251 containerLabel = containerName; 1252 } 1253 } 1254 itemName = itemName.concat(" " + containerLabel); 1255 li = new LoggerItem(itemName, type, sActionForward, oItem.toString(), containerType, containerName); 1256 al.add(li); 1257 } 1258 } 1259 Collections.sort(al, new BeanComparator(new String []{"name"})); 1261 return al; 1262 } 1263 1264 1270 public static ArrayList getMbeansLists() 1271 throws ManagementException { 1272 1273 MbeanItem oItem; 1274 1275 ArrayList al = new ArrayList (); 1277 Iterator it = JonasAdminJmx.getListMbean(null).iterator(); 1279 while (it.hasNext()) { 1280 oItem = MbeanItem.build((ObjectName ) it.next()); 1281 al.add(oItem); 1282 } 1283 return al; 1284 } 1285 1286 1292 public static ArrayList [] getFamiliesMbeansLists() 1293 throws ManagementException { 1294 1295 MbeanItem oItem; 1296 1297 ArrayList [] als = new ArrayList [3]; 1299 for (int i = 0; i < MbeanItem.SIZE_FAMILIES; i++) { 1300 als[i] = new ArrayList (); 1301 } 1302 Iterator it = JonasAdminJmx.getListMbean(null).iterator(); 1304 while (it.hasNext()) { 1305 oItem = MbeanItem.build((ObjectName ) it.next()); 1306 als[oItem.getFamily()].add(oItem); 1307 } 1308 return als; 1309 } 1310} 1311 | Popular Tags |