1 23 package com.sun.enterprise.config.serverbeans; 24 25 import com.sun.enterprise.config.ConfigContext; 26 import com.sun.enterprise.config.ConfigException; 27 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 28 import com.sun.enterprise.config.serverbeans.Domain; 29 import com.sun.enterprise.config.serverbeans.NodeAgent; 30 import com.sun.enterprise.config.serverbeans.Servers; 31 import com.sun.enterprise.config.serverbeans.Cluster; 32 import com.sun.enterprise.config.serverbeans.Server; 33 import com.sun.enterprise.config.serverbeans.Config; 34 35 import com.sun.enterprise.util.i18n.StringManager; 36 37 import com.sun.enterprise.admin.util.IAdminConstants; 38 39 import java.util.ArrayList ; 40 41 public class ConfigAPIHelper extends ReferenceHelperBase implements IAdminConstants { 42 43 protected static final StringManager _strMgr=StringManager.getManager(ConfigAPIHelper.class); 44 private static ConfigAPIHelper _theInstance; 45 private final static String [] ILLEGAL_NAME_STRINGS = {"--"}; 46 47 48 public ConfigAPIHelper() { 49 super(); 50 } 51 52 protected Server[] getReferencingServers(ConfigContext configContext, String name) 53 throws ConfigException 54 { 55 return ServerHelper.getServersReferencingConfig(configContext, name); 56 } 57 58 protected Cluster[] getReferencingClusters(ConfigContext configContext, String name) 59 throws ConfigException 60 { 61 return ClusterHelper.getClustersReferencingConfig(configContext, name); 62 } 63 64 private synchronized static ConfigAPIHelper getInstance() 65 { 66 if (_theInstance == null) { 67 _theInstance = new ConfigAPIHelper(); 68 } 69 return _theInstance; 70 } 71 72 public static Domain getDomainConfigBean(ConfigContext configCtxt) 73 throws ConfigException 74 { 75 return ServerBeansFactory.getDomainBean(configCtxt); 76 } 77 78 82 public static Config[] getConfigsInDomain(ConfigContext configContext) 83 throws ConfigException 84 { 85 final Domain domain = getDomainConfigBean(configContext); 86 return domain.getConfigs().getConfig(); 87 } 88 89 92 public static boolean isAConfig(ConfigContext configContext, String configName) 93 throws ConfigException 94 { 95 final Domain domain = getDomainConfigBean(configContext); 96 final Config config = domain.getConfigs().getConfigByName(configName); 97 return (config != null ? true : false); 98 } 99 100 104 public static Config getConfigByName(ConfigContext configContext, String configName) 105 throws ConfigException 106 { 107 final Domain domain = getDomainConfigBean(configContext); 108 final Config config = domain.getConfigs().getConfigByName(configName); 109 if (config == null) { 110 throw new ConfigException(_strMgr.getString("noSuchConfig", configName)); 111 } 112 return config; 113 } 114 115 119 public static boolean isNameUnique(ConfigContext configContext, String name) 120 throws ConfigException 121 { 122 final Server[] servers = ServerHelper.getServersInDomain(configContext); 123 for (int i = 0; i < servers.length; i++) { 124 if (servers[i].getName().equals(name)) { 125 return false; 126 } 127 } 128 129 final Config[] configs = getConfigsInDomain(configContext); 130 for (int i = 0; i < configs.length; i++) { 131 if (configs[i].getName().equals(name)) { 132 return false; 133 } 134 } 135 136 final Cluster[] clusters = ClusterHelper.getClustersInDomain(configContext); 137 for (int i = 0; i < clusters.length; i++) { 138 if (clusters[i].getName().equals(name)) { 139 return false; 140 } 141 } 142 143 final NodeAgent[] controllers = NodeAgentHelper.getNodeAgentsInDomain(configContext); 144 for (int i = 0; i < controllers.length; i++) { 145 if (controllers[i].getName().equals(name)) { 146 return false; 147 } 148 } 149 return true; 150 } 151 152 156 public static void checkLegalName(String name) 157 throws ConfigException 158 { 159 164 for(int i = 0; i < ILLEGAL_NAME_STRINGS.length; i++) 165 { 166 if(name.indexOf(ILLEGAL_NAME_STRINGS[i]) >= 0) 167 { 168 String s = _strMgr.getString("illegalName", ILLEGAL_NAME_STRINGS[i]); 169 throw new ConfigException(s); 170 } 171 } 172 } 173 174 public static String getStandAloneConfigurationName(String name) 175 { 176 return name + STANDALONE_CONFIGURATION_SUFFIX; 177 } 178 179 183 public static boolean isConfigurationNameStandAlone(String configName, String name) 184 { 185 return configName.equals(getStandAloneConfigurationName( 186 name)) ? true : false; 187 } 188 189 192 public static boolean isConfigurationReferenced(ConfigContext configContext, String configName) 193 throws ConfigException 194 { 195 return getInstance().isReferenced(configContext, configName); 196 } 197 198 202 public static boolean isConfigurationReferencedByServerOnly(ConfigContext configContext, 203 String configName, String serverName) throws ConfigException 204 { 205 return getInstance().isReferencedByServerOnly(configContext, configName, serverName); 206 } 207 208 212 public static boolean isConfigurationReferencedByClusterOnly(ConfigContext configContext, 213 String configName, String clusterName) throws ConfigException 214 { 215 return getInstance().isReferencedByClusterOnly(configContext, configName, clusterName); 216 } 217 218 222 public static String getConfigurationReferenceesAsString(ConfigContext configContext, String configName) 223 throws ConfigException 224 { 225 return getInstance().getReferenceesAsString(configContext, configName); 226 } 227 } 228 | Popular Tags |