1 23 24 27 28 package com.sun.enterprise.admin.mbeans; 29 30 import com.sun.enterprise.admin.target.Target; 31 import com.sun.enterprise.admin.target.TargetBuilder; 32 import com.sun.enterprise.admin.target.TargetType; 33 import com.sun.enterprise.config.ConfigContext; 34 import com.sun.enterprise.config.ConfigException; 35 import com.sun.enterprise.config.serverbeans.ClusterHelper; 36 import com.sun.enterprise.config.serverbeans.ConfigAPIHelper; 37 import com.sun.enterprise.config.serverbeans.ServerHelper; 38 import com.sun.enterprise.util.i18n.StringManager; 39 import java.util.List ; 40 41 import javax.management.Attribute ; 42 43 import com.sun.enterprise.config.serverbeans.ServerTags; 44 import javax.management.MBeanException ; 45 import javax.management.MBeanServer ; 46 47 48 54 public class ConfigMBeanUtil { 55 56 59 private static final StringManager localStrings = 60 StringManager.getManager(ConfigsMBean.class); 61 62 63 private ConfigMBeanUtil() { 65 } 66 67 75 public static boolean attributeDefinedInList(final List list, 76 final String name) { 77 if(name != null) { 78 for(java.util.Iterator itr = list.iterator(); itr.hasNext(); ) { 79 Attribute attr = (Attribute ) itr.next(); 80 if(name != null && name.equals(attr.getName())) { 81 return true; 82 } 83 } 84 } 85 return false; 86 } 87 88 92 public static MBeanServer getMBeanServer() throws MBeanException { 93 return com.sun.enterprise.admin.common.MBeanServerFactory.getMBeanServer(); 94 } 95 96 97 101 public static Target getTarget(String targetName, TargetType[] targetTypes, 102 ConfigContext configContext) throws MBeanException { 103 104 try { 105 Target target = TargetBuilder.INSTANCE.createTarget( 106 targetTypes, targetName, configContext); 107 if (target.getType() == TargetType.SERVER || 108 target.getType() == TargetType.DAS) { 109 String configName = ServerHelper.getConfigForServer(configContext, 112 target.getName()).getName(); 113 if (!ConfigAPIHelper.isConfigurationReferencedByServerOnly(configContext, 114 configName, target.getName())) { 115 throw new ConfigException(localStrings.getString( 116 "configurationHasMultipleRefs", target.getName(), configName, 117 ConfigAPIHelper.getConfigurationReferenceesAsString( 118 configContext, configName))); 119 } 120 } else if (target.getType() == TargetType.CLUSTER) { 121 String configName = ClusterHelper.getConfigForCluster(configContext, 124 target.getName()).getName(); 125 if (!ConfigAPIHelper.isConfigurationReferencedByClusterOnly(configContext, 126 configName, target.getName())) { 127 throw new ConfigException(localStrings.getString( 128 "configurationHasMultipleRefs", target.getName(), configName, 129 ConfigAPIHelper.getConfigurationReferenceesAsString( 130 configContext, configName))); 131 } 132 } 133 return target; 134 } 135 catch (Exception e) { 136 throw MBeanExceptionFormatter.toMBeanException(e, null); 137 } 138 } 139 } 140 | Popular Tags |