1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import com.sun.enterprise.tools.verifier.tests.web.WebTest; 26 import java.util.*; 27 import java.io.*; 28 import com.sun.enterprise.deployment.*; 29 import com.sun.enterprise.tools.verifier.*; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 import com.sun.enterprise.util.FileClassLoader; 32 33 34 38 public class ExceptionType extends WebTest implements WebCheck { 39 40 41 49 public Result check(WebBundleDescriptor descriptor) { 50 51 Result result = loadWarFile(descriptor); 52 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 53 54 if (descriptor.getErrorPageDescriptors().hasMoreElements()) { 55 boolean oneFailed = false; 56 int oneExceptionType = 0; 57 int oneNA = 0; 58 boolean foundIt = false; 59 for (Enumeration e = descriptor.getErrorPageDescriptors() ; e.hasMoreElements() ;) { 61 foundIt = false; 62 oneExceptionType++; 63 ErrorPageDescriptorImpl errorpage = (ErrorPageDescriptorImpl) e.nextElement(); 64 if (errorpage.getErrorCode() == 0) { 65 String exceptionType = errorpage.getExceptionType(); 66 if ((exceptionType != null) && (exceptionType.length() > 0)) { 67 boolean isValidExceptionType = false; 68 try { 69 Class c = loadClass(result, exceptionType); 70 if (isSubclassOf(c, "java.lang.Exception")) { 71 isValidExceptionType = true; 72 } 73 } catch (Exception ex) { 74 isValidExceptionType = false; 76 } 77 78 if (isValidExceptionType) { 79 foundIt = true; 80 } else { 81 foundIt = false; 82 } 83 84 if (foundIt) { 85 result.addGoodDetails(smh.getLocalString 86 ("tests.componentNameConstructor", 87 "For [ {0} ]", 88 new Object [] {compName.toString()})); 89 90 result.addGoodDetails(smh.getLocalString 91 (getClass().getName() + ".passed", 92 "Exception type [ {0} ] contains a fully qualified class name of a Java exception type within web application [ {1} ]", 93 new Object [] {exceptionType, descriptor.getName()})); 94 } else { 95 if (!oneFailed) { 96 oneFailed = true; 97 } 98 result.addErrorDetails(smh.getLocalString 99 ("tests.componentNameConstructor", 100 "For [ {0} ]", 101 new Object [] {compName.toString()})); 102 103 result.addErrorDetails(smh.getLocalString 104 (getClass().getName() + ".failed", 105 "Error: Exception type [ {0} ] does not contain a fully qualified class name of a Java exception type within web application [ {1} ]", 106 new Object [] {exceptionType, descriptor.getName()})); 107 } 108 } else { 109 if (!oneFailed) { 110 oneFailed = true; 111 } 112 Integer errorCode = new Integer ( errorpage.getErrorCode() ); 113 result.addErrorDetails(smh.getLocalString 114 ("tests.componentNameConstructor", 115 "For [ {0} ]", 116 new Object [] {compName.toString()})); 117 118 result.addErrorDetails(smh.getLocalString 119 (getClass().getName() + ".failed", 120 "Error: Exception type [ {0} ] does not contain a fully qualified class name of a Java exception type within web application [ {1} ]", 121 new Object [] {errorCode.toString(), descriptor.getName()})); 122 oneNA++; 123 } 124 } else { 125 Integer errorCode = new Integer ( errorpage.getErrorCode() ); 128 result.addNaDetails(smh.getLocalString 129 ("tests.componentNameConstructor", 130 "For [ {0} ]", 131 new Object [] {compName.toString()})); 132 133 result.addNaDetails(smh.getLocalString 134 (getClass().getName() + ".notApplicable1", 135 "Exception type is null, using error-code [ {0} ] instead within web application [ {1} ]", 136 new Object [] {errorCode.toString(), descriptor.getName()})); 137 oneNA++; 138 } 139 } 140 if (oneFailed) { 141 result.setStatus(Result.FAILED); 142 } else if (oneNA == oneExceptionType) { 143 result.setStatus(Result.NOT_APPLICABLE); 144 } else { 145 result.setStatus(Result.PASSED); 146 } 147 } else { 148 result.addNaDetails(smh.getLocalString 149 ("tests.componentNameConstructor", 150 "For [ {0} ]", 151 new Object [] {compName.toString()})); 152 153 result.notApplicable(smh.getLocalString 154 (getClass().getName() + ".notApplicable", 155 "There are no exception-type elements within the web archive [ {0} ]", 156 new Object [] {descriptor.getName()})); 157 } 158 159 return result; 160 } 161 } 162 | Popular Tags |