1 23 24 31 32 package com.sun.enterprise.admin.verifier.tests; 33 34 37 38 import java.io.File ; 39 import java.util.StringTokenizer ; 40 import java.util.Vector ; 41 42 import com.sun.enterprise.config.serverbeans.Server; 45 import com.sun.enterprise.config.serverbeans.*; 46 import com.sun.enterprise.config.serverbeans.Resources; 47 import com.sun.enterprise.config.serverbeans.Applications; 48 import com.sun.enterprise.config.ConfigContext; 49 import com.sun.enterprise.config.ConfigException; 50 import com.sun.enterprise.config.serverbeans.*; 51 import com.sun.enterprise.config.ConfigContextEvent; 52 53 import com.sun.enterprise.admin.verifier.*; 54 import java.util.logging.Logger ; 56 import java.util.logging.Level ; 57 import com.sun.logging.LogDomains; 58 59 60 61 public class VirtualServerTest extends ServerXmlTest implements ServerCheck { 62 static Logger _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER); 64 65 public VirtualServerTest() { 66 } 67 68 public Result check(ConfigContext context) { 70 Result result; 71 result = super.getInitializedResult(); 72 132 136 return result; 137 } 138 139 public Result check(ConfigContextEvent ccce) { 141 Result result = new Result(); 142 Object value = ccce.getObject(); 143 ConfigContext context = ccce.getConfigContext(); 144 String beanName = ccce.getBeanName(); 145 result.passed("Passed ***"); 146 147 String choice = ccce.getChoice(); 149 if (choice.equals(StaticTest.DELETE)) { 150 153 return result; 154 } 155 157 if(beanName != null) { 158 String name = ccce.getName(); 159 result = testSave(name, (String )value, context); 160 return result; 161 } 162 VirtualServer virtual = (VirtualServer)value; 163 164 String id = virtual.getId(); 166 if(StaticTest.checkObjectName(id, result)) 167 result.passed("Valid Object Name"); 168 else { 169 result.failed("Virtual Server ID Invalid "); 170 return result; 171 } 172 174 boolean isNumber = false; 175 for(int i=0; i<10;i++) { 177 if(virtual.getId().startsWith(String.valueOf(i))) 178 isNumber = true; 179 } 180 if(isNumber) 181 result.failed("ID cannot start with a number"); 182 187 return result; 188 } 189 190 public Result testSave(String name, String value, ConfigContext context) { 191 Result result = new Result(); 192 result.passed("passed ****"); 193 203 if(name.equals(ServerTags.LOG_FILE)) { 205 if(value != null) { 206 File f = new File (value); 207 if(!f.exists()) 208 result.failed("Log File does not exist"); 209 } 210 } 211 225 if(name.equals(ServerTags.HTTP_LISTENERS)) { 227 if(value!=null) { 228 Vector https = tokens(value); 229 for(int i=0;i<https.size();i++) { 230 if(! isHttpListenerAvailable((String )https.get(i), context)) { 231 result.failed("Http Listener not available"); 232 return result; 233 } 234 } 235 } 236 } 237 return result; 238 } 239 240 public boolean isMimeAvailable(String value, ConfigContext context) { 241 258 return false; 259 } 260 261 public boolean isAclAvailable(String value, ConfigContext context) { 262 279 return false; 280 } 281 282 public boolean isHttpListenerAvailable(String value, ConfigContext context) { 283 try { 284 Config config = StaticTest.getConfig(context); 286 if(config!=null) { 287 HttpListener[] http = config.getHttpService().getHttpListener(); 288 for(int i=0;i<http.length;i++) { 289 if(value.equals(http[i].getId())) 290 return true; 291 } 292 } 293 }catch(Exception ex) { 294 296 _logger.log(Level.FINE, "serverxmlverifier.exception", ex); 297 } 299 return false; 300 } 301 302 public Vector tokens(String value) { 303 StringTokenizer token = new StringTokenizer (value,","); 304 Vector test = new Vector (); 305 while(token.hasMoreTokens()) 306 test.add(token.nextToken()); 307 return test; 308 } 309 } 310 | Popular Tags |