1 23 24 package com.sun.enterprise.admin.servermgmt; 25 26 import com.sun.enterprise.util.i18n.StringManager; 27 import com.sun.enterprise.admin.servermgmt.InvalidConfigException; 28 29 import java.util.HashMap ; 30 31 36 public abstract class DomainConfigValidator extends Validator 37 { 38 41 private static final StringManager strMgr = 42 StringManager.getManager(DomainConfigValidator.class); 43 44 49 protected static class DomainConfigEntryInfo 50 { 51 final String key; 52 final String dataType; 53 final String displayText; 54 final Validator validator; 55 56 57 public DomainConfigEntryInfo(String key, 58 String dataType, 59 String displayText, 60 Validator validator) 61 { 62 this.key = key; 63 this.dataType = dataType; 64 this.displayText = displayText; 65 this.validator = validator; 66 } 67 68 72 public boolean hasValidator() 73 { 74 return (validator != null); 75 } 76 } 77 78 82 private DomainConfigEntryInfo[] entries; 83 84 89 protected DomainConfigValidator(DomainConfigEntryInfo[] entries) 90 { 91 super(strMgr.getString("domainConfig"), DomainConfig.class); 92 this.entries = entries; 93 } 94 95 protected DomainConfigValidator(String name, Class type, DomainConfigEntryInfo[] entries) 96 { 97 super(name, type); 98 this.entries = entries; 99 } 100 101 115 public void validate(Object domainConfig) 116 throws InvalidConfigException 117 { 118 super.validate(domainConfig); 119 for (int i = 0; i < entries.length; i++) 120 { 121 if (isValidate(entries[i].key, domainConfig)) 122 { 123 final Object value = ((HashMap )domainConfig).get(entries[i].key); 124 if (entries[i].hasValidator()) 125 { 126 entries[i].validator.validate(value); 127 } 128 } 129 } 130 } 131 132 136 public boolean isKeyAllowed(Object key) 137 { 138 return (get(key) != null); 139 } 140 141 147 public boolean isValueValid(Object key, Object value) 148 { 149 boolean isValid = false; 150 final DomainConfigEntryInfo info = get(key); 151 if (info != null) 152 { 153 if (info.hasValidator()) 154 { 155 try 156 { 157 info.validator.validate(value); 158 } 159 catch (InvalidConfigException idce) 160 { 161 isValid = false; 162 } 163 } 164 else 165 { 166 isValid = true; 167 } 168 } 169 return isValid; 170 } 171 172 177 public String getDataType(Object key) 178 { 179 final DomainConfigEntryInfo info = get(key); 180 if (info != null) 181 { 182 return info.dataType; 183 } 184 return ""; 185 } 186 187 193 protected abstract boolean isValidate(String name, Object domainConfig); 194 195 200 private DomainConfigEntryInfo get(Object key) 201 { 202 for (int i = 0; i < entries.length; i++) 203 { 204 if (entries[i].key.equals(key)) { return entries[i]; } 205 } 206 return null; 207 } 208 } 209 | Popular Tags |