1 23 24 29 30 package com.sun.enterprise.config.serverbeans; 31 32 import java.io.*; 33 import java.util.*; 34 import com.sun.enterprise.config.ConfigException; 35 import com.sun.enterprise.config.ConfigContext; 36 import com.sun.enterprise.config.ConfigBean; 37 import com.sun.enterprise.config.ConfigBeansFactory; 38 import java.lang.reflect.Method ; 39 import java.text.CharacterIterator ; 40 import java.text.StringCharacterIterator ; 41 42 import com.sun.enterprise.util.i18n.StringManager; 43 import com.sun.enterprise.admin.util.IAdminConstants; 44 45 54 public class ServerBeansFactory { 55 56 57 private static Config configModel; 58 59 60 private static StringManager localStrings = 61 StringManager.getManager("com.sun.enterprise.server"); 62 63 64 public ServerBeansFactory() { 65 } 66 67 73 public static Config getConfigModel(ConfigContext configContext) throws ConfigException { 74 75 if (configContext != null) { 77 Server server = ServerBeansFactory.getServerBean(configContext); 78 String configRef = server.getConfigRef(); 79 String configXpath = ServerXPathHelper.getConfigIdXpath(configRef); 80 configModel = (Config) ConfigBeansFactory.getConfigBeanByXPath(configContext, configXpath); 81 } else { 82 String msg = localStrings.getString( 83 "serverContext.config_context_is_null"); 84 throw new ConfigException(msg); 85 } 86 return configModel; 87 } 88 89 92 public static Domain getDomainBean(ConfigContext ctx) throws ConfigException { 93 return (Domain)ctx.getRootConfigBean(); 94 } 95 96 101 public static Server getServerBean(ConfigContext ctx) throws ConfigException { 102 final String serverName = java.lang.System.getProperty("com.sun.aas.instanceName"); 103 String xpath = ServerXPathHelper.getServerIdXpath(serverName); 104 final Server server = 105 (Server) ConfigBeansFactory.getConfigBeanByXPath(ctx, xpath); 106 return server; 107 } 108 109 114 public static Config getConfigBean(ConfigContext ctx) throws ConfigException { 115 return ServerBeansFactory.getConfigModel(ctx); 116 } 117 118 123 public static ConfigBean[] getResources(ConfigContext ctx, String type) throws ConfigException { 124 Resources r = getDomainBean(ctx).getResources(); 125 126 128 130 return r.getChildBeansByName(type); 133 } 134 135 142 public static ConnectorService getConnectorServiceBean(ConfigContext ctx) throws ConfigException{ 143 return getConfigBean(ctx).getConnectorService(); 144 } 145 146 147 150 public static SecurityService getSecurityServiceBean(ConfigContext ctx) throws ConfigException { 151 Config cfg = ServerBeansFactory.getConfigBean(ctx); 152 return cfg.getSecurityService(); 153 } 154 155 158 public static TransactionService getTransactionServiceBean(ConfigContext ctx) throws ConfigException { 159 Config cfg = ServerBeansFactory.getConfigBean(ctx); 160 return cfg.getTransactionService(); 161 } 162 163 166 public static HttpService getHttpServiceBean(ConfigContext ctx) throws ConfigException { 167 Config cfg = ServerBeansFactory.getConfigBean(ctx); 168 HttpService httpService = cfg.getHttpService(); 169 return httpService; 170 } 171 172 175 public static JmsService getJmsServiceBean(ConfigContext ctx) throws ConfigException { 176 Config cfg = ServerBeansFactory.getConfigBean(ctx); 177 JmsService jmsService = cfg.getJmsService(); 178 return jmsService; 179 } 180 181 184 public static JmsHost getJmsHostBean(ConfigContext ctx) throws ConfigException { 185 JmsService jmsService = ServerBeansFactory.getJmsServiceBean(ctx); 186 JmsHost[] hosts = jmsService.getJmsHost(); 187 return hosts[0]; 188 } 189 190 193 public static IiopService getIiopServiceBean(ConfigContext ctx) throws ConfigException { 194 Config cfg = ServerBeansFactory.getConfigBean(ctx); 195 IiopService iiopService = cfg.getIiopService(); 196 return iiopService; 197 } 198 199 202 public static JavaConfig getJavaConfigBean(ConfigContext ctx) throws ConfigException { 203 Config cfg = ServerBeansFactory.getConfigBean(ctx); 204 JavaConfig javaConfig = cfg.getJavaConfig(); 205 return javaConfig; 206 } 207 208 211 public static String getAdminServiceLogLevel(ConfigContext ctx) throws ConfigException { 212 Config cfg = ServerBeansFactory.getConfigBean(ctx); 213 LogService logService = cfg.getLogService(); 214 return logService.getModuleLogLevels().getAdmin(); 215 } 216 217 220 public static String getEjbContainerLogLevel(ConfigContext ctx) throws ConfigException { 221 Config cfg = ServerBeansFactory.getConfigBean(ctx); 222 LogService logService = cfg.getLogService(); 223 return logService.getModuleLogLevels().getEjbContainer(); 224 } 225 226 227 230 public static String getWebContainerLogLevel(ConfigContext ctx) throws ConfigException { 231 Config cfg = ServerBeansFactory.getConfigBean(ctx); 232 LogService logService = cfg.getLogService(); 233 return logService.getModuleLogLevels().getWebContainer(); 234 } 235 236 237 240 public static String getMdbContainerLogLevel(ConfigContext ctx) throws ConfigException { 241 Config cfg = ServerBeansFactory.getConfigBean(ctx); 242 LogService logService = cfg.getLogService(); 243 return logService.getModuleLogLevels().getMdbContainer(); 244 } 245 246 249 public static String getSecurityServiceLogLevel(ConfigContext ctx) throws ConfigException { 250 Config cfg = ServerBeansFactory.getConfigBean(ctx); 251 254 LogService logService = cfg.getLogService(); 255 return logService.getModuleLogLevels().getSecurity(); 256 } 257 258 261 public static String getTransactionServiceLogLevel(ConfigContext ctx) throws ConfigException { 262 Config cfg = ServerBeansFactory.getConfigBean(ctx); 263 LogService logService = cfg.getLogService(); 264 return logService.getModuleLogLevels().getJts(); 265 266 } 267 268 271 public static String getCorbaLogLevel(ConfigContext ctx) throws ConfigException { 272 Config cfg = ServerBeansFactory.getConfigBean(ctx); 273 LogService logService = cfg.getLogService(); 274 return logService.getModuleLogLevels().getCorba(); 275 } 276 277 280 public static String getRootLogLevel(ConfigContext ctx) throws ConfigException { 281 Config cfg = ServerBeansFactory.getConfigBean(ctx); 282 LogService logService = cfg.getLogService(); 283 return logService.getModuleLogLevels().getRoot(); 284 } 285 286 287 290 public static MdbContainer getMdbContainerBean(ConfigContext ctx) throws ConfigException { 291 Config cfg = ServerBeansFactory.getConfigBean(ctx); 292 MdbContainer container = cfg.getMdbContainer(); 293 return container; 294 } 295 296 299 public static DasConfig getDasConfigBean(ConfigContext ctx) 300 throws ConfigException { 301 Config cfg = ServerBeansFactory.getConfigBean(ctx); 302 AdminService as = cfg.getAdminService(); 303 DasConfig ds = null; 304 if(as != null) ds = as.getDasConfig(); 305 return ds; } 307 308 309 312 320 321 324 public static Applications getApplicationsBean(ConfigContext ctx) 325 throws ConfigException { 326 return ServerBeansFactory.getDomainBean(ctx).getApplications(); 327 } 328 329 332 public static WebContainer getWebContainerBean(ConfigContext ctx) 333 throws ConfigException { 334 Config cfg = ServerBeansFactory.getConfigBean(ctx); 335 WebContainer webContainer = cfg.getWebContainer(); 336 return webContainer; 337 } 338 339 345 public static Server getServerBeanFromArray(Server[] serverArray,String serverName) { 346 for (int i=0;i<serverArray.length;i++) { 347 if (serverArray[i].getName().equals(serverName)) { 348 return serverArray[i]; 349 } 350 } 351 return serverArray[0]; 353 } 354 355 366 public static boolean isReferenced(final AdminObjectResource res, final ConfigContext ctx) throws ConfigException { 367 return isReferencedByResourceRef(res.getJndiName(), ctx); 368 } 369 370 381 public static Set getReferers(final AdminObjectResource res, final ConfigContext ctx) throws ConfigException{ 382 return getResourceRefsReferencing(res.getJndiName(), ctx); 383 } 384 385 396 public static boolean isReferenced(final AppclientModule cm, final ConfigContext ctx) throws ConfigException { 397 return isReferencedByApplicationRef(cm.getName(), ctx); 398 } 399 400 411 public static Set getReferers(final AppclientModule cm, final ConfigContext ctx) throws ConfigException{ 412 return getApplicationRefsReferencing(cm.getName(), ctx); 413 } 414 415 426 public static boolean isReferenced(final Config res, final ConfigContext ctx) throws ConfigException { 427 if (null == res || null == ctx) { return false; } 428 for (final Iterator it = getServers(ctx).iterator(); it.hasNext();){ 429 if (res.getName().equals(((Server) it.next()).getConfigRef())){ 430 return true; 431 } 432 } 433 434 for (final Iterator it = getClusters(ctx).iterator(); it.hasNext();){ 435 if (res.getName().equals(((Cluster) it.next()).getConfigRef())){ 436 return true; 437 } 438 } 439 440 return false; 441 } 442 443 454 public static Set getReferers(final Config res, final ConfigContext ctx) throws ConfigException{ 455 if (null == res || null == ctx) { return Collections.EMPTY_SET; } 456 final Set result = new HashSet(); 457 for (final Iterator it = getServers(ctx).iterator(); it.hasNext();){ 458 final Server el = (Server) it.next(); 459 if (res.getName().equals(el.getConfigRef())){ 460 result.add(el); 461 } 462 } 463 464 for (final Iterator it = getClusters(ctx).iterator(); it.hasNext();){ 465 final Cluster el = (Cluster) it.next(); 466 if (res.getName().equals(el.getConfigRef())){ 467 result.add(el); 468 } 469 } 470 471 return result; 472 } 473 474 485 public static boolean isReferenced(final NodeAgent res, final ConfigContext ctx) throws ConfigException { 486 if (null == res || null == ctx) { return false; } 487 for (final Iterator it = getServers(ctx).iterator(); it.hasNext();){ 488 if (res.getName().equals(((Server) it.next()).getNodeAgentRef())){ 489 return true; 490 } 491 } 492 493 return false; 494 } 495 496 507 public static Set getReferers(final NodeAgent res, final ConfigContext ctx) throws ConfigException{ 508 if (null == res || null == ctx) { return Collections.EMPTY_SET; } 509 final Set result = new HashSet(); 510 for (final Iterator it = getServers(ctx).iterator(); it.hasNext();){ 511 final Server el = (Server) it.next(); 512 if (res.getName().equals(el.getNodeAgentRef())){ 513 result.add(el); 514 } 515 } 516 return result; 517 } 518 519 530 public static boolean isReferenced(final ConnectorResource res, final ConfigContext ctx) throws ConfigException { 531 return isReferencedByResourceRef(res.getJndiName(), ctx); 532 } 533 534 545 public static Set getReferers(final ConnectorResource res, final ConfigContext ctx) throws ConfigException{ 546 return getResourceRefsReferencing(res.getJndiName(), ctx); 547 } 548 549 560 public static boolean isReferenced(final Cluster cm, final ConfigContext ctx) throws ConfigException { 561 if (null == cm || null == ctx) {return false;} 562 563 final Set refs = getClusterRefs(ctx); 564 if (refs.isEmpty()) { return false; } 565 for (final Iterator it = refs.iterator(); it.hasNext(); ){ 566 if (cm.getName().equals(((ClusterRef) it.next()).getRef())){ 567 return true; 568 } 569 } 570 return false; 571 } 572 573 584 public static Set getReferers(final Cluster cm, final ConfigContext ctx) throws ConfigException{ 585 if (null == cm || null == ctx) {return Collections.EMPTY_SET;} 586 587 final Set refs = getClusterRefs(ctx); 588 if (refs.isEmpty()) { return Collections.EMPTY_SET; } 589 590 final Set result = new HashSet(); 591 for (final Iterator it = refs.iterator(); it.hasNext(); ){ 592 final ClusterRef ref = (ClusterRef) it.next(); 593 if (cm.getName().equals(ref.getRef())){ 594 result.add(ref); 595 } 596 } 597 return result; 598 } 599 600 611 public static boolean isReferenced(final ConnectorConnectionPool cm, final ConfigContext ctx) throws ConfigException { 612 if (null == cm || null == ctx) {return false;} 613 614 final Set crs = getConnectorResources(ctx); 615 if (crs.isEmpty()) { return false; } 616 for (final Iterator it = crs.iterator(); it.hasNext(); ){ 617 if (cm.getName().equals(((ConnectorResource) it.next()).getPoolName())){ 618 return true; 619 } 620 } 621 return false; 622 } 623 624 635 public static Set getReferers(final ConnectorConnectionPool cm, final ConfigContext ctx) throws ConfigException{ 636 if (null == cm || null == ctx) {return Collections.EMPTY_SET;} 637 638 final Set crs = getConnectorResources(ctx); 639 if (crs.isEmpty()) { return Collections.EMPTY_SET; } 640 641 final Set result = new HashSet(); 642 for (final Iterator it = crs.iterator(); it.hasNext(); ){ 643 final ConnectorResource cr = (ConnectorResource) it.next(); 644 if (cm.getName().equals(cr.getPoolName())){ 645 result.add(cr); 646 } 647 } 648 return result; 649 } 650 651 662 public static boolean isReferenced(final ConnectorModule cm, final ConfigContext ctx) throws ConfigException { 663 return isReferencedByApplicationRef(cm.getName(), ctx); 664 } 665 666 677 public static Set getReferers(final ConnectorModule cm, final ConfigContext ctx) throws ConfigException{ 678 return getApplicationRefsReferencing(cm.getName(), ctx); 679 } 680 681 692 public static boolean isReferenced(final CustomResource res, final ConfigContext ctx) throws ConfigException { 693 return isReferencedByResourceRef(res.getJndiName(), ctx); 694 } 695 696 707 public static Set getReferers(final CustomResource res, final ConfigContext ctx) throws ConfigException{ 708 return getResourceRefsReferencing(res.getJndiName(), ctx); 709 } 710 721 public static boolean isReferenced(final EjbModule cm, final ConfigContext ctx) throws ConfigException { 722 return isReferencedByApplicationRef(cm.getName(), ctx); 723 } 724 725 736 public static Set getReferers(final EjbModule cm, final ConfigContext ctx) throws ConfigException{ 737 return getApplicationRefsReferencing(cm.getName(), ctx); 738 } 739 740 751 public static boolean isReferenced(final ExternalJndiResource res, final ConfigContext ctx) throws ConfigException { 752 return isReferencedByResourceRef(res.getJndiName(), ctx); 753 } 754 755 766 public static Set getReferers(final ExternalJndiResource res, final ConfigContext ctx) throws ConfigException{ 767 return getResourceRefsReferencing(res.getJndiName(), ctx); 768 } 769 780 public static boolean isReferenced(final J2eeApplication cm, final ConfigContext ctx) throws ConfigException { 781 return isReferencedByApplicationRef(cm.getName(), ctx); 782 } 783 784 795 public static Set getReferers(final J2eeApplication cm, final ConfigContext ctx) throws ConfigException{ 796 return getApplicationRefsReferencing(cm.getName(), ctx); 797 } 798 799 810 public static boolean isReferenced(final JdbcResource res, final ConfigContext ctx) throws ConfigException { 811 return isReferencedByResourceRef(res.getJndiName(), ctx); 812 } 813 814 825 public static Set getReferers(final JdbcResource res, final ConfigContext ctx) throws ConfigException{ 826 return getResourceRefsReferencing(res.getJndiName(), ctx); 827 } 828 839 public static boolean isReferenced(final LifecycleModule cm, final ConfigContext ctx) throws ConfigException { 840 return isReferencedByApplicationRef(cm.getName(), ctx); 841 } 842 843 854 public static Set getReferers(final LifecycleModule cm, final ConfigContext ctx) throws ConfigException{ 855 return getApplicationRefsReferencing(cm.getName(), ctx); 856 } 857 868 public static boolean isReferenced(final MailResource res, final ConfigContext ctx) throws ConfigException { 869 return isReferencedByResourceRef(res.getJndiName(), ctx); 870 } 871 872 883 public static Set getReferers(final MailResource res, final ConfigContext ctx) throws ConfigException{ 884 return getResourceRefsReferencing(res.getJndiName(), ctx); 885 } 886 897 public static boolean isReferenced(final PersistenceManagerFactoryResource res, final ConfigContext ctx) throws ConfigException { 898 return isReferencedByResourceRef(res.getJndiName(), ctx); 899 } 900 901 912 public static Set getReferers(final PersistenceManagerFactoryResource res, final ConfigContext ctx) throws ConfigException{ 913 return getResourceRefsReferencing(res.getJndiName(), ctx); 914 } 915 916 927 public static boolean isReferenced(final ResourceAdapterConfig res, final ConfigContext ctx) throws ConfigException { 928 return isReferencedByResourceRef(res.getResourceAdapterName(), ctx); 929 } 930 931 942 public static Set getReferers(final ResourceAdapterConfig res, final ConfigContext ctx) throws ConfigException{ 943 return getResourceRefsReferencing(res.getResourceAdapterName(), ctx); 944 } 945 946 957 public static boolean isReferenced(final Server res, final ConfigContext ctx) throws ConfigException { 958 return isReferencedByServerRef(res.getName(), ctx); 959 } 960 961 972 public static Set getReferers(final Server res, final ConfigContext ctx) throws ConfigException{ 973 return getServerRefsReferencing(res.getName(), ctx); 974 } 975 986 public static boolean isReferenced(final WebModule cm, final ConfigContext ctx) throws ConfigException { 987 for (final Iterator it = getVirtualServers(ctx).iterator(); it.hasNext(); ){ 988 if (cm.getName().equals(((VirtualServer) it.next()).getDefaultWebModule())){ 989 return true; 990 } 991 } 992 993 return isReferencedByApplicationRef(cm.getName(), ctx); 994 } 995 996 1007 public static Set getReferers(final WebModule cm, final ConfigContext ctx) throws ConfigException{ 1008 return getApplicationRefsReferencing(cm.getName(), ctx); 1009 } 1010 1011 private static boolean isReferencedByApplicationRef(final String name, final ConfigContext ctx) throws ConfigException { 1012 for (final Iterator it = getApplicationRefs(ctx).iterator(); it.hasNext(); ){ 1013 if (name.equals(((ApplicationRef) it.next()).getRef())){ 1014 return true; 1015 } 1016 } 1017 return false; 1018 } 1019 1020 private static Set getApplicationRefsReferencing(final String name, final ConfigContext ctx) throws ConfigException { 1021 final Set refers = new HashSet(); 1022 for (final Iterator it = getApplicationRefs(ctx).iterator(); it.hasNext(); ){ 1023 final ApplicationRef ar = (ApplicationRef) it.next(); 1024 if (name.equals(ar.getRef())){ 1025 refers.add(ar); 1026 } 1027 } 1028 return refers; 1029 } 1030 1031 1032 1039 public static Set getApplicationRefs(final ConfigContext ctx) throws ConfigException { 1040 final Set refs = new HashSet(); 1041 for (final Iterator it = getServers(ctx).iterator(); it.hasNext();){ 1042 refs.addAll(Arrays.asList(((Server) it.next()).getApplicationRef())); 1043 } 1044 1045 for (final Iterator it = getClusters(ctx).iterator(); it.hasNext();){ 1046 refs.addAll(Arrays.asList(((Cluster) it.next()).getApplicationRef())); 1047 } 1048 1049 return refs; 1050 } 1051 1052 private static boolean isReferencedByResourceRef(final String name, final ConfigContext ctx) throws ConfigException { 1053 for (final Iterator it = getResourceRefs(ctx).iterator(); it.hasNext(); ){ 1054 if (name.equals(((ResourceRef) it.next()).getRef())){ 1055 return true; 1056 } 1057 } 1058 return false; 1059 } 1060 1061 private static Set getResourceRefsReferencing(final String name, final ConfigContext ctx) throws ConfigException { 1062 final Set refers = new HashSet(); 1063 for (final Iterator it = getResourceRefs(ctx).iterator(); it.hasNext(); ){ 1064 final ResourceRef ar = (ResourceRef) it.next(); 1065 if (name.equals(ar.getRef())){ 1066 refers.add(ar); 1067 } 1068 } 1069 return refers; 1070 } 1071 private static boolean isReferencedByServerRef(final String name, final ConfigContext ctx) throws ConfigException { 1072 for (final Iterator it = getServerRefs(ctx).iterator(); it.hasNext(); ){ 1073 if (name.equals(((ServerRef) it.next()).getRef())){ 1074 return true; 1075 } 1076 } 1077 return false; 1078 } 1079 1080 private static Set getServerRefsReferencing(final String name, final ConfigContext ctx) throws ConfigException { 1081 final Set refers = new HashSet(); 1082 for (final Iterator it = getServerRefs(ctx).iterator(); it.hasNext(); ){ 1083 final ServerRef ar = (ServerRef) it.next(); 1084 if (name.equals(ar.getRef())){ 1085 refers.add(ar); 1086 } 1087 } 1088 return refers; 1089 } 1090 1091 1092 1099 public static Set getResourceRefs(final ConfigContext ctx) throws ConfigException { 1100 final Set refs = new HashSet(); 1101 for (final Iterator it = getServers(ctx).iterator(); it.hasNext();){ 1102 refs.addAll(Arrays.asList(((Server) it.next()).getResourceRef())); 1103 } 1104 1105 for (final Iterator it = getClusters(ctx).iterator(); it.hasNext();){ 1106 refs.addAll(Arrays.asList(((Cluster) it.next()).getResourceRef())); 1107 } 1108 1109 return refs; 1110 } 1111 1112 1119 public static Set getServerRefs(final ConfigContext ctx) throws ConfigException { 1120 final Set refs = new HashSet(); 1121 for (final Iterator it = getLbConfigs(ctx).iterator(); it.hasNext();){ 1122 refs.addAll(Arrays.asList(((LbConfig) it.next()).getServerRef())); 1123 } 1124 1125 for (final Iterator it = getClusters(ctx).iterator(); it.hasNext();){ 1126 refs.addAll(Arrays.asList(((Cluster) it.next()).getServerRef())); 1127 } 1128 return refs; 1129 } 1130 1131 1142 public static Set getConfigs(final ConfigContext ctx) throws ConfigException { 1143 if (null == ctx) { 1144 return Collections.EMPTY_SET; 1145 } 1146 final Domain dom = (Domain) ctx.getRootConfigBean(); 1147 if (null == dom){ 1148 return Collections.EMPTY_SET; 1149 } 1150 final Configs configs = dom.getConfigs(); 1151 if (null == configs || null == configs.getConfig()){ 1152 return Collections.EMPTY_SET; 1153 } 1154 final Set result = new HashSet(); 1155 result.addAll(Arrays.asList(configs.getConfig())); 1156 return result; 1157 } 1158 1159 1170 public static Set getClusters(final ConfigContext ctx) throws ConfigException { 1171 if (null == ctx) { 1172 return Collections.EMPTY_SET; 1173 } 1174 final Domain dom = (Domain) ctx.getRootConfigBean(); 1175 if (null == dom){ 1176 return Collections.EMPTY_SET; 1177 } 1178 final Clusters clusters = dom.getClusters(); 1179 if (null == clusters || null == clusters.getCluster()){ 1180 return Collections.EMPTY_SET; 1181 } 1182 final Set result = new HashSet(); 1183 result.addAll(Arrays.asList(clusters.getCluster())); 1184 return result; 1185 } 1186 1197 public static Set getServers(final ConfigContext ctx) throws ConfigException { 1198 if (null == ctx) { 1199 return Collections.EMPTY_SET; 1200 } 1201 final Domain dom = (Domain) ctx.getRootConfigBean(); 1202 if (null == dom){ 1203 return Collections.EMPTY_SET; 1204 } 1205 final Servers servers = dom.getServers(); 1206 if (null == servers || null == servers.getServer()){ 1207 return Collections.EMPTY_SET; 1208 } 1209 final Set result = new HashSet(); 1210 result.addAll(Arrays.asList(servers.getServer())); 1211 return result; 1212 } 1213 1214 1225 public static Set getVirtualServers(final ConfigContext ctx) throws ConfigException { 1226 final Set result = new HashSet(); 1227 for (final Iterator it = getHttpServices(ctx).iterator(); it.hasNext(); ){ 1228 final ConfigBean [] vs = ((HttpService) it.next()).getVirtualServer(); 1229 if (null != vs){ 1230 result.addAll(Arrays.asList(vs)); 1231 } 1232 } 1233 return result; 1234 } 1235 1246 public static Set getHttpServices(final ConfigContext ctx) throws ConfigException { 1247 final Set result = new HashSet(); 1248 for (final Iterator it = getConfigs(ctx).iterator(); it.hasNext(); ){ 1249 result.add(((Config) it.next()).getHttpService()); 1250 } 1251 return result; 1252 } 1253 1263 public static Set getClusterRefs(final ConfigContext ctx) throws ConfigException { 1264 final Set lbconfigs = getLbConfigs(ctx); 1265 if (lbconfigs.isEmpty()){ 1266 return Collections.EMPTY_SET; 1267 } 1268 final Set result = new HashSet(); 1269 for (final Iterator it = lbconfigs.iterator(); it.hasNext();){ 1270 final ConfigBean [] cr = ((LbConfig) it.next()).getClusterRef(); 1271 if (null != cr){ 1272 result.addAll(Arrays.asList(cr)); 1273 } 1274 } 1275 return result; 1276 } 1277 1278 1289 1290 public static Set getConnectorResources(final ConfigContext ctx) throws ConfigException { 1291 final Set result = new HashSet(); 1292 final ConfigBean [] cr = getResources(ctx, ServerTags.CONNECTOR_RESOURCE); 1293 if (null != cr){ 1294 result.addAll(Arrays.asList(cr)); 1295 } 1296 return result; 1297 } 1298 1299 1300 1311 public static Set getLbConfigs(final ConfigContext ctx) throws ConfigException { 1312 if (null == ctx) { 1313 return Collections.EMPTY_SET; 1314 } 1315 final Domain dom = (Domain) ctx.getRootConfigBean(); 1316 if (null == dom){ 1317 return Collections.EMPTY_SET; 1318 } 1319 final LbConfigs lbconfigs = dom.getLbConfigs(); 1320 if (null == lbconfigs || null == lbconfigs.getLbConfig()){ 1321 return Collections.EMPTY_SET; 1322 } 1323 final Set result = new HashSet(); 1324 result.addAll(Arrays.asList(lbconfigs.getLbConfig())); 1325 return result; 1326 } 1327 1328 1329 1341 public static String getVirtualServersByAppName(ConfigContext ctx, 1342 String appName) 1343 throws ConfigException { 1344 1345 ApplicationRef ar = getServerBean(ctx).getApplicationRefByRef(appName); 1346 if (ar == null) return null; 1348 return ar.getVirtualServers(); 1349 1350 1351 1366 } 1367 1376 public static List<Mbean> getAllMBeanDefinitions(final ConfigContext cc) throws ConfigException { 1377 final Domain d = ServerBeansFactory.getDomainBean(cc); 1378 final Applications as = d.getApplications(); 1379 final Mbean[] ma = as.getMbean(); 1380 final List<Mbean> ml = Arrays.asList(ma); 1381 return ( Collections.unmodifiableList(ml) ); 1382 } 1383 1384 1390 public static List<Mbean> getReferencedMBeans(final ConfigContext cc, final String sn) throws ConfigException { 1391 final List<Mbean> em = new ArrayList<Mbean>(); 1392 final Domain d = ServerBeansFactory.getDomainBean(cc); 1393 final Server[] ss = d.getServers().getServer(); 1394 for(Server a : ss) { 1395 if (sn.equals(a.getName())) { 1396 ApplicationRef[] ars = a.getApplicationRef(); 1397 for (ApplicationRef ar : ars) { 1398 final Mbean tmp = getMBeanDefinition(cc, ar.getRef()); 1399 if (tmp != null) 1400 em.add(tmp); 1401 } 1402 } 1403 } 1404 return ( Collections.unmodifiableList(em) ); 1405 } 1406 1407 public static boolean isReferencedMBean(final ConfigContext cc, final String sn, final String mn) throws ConfigException { 1408 final List<Mbean> rm = getReferencedMBeans(cc, sn); 1409 boolean refd = false; 1410 for (Mbean m : rm) { 1411 if (m.getName().equals(mn)) { 1412 refd = true; 1413 break; 1414 } 1415 } 1416 return ( refd ); 1417 } 1418 1419 1431 1432 public static boolean isReferencedMBeanInCluster(final ConfigContext cc, final String cn, final String mn) throws ConfigException { 1433 assert cc != null && cn != null && mn != null; 1435 if(cc == null || cn == null || mn == null) 1438 return false; 1439 1440 final Server[] ss = ServerHelper.getServersInCluster(cc, cn); 1441 1442 if(ss == null || ss.length < 1) 1443 return false; 1444 1445 final boolean[] isrefs = new boolean[ss.length]; 1446 1447 for(int i = 0; i < ss.length; i++) 1448 { 1449 isrefs[i] = isReferencedMBean(cc, ss[i].getName(), mn); 1450 } 1451 1452 for(int i = 1; i < ss.length; i++) 1455 { 1456 if(isrefs[i] != isrefs[0]) 1457 { 1458 String messy = prepareMessyStringMessage(ss, isrefs); 1459 String msg = StringManager.getManager(ServerBeansFactory.class).getString("CorruptClusterConfig", 1460 new Object [] { cn, mn, messy} ); 1461 throw new ConfigException(msg); 1462 } 1463 } 1464 return isrefs[0]; } 1466 1467 1475 public static List<Mbean> getFullyEnabledMBeans(final ConfigContext cc, final String sn) throws ConfigException { 1476 final List<Mbean> em = new ArrayList<Mbean>(); 1478 final Domain d = ServerBeansFactory.getDomainBean(cc); 1479 final Server[] ss = d.getServers().getServer(); 1480 for(Server a : ss) { 1481 if (sn.equals(a.getName())) { 1482 ApplicationRef[] ars = a.getApplicationRef(); 1483 for (ApplicationRef ar : ars) { 1484 if (ar.isEnabled()) { final Mbean tmp = getMBeanDefinition(cc, ar.getRef()); 1486 if (tmp != null && tmp.isEnabled()) { em.add(tmp); 1489 } 1490 } 1491 } 1492 } 1493 } 1494 return ( Collections.unmodifiableList(em) ); 1495 } 1496 1497 public static Mbean getMBeanDefinition(final ConfigContext cc, final String n) throws ConfigException { 1498 final Domain d = ServerBeansFactory.getDomainBean(cc); 1499 final Applications a = d.getApplications(); 1500 final Mbean[] ms = a.getMbean(); 1501 for (Mbean m : ms) { 1502 if (n.equals(m.getName())) { 1503 return ( m ); 1504 } 1505 } 1506 return ( null ); 1507 } 1508 1509 1518 public static List<Mbean> getFullyEnabledUserDefinedMBeans(final ConfigContext cc, final String sn) throws ConfigException { 1519 final List<Mbean> em = ServerBeansFactory.getFullyEnabledMBeans(cc, sn); 1520 final List<Mbean> uem = new ArrayList<Mbean>(); 1521 for (Mbean m : em) { 1522 assert (m.isEnabled()); 1523 if (IAdminConstants.USER.equals(m.getObjectType())) { 1524 uem.add(m); 1525 } 1526 } 1527 return ( Collections.unmodifiableList(uem) ); 1528 } 1529 1530 public static void addMbeanDefinition(final ConfigContext cc, final Mbean m) throws ConfigException { 1531 final Domain d = ServerBeansFactory.getDomainBean(cc); 1532 final Applications as = d.getApplications(); 1533 as.addMbean(m); 1534 } 1535 1536 public static void addMbeanReference(final ConfigContext cc, final String toThisMbean, final String server) throws ConfigException { 1537 final Domain d = ServerBeansFactory.getDomainBean(cc); 1538 final Servers ss = d.getServers(); 1539 final Server s = ss.getServerByName(server); 1540 final ApplicationRef ar = new ApplicationRef(); 1541 ar.setRef(toThisMbean); 1542 ar.setEnabled(true); 1543 s.addApplicationRef(ar); 1544 } 1545 1546 public static void addClusterMbeanReference(final ConfigContext cc, final String toThisMbean, final String clusterName) throws ConfigException { 1547 final Cluster cluster = ClusterHelper.getClusterByName(cc, clusterName); 1548 final ApplicationRef ar = new ApplicationRef(); 1549 ar.setRef(toThisMbean); 1550 ar.setEnabled(true); 1551 cluster.addApplicationRef(ar); 1552 } 1553 1554 public static void removeMbeanDefinition(final ConfigContext cc, final String n) throws ConfigException { 1555 final Domain d = ServerBeansFactory.getDomainBean(cc); 1556 final Applications as = d.getApplications(); 1557 as.removeMbean(as.getMbeanByName(n)); 1558 } 1559 1560 public static void removeMbeanReference(final ConfigContext cc, final String ref, final String server) throws ConfigException { 1561 final Domain d = ServerBeansFactory.getDomainBean(cc); 1562 final Servers ss = d.getServers(); 1563 final Server s = ss.getServerByName(server); 1564 final ApplicationRef ar = s.getApplicationRefByRef(ref); 1565 s.removeApplicationRef(ar); 1566 } 1567 1568 public static void removeClusterMbeanReference(final ConfigContext cc, final String ref, final String clusterName) throws ConfigException { 1569 final Cluster cluster = ClusterHelper.getClusterByName(cc, clusterName); 1570 final ApplicationRef ar = cluster.getApplicationRefByRef(ref); 1571 cluster.removeApplicationRef(ar); 1572 } 1573 1574 public static Server[] getServersReferencingMBeanDefinition(final ConfigContext cc, final String name) throws ConfigException { 1575 Server[] ss = null; 1577 final List<Server> list = new ArrayList<Server> (); 1578 ss = ServerBeansFactory.getDomainBean(cc).getServers().getServer(); 1579 int numberOfReferencingServers = 0; 1580 for (Server s : ss) { 1581 boolean referenced = false; 1582 final String sName = s.getName(); 1583 referenced = ServerBeansFactory.isReferencedMBean(cc, sName, name); 1584 if (referenced) { 1585 list.add(s); 1586 } 1587 } 1588 final Server[] rss = new Server[list.size()]; 1589 return ( list.toArray(rss) ); 1590 } 1591 private static String prepareMessyStringMessage(Server[] ss, boolean[] isrefs) 1592 { 1593 StringBuilder sb = new StringBuilder (); 1596 1597 for(int i = 0; i < ss.length; i++) 1598 { 1599 if(i != 0) 1600 sb.append(", "); 1601 String s = isrefs[i] ? "referenced" : "not-referenced"; 1602 sb.append(ss[i].getName()).append(":").append(s); 1603 } 1604 1605 return sb.toString(); 1606 } 1607} | Popular Tags |