1 19 package org.netbeans.modules.j2ee.sun.ide.controllers; 20 21 import java.util.HashSet ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.util.List ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 import java.util.Vector ; 28 import java.util.logging.Logger ; 29 import java.util.logging.Level ; 30 import java.io.IOException ; 31 import java.lang.reflect.Method ; 32 33 import javax.management.Attribute ; 34 import javax.management.MBeanAttributeInfo ; 35 import javax.management.MBeanInfo ; 36 import javax.management.MBeanServerConnection ; 37 import javax.management.ObjectName ; 38 import javax.management.RuntimeMBeanException ; 39 import javax.enterprise.deploy.spi.DeploymentManager ; 40 41 import com.sun.appserv.management.base.AMX; 42 import com.sun.appserv.management.base.Util; 43 import com.sun.appserv.management.base.QueryMgr; 44 import com.sun.appserv.management.base.XTypes; 45 import com.sun.appserv.management.j2ee.J2EEManagedObject; 46 import com.sun.appserv.management.j2ee.J2EETypes; 47 import com.sun.appserv.management.client.AppserverConnectionSource; 48 import com.sun.appserv.management.config.DeployedItemRefConfig; 49 import com.sun.appserv.management.config.ModuleConfig; 50 import com.sun.appserv.management.config.ResourceConfig; 51 import com.sun.appserv.management.config.ResourceRefConfig; 52 import com.sun.appserv.management.config.ServerConfig; 53 import java.io.File ; 54 55 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface; 56 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtController; 57 import org.netbeans.modules.j2ee.sun.util.AppserverConnectionFactory; 58 import org.netbeans.modules.j2ee.sun.util.GUIUtils; 59 import org.netbeans.modules.j2ee.sun.util.NodeTypes; 60 import org.netbeans.modules.j2ee.sun.util.PluginRequestInterceptor; 61 import org.openide.util.NbBundle; 62 63 66 public class ControllerUtil { 67 68 private static final String DELIMINATOR = " "; 69 private static String PROPERTIES_INTERFACE = "PropertiesAccess"; 70 private static String DESCRIPTION_INTERFACE = "Description"; 71 private static String ENABLED_INTERFACE = "Enabled"; 72 private static String RESOURCE_CONFIG_INTERFACE = "ResourceConfig"; 73 private static String MODULE_CONFIG_INTERFACE = "ModuleConfig"; 74 private static String J2EE_DEPLOYED_OBJ_INTERFACE = "J2EEDeployedObject"; 75 private static String OBJECT_TYPE_INTERFACE = "ObjectType"; 76 private static String NAME_ATTRIBUTE = "Name"; 77 private static String JNDI_NAME_ATTRIBUTE = "JNDIName"; 78 79 private static final String ASADMIN_KEY = "asadmin"; 80 private static final String ADMIN_GUI_KEY = "admingui"; 81 private static final String ADMIN_GUI_KEY2 = "admin-console"; 82 private static final String ADMIN_APP_KEY = "adminapp"; 83 private static final String WEB_UI_KEY = "com_sun_web_ui"; 84 private static final String MEJB_SYS_APP = "MEjbApp"; 85 private static final String EJB_TIMER_SYS_APP = "__ejb_container_timer_app"; 86 private static final String JWS_APPCLIENTS_KEY = "__JWSappclients"; 87 private static final String WSIT_KEY = "WSTXServices"; 88 private static final String SERVER_KEY = "//server/"; 89 90 static final String [] RES_ADAPTOR_KEYS = {"__xa", "jmsra", "__ds"}; 91 92 private static final String CONFIG_OBJ_NAME = "com.sun.appserv:type=applications,category=config"; 93 private static Logger logger; 94 private static Map j2eeTypeToConfigMap; 95 96 private static final String DAS_SERVER_NAME = "server"; 97 98 static { 99 logger = Logger.getLogger("org.netbeans.modules.j2ee.sun"); 100 } 101 102 static { 103 j2eeTypeToConfigMap = new HashMap (); 104 j2eeTypeToConfigMap.put(J2EETypes.J2EE_DOMAIN, XTypes.DOMAIN_CONFIG); 105 j2eeTypeToConfigMap.put(J2EETypes.J2EE_CLUSTER, XTypes.CLUSTER_CONFIG); 106 j2eeTypeToConfigMap.put(J2EETypes.J2EE_SERVER, 107 XTypes.STANDALONE_SERVER_CONFIG); 108 j2eeTypeToConfigMap.put(J2EETypes.JVM, XTypes.JAVA_CONFIG); 109 j2eeTypeToConfigMap.put(J2EETypes.J2EE_APPLICATION, 110 XTypes.J2EE_APPLICATION_CONFIG); 111 j2eeTypeToConfigMap.put(J2EETypes.EJB_MODULE, XTypes.EJB_MODULE_CONFIG); 112 j2eeTypeToConfigMap.put(J2EETypes.WEB_MODULE, XTypes.WEB_MODULE_CONFIG); 113 j2eeTypeToConfigMap.put(J2EETypes.APP_CLIENT_MODULE, 114 XTypes.APP_CLIENT_MODULE_CONFIG); 115 j2eeTypeToConfigMap.put(J2EETypes.RESOURCE_ADAPTER_MODULE, 116 XTypes.RAR_MODULE_CONFIG); 117 j2eeTypeToConfigMap.put(J2EETypes.RESOURCE_ADAPTER, 118 XTypes.RESOURCE_ADAPTER_CONFIG); 119 } 120 121 122 125 private ControllerUtil() { 126 } 127 128 129 133 public static AppserverMgmtController getAppserverMgmtControllerFromDeployMgr(final DeploymentManager deployMgr) { 134 AppserverConnectionSource con = createAppserverConnFromDeploymentMgr(deployMgr); 135 if (con==null){ 136 return null; } 138 else { 139 return new AppserverMgmtController(deployMgr, con); 140 } 141 } 142 143 144 148 public static AppserverConnectionSource createAppserverConnFromDeploymentMgr(final DeploymentManager deployMgr) { 149 AppserverConnectionSource connection = null; 150 SunDeploymentManagerInterface sunDpmtMgr = 151 (SunDeploymentManagerInterface) deployMgr; 152 153 try { 154 connection = AppserverConnectionFactory.getHTTPAppserverConnection( 156 sunDpmtMgr.getHost(), sunDpmtMgr.getPort(), 157 sunDpmtMgr.getUserName(), sunDpmtMgr.getPassword(), 158 sunDpmtMgr.isSecure()); 159 160 connection.getDomainRoot(); 163 164 } catch (Exception ioex) { 165 connection=null; 166 168 169 170 } 171 return connection; 172 } 173 174 175 179 public static MBeanServerConnection getMBeanServerConnWithInterceptor( 180 final SunDeploymentManagerInterface sunDplymtIntrface, 181 final AppserverConnectionSource connSource) { 182 MBeanServerConnection conn = null; 183 try { 184 conn = connSource.getMBeanServerConnection(false); 185 } catch (IOException io) { 186 logger.log(Level.FINE, io.getMessage(), io); 187 } 188 MBeanServerConnection connWithInterceptor = 189 new PluginRequestInterceptor(sunDplymtIntrface, conn); 190 return connWithInterceptor; 191 } 192 193 194 198 static public AMX getAMXComponentFromMap(Map map, String keyName) { 199 for(Iterator itr = map.values().iterator(); itr.hasNext(); ) { 200 AMX component = (AMX)itr.next(); 201 if(component.getName().equals(keyName)) { 202 return component; 203 } 204 } 205 return null; 206 } 207 208 209 212 static public String [] getComponentNamesFromMap(Map map) { 213 String [] names = new String [map.size()]; 214 int pos = 0; 215 for(Iterator itr = map.values().iterator(); itr.hasNext(); ) { 216 AMX component = (AMX)itr.next(); 217 names[pos] = component.getName(); 218 pos++; 219 } 220 return names; 221 } 222 223 226 static public String arrayToString(Object [] array) { 227 StringBuffer buffer = new StringBuffer (); 228 for(int i = 0; i < array.length; i++) { 229 buffer.append(array[i]); 230 buffer.append(DELIMINATOR); 231 } 232 return buffer.toString(); 233 } 234 235 236 240 public static Map getAllAttributes(final Class clazz, 241 final AMX amx, final List propsToIgnore, 242 final MBeanServerConnection conn, final String nodeType) { 243 Map attrs = null; 244 Set declaredAttrs = 245 extractAttributeNamesFromMethods( 246 getGetterMethods(clazz.getDeclaredMethods())); 247 Set inheritedAttrs = getExtraAttributes(clazz); 248 declaredAttrs.addAll(inheritedAttrs); 249 if(isJNDINameAbsent(declaredAttrs)) { 250 declaredAttrs.add(NAME_ATTRIBUTE); 251 } 252 if(nodeType.equals(NodeTypes.WEB_MODULE)){ 253 attrs = getAttributeProperties( 255 applyFilterToAttributeNamesForWeb(propsToIgnore,declaredAttrs), amx, conn); 256 }else{ 257 attrs = getAttributeProperties( 258 applyFilterToAttributeNames(propsToIgnore,declaredAttrs), amx, conn); 259 } 260 attrs = modifyEnabledProperty(attrs, amx); 261 return attrs; 262 } 263 264 268 private static Set getExtraAttributes(Class clazz) { 269 Set attrSet = new HashSet (); 270 Class [] classes = clazz.getInterfaces(); 271 for(int i = 0; i < classes.length; i++) { 272 if(isExtraInterface(getSimpleClassName(classes[i]))) { 273 attrSet.addAll(extractAttributeNamesFromMethods( 274 getGetterMethods(classes[i].getDeclaredMethods()))); 275 276 } 277 attrSet.addAll(getExtraAttributes(classes[i])); 278 } 279 return attrSet; 280 } 281 282 285 private static String getSimpleClassName(Class clazz) { 286 String fullClassName = clazz.getName(); 287 int lastIndex = fullClassName.lastIndexOf("."); 288 return fullClassName.substring(lastIndex + 1, 289 fullClassName.length()).trim(); 290 } 291 292 296 private static boolean isExtraInterface(String intrfaceName) { 297 return (DESCRIPTION_INTERFACE.equals(intrfaceName) 298 || ENABLED_INTERFACE.equals(intrfaceName) 299 || PROPERTIES_INTERFACE.equals(intrfaceName) 300 || RESOURCE_CONFIG_INTERFACE.equals(intrfaceName) 301 || J2EE_DEPLOYED_OBJ_INTERFACE.equals(intrfaceName) 302 || MODULE_CONFIG_INTERFACE.equals(intrfaceName) 303 || OBJECT_TYPE_INTERFACE.equals(intrfaceName)); 304 } 305 306 307 310 private static boolean isJNDINameAbsent(Set attrs) { 311 for(Iterator itr = attrs.iterator(); itr.hasNext(); ) { 312 if(JNDI_NAME_ATTRIBUTE.equals(itr.next())) { 313 return false; 314 } 315 } 316 return true; 317 } 318 319 320 323 private static Set applyFilterToAttributeNames( 324 final List propsToIgnore, final Set names) { 325 if(propsToIgnore != null && propsInListAreStrings(propsToIgnore)) { 326 for(Iterator itr = propsToIgnore.iterator(); itr.hasNext(); ) { 327 String name = (String ) itr.next(); 328 if(names.contains(name)) { 329 names.remove(name); 330 } 331 } 332 } 333 return names; 334 } 335 336 private static Set applyFilterToAttributeNamesForWeb( 337 final List propsToAdd, final Set names) { 338 Set attrNames = new HashSet (); 339 if(propsToAdd == null){ 340 return names; 341 } 342 if(propsToAdd != null && propsInListAreStrings(propsToAdd)) { 343 for(Iterator itr = propsToAdd.iterator(); itr.hasNext(); ) { 344 String name = (String ) itr.next(); 345 if(names.contains(name)) { 346 attrNames.add(name); 347 } 348 } 349 } 350 return attrNames; 351 } 352 353 354 357 public static boolean propsInListAreStrings(List propsToIgnore) { 358 for(Iterator itr = propsToIgnore.iterator(); itr.hasNext(); ) { 359 if(!(itr.next() instanceof String )) { 360 return false; 361 } 362 } 363 return true; 364 } 365 366 367 371 private static Map getAttributeProperties(Set names, AMX amx, 372 MBeanServerConnection conn) { 373 Map returnMap = new HashMap (); 375 final ObjectName on = Util.getObjectName(amx); 376 try { 378 final MBeanInfo mi = conn.getMBeanInfo(on); 379 final MBeanAttributeInfo [] mai = mi.getAttributes(); 380 for (int i = 0 ; i < mai.length ; i++) { 381 if (mai[i] != null && names.contains(mai[i].getName())) { 382 try { 384 Object attrValue = conn.getAttribute(on, mai[i].getName()); 385 returnMap.put(new Attribute (mai[i].getName(), 387 attrValue), mai[i]); 388 } catch(javax.management.AttributeNotFoundException ex) { 389 continue; 390 } 391 } 392 } 393 } catch(Exception e) { 394 logger.log(Level.FINE, e.getMessage(), e); 395 } 396 if(returnMap.size() == 0 || returnMap == null) { 397 logger.log(Level.FINE, "The return Map in getAttrProperties is " + 398 "size 0!"); 399 } 400 return returnMap; 401 } 402 403 404 408 public static Set extractAttributeNamesFromMethods(final Method [] method) { 409 final Set attrNames = new HashSet (); 410 for (int i = 0 ; i < method.length ; i++) { 411 final String methodName = method[i].getName(); 412 final String name = 413 methodName.substring(methodName.indexOf("get")+3); 414 attrNames.add(name); 415 } 416 return attrNames; 417 } 418 419 420 424 public static Method [] getGetterMethods(Method [] methods) { 425 final Vector v = new Vector (); 426 for (int i = 0 ; i < methods.length ; i++) { 427 if (methods[i].getName().startsWith("get") 428 && !methods[i].getName().endsWith("Stats")) { 429 v.add(methods[i]); 430 } 431 } 432 final Method [] mm = new Method [v.size()]; 433 return (Method []) v.toArray(mm); 434 } 435 436 437 441 public static AMX getConfigPeer(final AMX amx) { 442 J2EEManagedObject managedObj = (J2EEManagedObject) amx; 443 AMX configPeer = managedObj.getConfigPeer(); 444 if(configPeer != null) { 445 return configPeer; 446 } else { 447 String configXType = getConfigPeerAMXType(amx.getJ2EEType()); 448 QueryMgr queryMgr = amx.getDomainRoot().getQueryMgr(); 449 java.util.Set set = queryMgr.queryJ2EETypeSet(configXType); 450 for(Iterator itr = set.iterator(); itr.hasNext(); ) { 451 AMX config = (AMX) itr.next(); 452 if(config.getName().equals(amx.getName())) { 453 return config; 454 } 455 } 456 } 457 return null; 458 } 459 460 461 465 public static Attribute setAttributeValue(AMX j2eeMod, AMX configPeer, String attrName, Object value, 466 MBeanServerConnection conn) { 467 Attribute modAttr = new Attribute (attrName, value); 468 try { 469 if(attrName.equals(NodeTypes.ENABLED) && (configPeer != null)){ 470 updateEnabled(configPeer, value); 471 }else{ 472 ObjectName configOn = Util.getObjectName(configPeer); 473 conn.setAttribute(configOn, modAttr); 474 } 475 } catch (RuntimeMBeanException e) { 476 if(j2eeMod != null){ 477 ObjectName j2eeOn = Util.getObjectName(j2eeMod); 478 modAttr = setAttrValue(j2eeOn, attrName, modAttr, conn); 479 }else 480 modAttr = null; 481 } catch (Exception ex) { 482 Object [] params = new Object [] {attrName, ex.getMessage()}; 483 GUIUtils.showError( 484 getLocalizedString("unexpected_setAttr_except", params)); 485 modAttr = null; 486 } 487 return modAttr; 488 } 489 490 public static Attribute setAttributeValue(AMX amx, String attrName, Object value, 491 MBeanServerConnection conn) { 492 final ObjectName on = Util.getObjectName(amx); 493 Attribute modAttr = new Attribute (attrName, value); 494 try { 495 if(attrName.equals(NodeTypes.ENABLED) && (amx != null)) 496 updateEnabled(amx, value); 497 else 498 conn.setAttribute(on, modAttr); 499 } catch (RuntimeMBeanException e) { 500 modAttr = setAttributeOnConfigPeer(amx, attrName, value, conn); 501 } catch (Exception ex) { 502 Object [] params = new Object [] {attrName, ex.getMessage()}; 503 GUIUtils.showError( 504 getLocalizedString("unexpected_setAttr_except", params)); 505 modAttr = null; 506 } 507 return modAttr; 508 } 509 510 private static void updateEnabled(AMX amx, Object value){ 511 if(amx instanceof ResourceConfig){ 512 setResourceEnabled((ResourceConfig)amx, value); 513 } else { 514 if(amx instanceof ModuleConfig) { 515 setModuleEnabled((ModuleConfig)amx, value); 516 } 517 } 518 } 519 520 private static Attribute setAttrValue(ObjectName on, String attrName, Attribute modAttr, 521 MBeanServerConnection conn) { 522 try { 523 conn.setAttribute(on, modAttr); 524 } catch (Exception ex) { 525 Object [] params = new Object [] {attrName, ex.getMessage()}; 526 GUIUtils.showError( 527 getLocalizedString("unexpected_setAttr_except", params)); 528 modAttr = null; 529 } 530 return modAttr; 531 } 532 533 private static final String CONST_SET_PROP_EXCEPT = "unexpected_setProp_except"; 535 539 public static void setPropertyValue(com.sun.appserv.management.config.ResourceConfig resConfig, Object [] props) { 540 try { 541 for(int i=0; i<props.length; i++){ 542 Attribute attr = (Attribute )props[i]; 543 String propValue = null; 544 if(attr.getValue() != null){ 545 propValue = attr.getValue().toString(); 546 } 547 resConfig.setPropertyValue(attr.getName(), propValue); 548 } 549 } catch (RuntimeMBeanException e) { 550 Object [] params = new Object [] {resConfig.getJNDIName(), e.getMessage()}; 551 GUIUtils.showError( 552 getLocalizedString(CONST_SET_PROP_EXCEPT, params)); 553 } catch (Exception ex) { 554 Object [] params = new Object [] {resConfig.getJNDIName(), ex.getMessage()}; 555 GUIUtils.showError( 556 getLocalizedString(CONST_SET_PROP_EXCEPT, params)); 557 } 558 } 559 560 564 public static void setPropertyValue(com.sun.appserv.management.config.JDBCConnectionPoolConfig resConfig, Object [] props) { 565 try { 566 for(int i=0; i<props.length; i++){ 567 Attribute attr = (Attribute )props[i]; 568 String propValue = null; 569 if(attr.getValue() != null){ 570 propValue = attr.getValue().toString(); 571 } 572 resConfig.setPropertyValue(attr.getName(), propValue); 573 } 574 } catch (RuntimeMBeanException e) { 575 Object [] params = new Object [] {resConfig.getName(), e.getMessage()}; 576 GUIUtils.showError( 577 getLocalizedString(CONST_SET_PROP_EXCEPT, params)); 578 } catch (Exception ex) { 579 Object [] params = new Object [] {resConfig.getName(), ex.getMessage()}; 580 GUIUtils.showError( 581 getLocalizedString(CONST_SET_PROP_EXCEPT, params)); 582 } 583 } 584 585 589 public static void setPropertyValue(com.sun.appserv.management.config.ConnectorConnectionPoolConfig resConfig, Object [] props) { 590 try { 591 for(int i=0; i<props.length; i++){ 592 Attribute attr = (Attribute )props[i]; 593 String propValue = null; 594 if(attr.getValue() != null){ 595 propValue = attr.getValue().toString(); 596 } 597 resConfig.setPropertyValue(attr.getName(), propValue); 598 } 599 } catch (RuntimeMBeanException e) { 600 Object [] params = new Object [] {resConfig.getName(), e.getMessage()}; 601 GUIUtils.showError( 602 getLocalizedString(CONST_SET_PROP_EXCEPT, params)); 603 } catch (Exception ex) { 604 Object [] params = new Object [] {resConfig.getName(), ex.getMessage()}; 605 GUIUtils.showError( 606 getLocalizedString(CONST_SET_PROP_EXCEPT, params)); 607 } 608 } 609 610 614 private static Attribute setAttributeOnConfigPeer(final AMX amx, 615 final String attrName, final Object value, 616 final MBeanServerConnection conn) { 617 AMX configPeer = getConfigPeer(amx); 618 Attribute modAttr = new Attribute (attrName, value); 619 try { 620 final ObjectName on = Util.getObjectName(configPeer); 621 conn.setAttribute(on, modAttr); 622 } catch (RuntimeMBeanException e) { 623 Object [] params = new Object [] {attrName, e.getMessage()}; 624 GUIUtils.showError( 625 getLocalizedString("unexpected_setAttrConfigPeer_except", params)); 626 modAttr = null; 627 } catch (Exception ex) { 628 Object [] params = new Object [] {attrName, ex.getMessage()}; 629 GUIUtils.showError( 630 getLocalizedString("unexpected_setAttrConfigPeer_except", params)); 631 modAttr = null; 632 } 633 return modAttr; 634 } 635 636 637 644 protected static String [] stripOutSystemApps(String [] allModuleNames) { 645 final java.util.Vector nonSystemApps = new java.util.Vector (); 646 for(int i = 0; i < allModuleNames.length; i++) { 647 if(allModuleNames[i].indexOf(ASADMIN_KEY) == -1 648 && allModuleNames[i].indexOf(MEJB_SYS_APP) == -1 649 && allModuleNames[i].indexOf(EJB_TIMER_SYS_APP) == -1 650 && allModuleNames[i].indexOf(JWS_APPCLIENTS_KEY) == -1 651 && ! allModuleNames[i].matches(SERVER_KEY) ) { 652 nonSystemApps.add(allModuleNames[i]); 653 } 654 } 655 final String [] str = new String [nonSystemApps.size()]; 656 return (String []) nonSystemApps.toArray(str); 657 } 658 659 660 667 protected static Map stripOutSystemApps(final Map allModules) { 668 Map nonSystemApps = new HashMap (); 669 for(Iterator itr = allModules.keySet().iterator(); itr.hasNext();) { 670 String moduleName = (String ) itr.next(); 671 if(moduleName.indexOf(ASADMIN_KEY) == -1 672 && moduleName.indexOf(ADMIN_GUI_KEY) == -1 673 && moduleName.indexOf(ADMIN_APP_KEY) == -1 674 && moduleName.indexOf(WEB_UI_KEY) == -1 675 && moduleName.indexOf(MEJB_SYS_APP) == -1 676 && moduleName.indexOf(EJB_TIMER_SYS_APP) == -1 677 && moduleName.indexOf(JWS_APPCLIENTS_KEY) == -1 678 && moduleName.indexOf(ADMIN_GUI_KEY2) == -1 679 && moduleName.indexOf(WSIT_KEY) == -1 680 && ! moduleName.matches(SERVER_KEY)) { 681 nonSystemApps.put(moduleName, allModules.get(moduleName)); 682 } 683 } 684 return nonSystemApps; 685 } 686 687 688 691 public static String getConfigPeerAMXType(final String j2eeType) { 692 return (String ) j2eeTypeToConfigMap.get(j2eeType); 693 } 694 695 696 697 705 public static void checkIfServerInDebugMode(final DeploymentManager dplymtMgr) { 706 SunDeploymentManagerInterface sunDpmtMgr = 707 (SunDeploymentManagerInterface) dplymtMgr; 708 if(sunDpmtMgr != null) { 709 if(sunDpmtMgr.isSuspended()) { 710 GUIUtils.showInformation( 711 getLocalizedString("server_dbg_mode_notify")); 712 throw new RuntimeException ( 713 getLocalizedString("server_dbg_mode_notify")); 714 } 715 } 716 } 717 718 719 723 public static Map getLogAttributes(final AMX config, final Map propNames, final MBeanServerConnection conn){ 724 Map returnMap = new HashMap (); 725 final ObjectName on = Util.getObjectName(config); 726 try { 728 final MBeanInfo mi = conn.getMBeanInfo(on); 729 final MBeanAttributeInfo [] mai = mi.getAttributes(); 730 for (int i = 0 ; i < mai.length ; i++) { 731 if (mai[i] != null && propNames.containsKey(mai[i].getName())) { 732 try { 734 Object attrValue = conn.getAttribute(on, mai[i].getName()); 735 returnMap.put(new Attribute (mai[i].getName(), 737 attrValue), mai[i]); 738 } catch(javax.management.AttributeNotFoundException ex) { 739 continue; 740 } 741 } 742 } 743 } catch(Exception e) { 744 logger.log(Level.FINE, e.getMessage(), e); 745 } 746 if(returnMap.size() == 0 || returnMap == null) { 747 logger.log(Level.FINE, "The return Map in getAttrProperties is " + 748 "size 0!"); 749 } 750 return returnMap; 751 } 752 753 757 private static String getLocalizedString(final String bundleStrProp) { 758 return NbBundle.getMessage(ControllerUtil.class, 759 bundleStrProp); 760 } 761 762 763 767 private static String getLocalizedString(final String bundleStrProp, 768 final Object [] params) { 769 return NbBundle.getMessage(ControllerUtil.class, 770 bundleStrProp, params); 771 } 772 773 public static boolean isGlassFish(DeploymentManager dm){ 774 File candidate = ((SunDeploymentManagerInterface)dm).getPlatformRoot(); 776 File as9 = new File (candidate.getAbsolutePath()+ 777 "/lib/dtds/sun-web-app_2_5-0.dtd"); return as9.exists(); 779 } 780 781 public static ObjectName [] getSubComponentsFromConfig(String modName, MBeanServerConnection conn){ 782 String [] subComponents = new String [] {}; 783 try{ 784 ObjectName oName = new ObjectName (CONFIG_OBJ_NAME); 785 Object [] params = {modName}; 786 String [] signature = {"java.lang.String"}; 787 subComponents = (String [])conn.invoke(oName, "getModuleComponents", params, signature); 788 }catch(Exception ex){} 789 return convertToObjNames(subComponents); 790 } 791 792 private static ObjectName [] convertToObjNames(String [] objNames){ 793 try{ 794 ObjectName [] compNames = new ObjectName [objNames.length]; 795 for(int i=0; i<objNames.length; i++){ 796 ObjectName name = new ObjectName (objNames[i]); 797 compNames[i] = name; 798 } 799 return compNames; 800 }catch(Exception ex){ 801 return new ObjectName [0]; 802 } 803 } 804 805 private static void setResourceEnabled(ResourceConfig resConfig, Object value){ 806 boolean val = Boolean.valueOf(value.toString()).booleanValue(); 807 ResourceRefConfig config = getResourceRefConfig(resConfig); 808 if(config != null) { 809 config.setEnabled(val); 810 } 811 } 812 813 private static void setModuleEnabled(ModuleConfig modConfig, Object value){ 814 boolean val = Boolean.valueOf(value.toString()).booleanValue(); 815 DeployedItemRefConfig config = getDeployedItemRefConfig(modConfig); 816 if(config != null) { 817 config.setEnabled(val); 818 } 819 } 820 821 private static ResourceRefConfig getResourceRefConfig(AMX appConfig){ 822 String appName = appConfig.getName(); 823 ResourceRefConfig itemName = (ResourceRefConfig)getDASConfig(appConfig).getResourceRefConfigMap().get(appName); 824 return itemName; 825 } 826 827 private static ServerConfig getDASConfig(AMX appConfig){ 828 Map serverConfigs = getServerInstancesMap(appConfig); 829 ServerConfig serverConfig = (ServerConfig)serverConfigs.get(DAS_SERVER_NAME); 830 return serverConfig; 831 } 832 833 public static Map modifyEnabledProperty(Map j2eeProps, AMX configPeer){ 834 Map modProps = j2eeProps; 835 for(Iterator itr = j2eeProps.keySet().iterator(); itr.hasNext(); ) { 836 Attribute attr = (Attribute ) itr.next(); 837 if(attr.getName().equals(NodeTypes.ENABLED)){ 838 MBeanAttributeInfo info = (MBeanAttributeInfo ) j2eeProps.get(attr); 839 Boolean value = (Boolean )attr.getValue(); 840 boolean attrVal = calculateIsEnabled(configPeer, value.booleanValue()); 841 Attribute enabled = new Attribute (NodeTypes.ENABLED, Boolean.valueOf(attrVal)); 842 modProps.remove(attr); 843 modProps.put(enabled, info); 844 break; 845 } 846 } 847 return modProps; 848 } 849 850 protected static boolean calculateIsEnabled(AMX appConfig, boolean configEnabled){ 851 boolean isEnabled = configEnabled; 852 boolean refEnabled = configEnabled; 853 if(appConfig instanceof ResourceConfig) { 854 ResourceRefConfig itemName = getResourceRefConfig(appConfig); 855 if(itemName != null) { 856 refEnabled = itemName.getEnabled(); 857 } 858 } else { 859 DeployedItemRefConfig itemName = getDeployedItemRefConfig(appConfig); 860 if(itemName != null) { 861 refEnabled = itemName.getEnabled(); 862 } 863 } 864 if(!configEnabled || !refEnabled) { 865 isEnabled = false; 866 } 867 return isEnabled; 868 } 869 870 protected static DeployedItemRefConfig getDeployedItemRefConfig(AMX appConfig){ 871 String appName = appConfig.getName(); 872 DeployedItemRefConfig itemName = (DeployedItemRefConfig)getDASConfig(appConfig).getDeployedItemRefConfigMap().get(appName); 873 return itemName; 874 } 875 876 public static String [] getServerTargets(AMX amx){ 877 return getComponentNamesFromMap(getServerInstancesMap(amx)); 878 } 879 880 public static Map getServerInstancesMap(AMX amx) { 881 Map serverConfigs = amx.getDomainRoot().getDomainConfig().getServerConfigMap(); 882 return serverConfigs; 883 } 884 885 public static Map getStandaloneServerInstancesMap(AMX amx) { 886 Map serverConfigs = amx.getDomainRoot().getDomainConfig().getStandaloneServerConfigMap(); 887 return serverConfigs; 888 } 889 } 890 | Popular Tags |