1 23 24 package com.sun.enterprise.admin.servermgmt.pe; 25 26 27 28 29 import com.sun.enterprise.admin.servermgmt.DomainConfig; 30 import com.sun.enterprise.admin.servermgmt.DomainConfigValidator; 31 import com.sun.enterprise.admin.servermgmt.FileValidator; 32 import com.sun.enterprise.admin.servermgmt.InvalidConfigException; 33 import com.sun.enterprise.admin.servermgmt.PortValidator; 34 import com.sun.enterprise.admin.servermgmt.StringValidator; 35 import com.sun.enterprise.util.i18n.StringManager; 36 import java.lang.StringBuffer ; 37 import java.util.HashSet ; 38 import java.util.Iterator ; 39 import java.util.Map.Entry; 40 import java.util.Map ; 41 import java.util.Set ; 42 import java.util.TreeMap ; 43 import java.util.TreeSet ; 44 45 49 class PEDomainConfigValidator extends DomainConfigValidator 50 { 51 54 private static final StringManager strMgr = 55 StringManager.getManager(PEDomainConfigValidator.class); 56 57 private static final String lInstallRoot = strMgr.getString("installRoot"); 58 private static final String lDomainsRoot = strMgr.getString("domainsRoot"); 59 private static final String lJavaHome = strMgr.getString("javaHome"); 60 private static final String lAdminPort = strMgr.getString("adminPort"); 61 private static final String lInstancePort = strMgr.getString("instancePort"); 62 private static final String lHostName = strMgr.getString("hostName"); 63 private static final String lJmsUser = strMgr.getString("jmsUser"); 64 private static final String lJmsPasswd = strMgr.getString("jmsPassword"); 65 private static final String lJmsPort = strMgr.getString("jmsPort"); 66 private static final String lOrbPort = strMgr.getString("orbPort"); 67 68 static DomainConfigEntryInfo[] entries = new DomainConfigEntryInfo[] 69 { 70 new DomainConfigEntryInfo(DomainConfig.K_INSTALL_ROOT, 71 "java.lang.String", lInstallRoot, 72 new FileValidator(lInstallRoot, "dr")), 73 new DomainConfigEntryInfo(DomainConfig.K_DOMAINS_ROOT, 74 "java.lang.String", lDomainsRoot, 75 new FileValidator(lDomainsRoot, "drw")), 76 new DomainConfigEntryInfo(DomainConfig.K_ADMIN_PORT, 77 "java.lang.Integer", lAdminPort, 78 new PortValidator(lAdminPort)), 79 new DomainConfigEntryInfo(DomainConfig.K_INSTANCE_PORT, 80 "java.lang.Integer", lInstancePort, 81 new PortValidator(lInstancePort)), 82 new DomainConfigEntryInfo(DomainConfig.K_HOST_NAME, 83 "java.lang.String", lHostName, 84 new StringValidator(lHostName)), 85 new DomainConfigEntryInfo(DomainConfig.K_JMS_USER, 86 "java.lang.String", lJmsUser, 87 new StringValidator(lJmsUser)), 88 new DomainConfigEntryInfo(DomainConfig.K_JMS_PASSWORD, 89 "java.lang.String", lJmsPasswd, 90 new StringValidator(lJmsPasswd)), 91 new DomainConfigEntryInfo(DomainConfig.K_ORB_LISTENER_PORT, 92 "java.lang.Integer", lOrbPort, 93 new PortValidator(lOrbPort)), 94 new DomainConfigEntryInfo(DomainConfig.K_JMS_PORT, 95 "java.lang.Integer", lJmsPort, 96 new PortValidator(lJmsPort)) 97 }; 98 99 100 PEDomainConfigValidator() 101 { 102 super(entries); 103 } 104 105 public void validate(Object domainConfig) throws InvalidConfigException{ 106 super.validate(domainConfig); 107 uniquePorts((DomainConfig) domainConfig); 108 } 109 110 protected boolean isValidate(String name, Object domainConfig) 111 { 112 boolean isPortEntry = DomainConfig.K_ADMIN_PORT.equals(name) || 113 DomainConfig.K_INSTANCE_PORT.equals(name) || 114 DomainConfig.K_ORB_LISTENER_PORT.equals(name) || 115 DomainConfig.K_JMS_PORT.equals(name); 116 return (isPortEntry) ? isValidatePorts((Map )domainConfig) : true; 117 } 118 119 private boolean isValidatePorts(Map domainConfig) 120 { 121 Boolean isValidatePorts = 122 (Boolean )domainConfig.get(DomainConfig.K_VALIDATE_PORTS); 123 return (null != isValidatePorts) ? 124 isValidatePorts.booleanValue() : true; 125 } 126 127 final void uniquePorts(final DomainConfig dc) throws InvalidConfigException{ 128 final Map ports = dc.getPorts(); 129 final Set portValues = new HashSet (ports.values()); 130 if (ports.keySet().size() != portValues.size()){ 131 throw new InvalidConfigException(getMessage(ports)); 132 } 133 } 134 135 private final String getMessage(final Map ports){ 136 return getLocalizedString("duplicatePorts", getDuplicatePorts(ports)); 137 } 138 139 private final String getLocalizedString(final String key, final Object o){ 140 return strMgr.getString(key, o); 141 } 142 143 final String getDuplicatePorts(final Map ports){ 144 return printDuplicatesFromMap(reverseMap(ports)); 145 } 146 147 148 155 private final Map reverseMap(final Map inputMap){ 156 final Map outputMap = new TreeMap (); 157 for (Iterator entries = inputMap.entrySet().iterator(); entries.hasNext(); ){ 158 Map.Entry entry = (Map.Entry ) entries.next(); 159 addEntryToMap(entry.getKey(), entry.getValue(), outputMap); 160 } 161 return outputMap; 162 } 163 164 168 private final void addEntryToMap(final Object key, final Object value, final Map map){ 169 if (!map.containsKey(value)){ 170 map.put(value, new TreeSet ()); 171 } 172 ((Set )map.get(value)).add(key); 173 } 174 175 180 private final String printDuplicatesFromMap(final Map map){ 181 final StringBuffer sb = new StringBuffer (); 182 final Iterator it = map.entrySet().iterator(); 183 Map.Entry entry = getNextDuplicate(it); 184 if (entry != null){ 185 printEntry(sb, entry); 186 while ((entry = getNextDuplicate(it)) != null){ 187 sb.append(", "); 188 printEntry(sb, entry); 189 } 190 } 191 return sb.toString(); 192 } 193 194 195 199 private final Map.Entry getNextDuplicate(final Iterator it){ 200 while (it.hasNext()){ 201 Map.Entry result = (Map.Entry ) it.next(); 202 if (((Set )result.getValue()).size() > 1){ 203 return result; 204 } 205 } 206 return null; 207 } 208 209 private final void printEntry(final StringBuffer sb, final Map.Entry entry){ 210 printEntry(sb, (Object ) entry.getKey(), (Set ) entry.getValue()); 211 } 212 213 218 private final void printEntry(final StringBuffer sb, final Object key, final Set dups){ 219 sb.append(key).append(" -> "); 220 printSet(sb, dups); 221 } 222 223 226 private final void printSet(final StringBuffer sb, final Set set){ 227 sb.append("{"); 228 String separator = ""; 229 for (Iterator it = set.iterator(); it.hasNext(); ){ 230 sb.append(separator).append(it.next()); 231 separator = ", "; 232 } 233 sb.append("}"); 234 } 235 } 236 | Popular Tags |