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.Server; 28 import com.sun.enterprise.config.serverbeans.Cluster; 29 30 import com.sun.enterprise.util.i18n.StringManager; 31 32 import java.util.ArrayList ; 33 34 public abstract class ReferenceHelperBase { 35 36 protected static final StringManager _strMgr=StringManager.getManager(ReferenceHelperBase.class); 37 38 public ReferenceHelperBase() { 39 } 40 41 protected abstract Server[] getReferencingServers(ConfigContext configContext, String name) 42 throws ConfigException; 43 protected abstract Cluster[] getReferencingClusters(ConfigContext configContext, String name) 44 throws ConfigException; 45 46 49 public boolean isReferenced(ConfigContext configContext, String name) 50 throws ConfigException 51 { 52 Server[] servers = getReferencingServers(configContext, name); 54 if (servers.length > 0) { 55 return true; 56 } 57 Cluster[] clusters = getReferencingClusters(configContext, name); 59 if (clusters.length > 0) { 60 return true; 61 } 62 return false; 63 } 64 65 69 public boolean isReferencedByServerOnly(ConfigContext configContext, 70 String name, String serverName) throws ConfigException 71 { 72 Server[] servers = getReferencingServers(configContext, name); 73 if (servers.length == 1 && servers[0].getName().equals(serverName)) { 74 Cluster[] clusters = getReferencingClusters(configContext, name); 77 if (clusters.length == 0) { 78 return true; 79 } 80 } 81 return false; 82 } 83 84 88 public boolean isReferencedByClusterOnly(ConfigContext configContext, 89 String name, String clusterName) throws ConfigException 90 { 91 Cluster[] clusters = getReferencingClusters(configContext, name); 93 if (clusters.length == 1 && clusters[0].getName().equals(clusterName)) { 94 Server[] servers = getReferencingServers(configContext, name); 95 if (servers.length == 0) { 96 return true; 97 } else { 98 Server[] clusterServers = ServerHelper.getServersInCluster(configContext, clusterName); 101 if (clusterServers.length == servers.length) { 102 boolean found = false; 103 for (int i = 0; i < clusterServers.length; i++) { 104 found = false; 105 for (int j = 0; j < servers.length; j++) { 106 if (clusterServers[i].getName().equals(servers[j].getName())) { 107 found = true; 108 break; 109 } 110 } 111 if (!found) { 112 return false; 113 } 114 } 115 if (found) { 116 return true; 117 } 118 } 119 } 120 } 121 return false; 122 } 123 124 128 public String getReferenceesAsString(ConfigContext configContext, String name) 129 throws ConfigException 130 { 131 Server[] servers = getReferencingServers(configContext, name); 132 Cluster[] clusters = getReferencingClusters(configContext, name); 133 String serverList = ServerHelper.getServersAsString(servers); 134 String clusterList = ClusterHelper.getClustersAsString(clusters); 135 if (serverList.length() > 0) { 136 if (clusterList.length() > 0) { 137 return serverList + "," + clusterList; 138 } 139 return serverList; 140 } else { 141 return clusterList; 142 } 143 } 144 } 145 | Popular Tags |