1 23 package com.sun.enterprise.tools.verifier.tests.web.elements; 24 25 import com.sun.enterprise.tools.verifier.tests.web.WebTest; 26 import com.sun.enterprise.tools.verifier.tests.web.WebCheck; 27 import java.util.*; 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.tools.verifier.tests.web.*; 32 33 41 public class WebReferencesInWEBINF extends WebTest implements WebCheck { 42 Result result = null; 43 ComponentNameConstructor compName = null; 44 EjbReferenceDescriptor ejbReference; 45 Iterator iterator; 46 47 55 public Result check(WebBundleDescriptor descriptor) { 56 57 result = getInitializedResult(); 58 boolean oneFailed = false; 59 compName = getVerifierContext().getComponentNameConstructor(); 60 61 if (descriptor instanceof WebBundleDescriptor) { 62 63 67 68 String f = descriptor.getModuleDescriptor().getArchiveUri(); 69 Set references = descriptor.getEjbReferenceDescriptors(); 70 iterator = references.iterator(); 71 result = loadWarFile(descriptor); 72 73 try { 74 if (iterator.hasNext()) { 75 while (iterator.hasNext()) { 76 ejbReference = (EjbReferenceDescriptor) iterator.next(); 77 if (ejbReference.isLinked()) { oneFailed = findEjbRef(f); 79 } else { 80 result.addGoodDetails(smh.getLocalString 82 ("tests.componentNameConstructor", 83 "For [ {0} ]", 84 new Object [] {compName.toString()})); 85 result.addGoodDetails(smh.getLocalString 86 (getClass().getName() + ".notApplicable2", 87 "Not Applicable: [ {0} ] must be external reference to bean outside of [ {1} ].", 88 new Object [] {ejbReference.getName(),f})); 89 } 90 } 91 } 92 else { 93 result.addNaDetails(smh.getLocalString 94 ("tests.componentNameConstructor", 95 "For [ {0} ]", 96 new Object [] {compName.toString()})); 97 result.notApplicable(smh.getLocalString 98 (getClass().getName() + ".notApplicable", 99 "Not Applicable: No EJB references found in [ {0} ]", 100 new Object [] {f})); 101 return result; 102 } 103 } catch (Exception e) { 104 result.addErrorDetails(smh.getLocalString 105 ("tests.componentNameConstructor", 106 "For [ {0} ]", 107 new Object [] {compName.toString()})); 108 result.failed(smh.getLocalString 109 (getClass().getName() + ".IOException", 110 "I/O error trying to open {0}", new Object [] {f})); 111 } finally { 112 try { 113 } catch (Exception x) {} 114 } 115 if (oneFailed) { 116 result.setStatus(Result.FAILED); 117 } else { 118 result.setStatus(Result.PASSED); 119 } 120 } else { 121 result.addNaDetails(smh.getLocalString 122 ("tests.componentNameConstructor", 123 "For [ {0} ]", 124 new Object [] {compName.toString()})); 125 result.notApplicable(smh.getLocalString 126 (getClass().getName() + ".notApplicable1", 127 "There are no ejb references to other beans within this web archive [ {0} ]", 128 new Object [] {descriptor.getName()})); 129 } 130 131 return result; 132 } 133 134 private boolean findEjbRef(String f) { 135 136 boolean oneFailed = false; 137 138 try { 139 if(ejbReference.getEjbHomeInterface() != null && 140 !"".equals(ejbReference.getEjbHomeInterface()) && 141 ejbReference.getEjbInterface() != null && 142 !"".equals(ejbReference.getEjbInterface())) { 143 oneFailed = common(ejbReference.getEjbHomeInterface(),f); 144 if (oneFailed == true) { 145 result.addErrorDetails(smh.getLocalString 146 ("tests.componentNameConstructor", 147 "For [ {0} ]", 148 new Object [] {compName.toString()})); 149 result.failed(smh.getLocalString 150 (getClass().getName() + ".failed", 151 "Error: The [ {0} ] interface of the referenced EJB [ {1} ] is not packaged inside the WEB-INF directory of the war file.", 152 new Object [] {ejbReference.getEjbHomeInterface(),ejbReference.getName()})); 153 return true; 154 } 155 156 oneFailed = common(ejbReference.getEjbInterface(),f); 157 if (oneFailed == true) { 158 result.addErrorDetails(smh.getLocalString 159 ("tests.componentNameConstructor", 160 "For [ {0} ]", 161 new Object [] {compName.toString()})); 162 result.failed(smh.getLocalString 163 (getClass().getName() + ".failed", 164 "Error: The [ {0} ] interface of the referenced EJB [ {1} ] is not packaged inside the WEB-INF directory of the war file", 165 new Object [] {ejbReference.getEjbInterface(),ejbReference.getName()})); 166 return true; 167 } 168 } 169 return oneFailed; 170 } catch (NoClassDefFoundError e) { 171 result.addErrorDetails(smh.getLocalString 172 ("tests.componentNameConstructor", 173 "For [ {0} ]", 174 new Object [] {compName.toString()})); 175 result.failed(smh.getLocalString 176 (getClass().getName() + ".failed1", 177 "Error: Bean class [ {0} ] does not exist or is not loadable:NoClassDefFoundError.", 178 new Object [] {ejbReference.getName()})); 179 oneFailed = true; 180 return oneFailed; 181 } catch (Exception e) { 182 Verifier.debug(e); 183 result.addErrorDetails(smh.getLocalString 184 ("tests.componentNameConstructor", 185 "For [ {0} ]", 186 new Object [] {compName.toString()})); 187 result.failed(smh.getLocalString 188 (getClass().getName() + ".failed1", 189 "Error: Bean class [ {0} ] does not exist or is not loadable:ClassNotFoundException", 190 new Object [] {ejbReference.getName()})); 191 oneFailed = true; 192 return oneFailed; 193 } 194 } 195 196 private boolean common(String intf, String f) { 197 Class cl = loadClass(result, intf); 198 if (cl != null) { 199 result.addGoodDetails(smh.getLocalString 200 ("tests.componentNameConstructor", 201 "For [ {0} ]", 202 new Object [] {compName.toString()})); 203 result.passed(smh.getLocalString 204 (getClass().getName() + ".passed", 205 "The referenced beans home/component [ {0} ] interface exists and is loadable within [ {1} ].", 206 new Object [] {intf,f})); 207 return false; 208 } 209 else return true; 210 } 211 } 212 213 214 | Popular Tags |