1 23 package com.sun.enterprise.tools.verifier.tests.ejb.elements; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 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 32 import java.util.logging.Level ; 33 34 42 public class EjbReferencesElement extends EjbTest implements EjbCheck { 43 44 45 Result result = null; 46 ComponentNameConstructor compName = null; 47 48 50 51 63 public Result check(EjbDescriptor descriptor) { 64 65 result = getInitializedResult(); 66 compName = getVerifierContext().getComponentNameConstructor(); 67 68 if ((descriptor instanceof EjbEntityDescriptor) || 69 (descriptor instanceof EjbSessionDescriptor)) { 70 71 75 80 EjbReferenceDescriptor ejbReference; 81 try { 83 84 String fName = null; 85 Set references = descriptor.getEjbReferenceDescriptors(); 86 if(references == null) { 87 logger.log(Level.INFO,getClass().getName() + ".refnull"); 88 return result; 89 } 90 Iterator iterator = references.iterator(); 91 92 if (iterator.hasNext()) { 93 boolean oneFailed = false; 94 fName = descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri(); 102 while (iterator.hasNext()) { 104 ejbReference = (EjbReferenceDescriptor) iterator.next(); 105 if (ejbReference.isLinked()) { 106 if(ejbReference.getEjbHomeInterface() != null && 108 ejbReference.getEjbInterface() != null) { 109 oneFailed = commonToBothInterfaces(ejbReference.getEjbHomeInterface(),ejbReference.getEjbInterface(),fName); 110 } 111 } else { 112 result.addNaDetails(smh.getLocalString 114 ("tests.componentNameConstructor", 115 "For [ {0} ]", 116 new Object [] {compName.toString()})); 117 result.notApplicable(smh.getLocalString 118 (getClass().getName() + ".notApplicable2", 119 "Not Applicable: [ {0} ] must be external reference to bean outside of [ {1} ].", 120 new Object [] {ejbReference.getName(),fName})); 121 } 122 } 123 if (oneFailed) { 124 result.setStatus(result.FAILED); 125 } else { 126 result.setStatus(result.PASSED); 127 } 128 } else { 129 result.addNaDetails(smh.getLocalString 130 ("tests.componentNameConstructor", 131 "For [ {0} ]", 132 new Object [] {compName.toString()})); 133 result.notApplicable(smh.getLocalString 134 (getClass().getName() + ".notApplicable1", 135 "There are no ejb references to other beans within this bean [ {0} ]", 136 new Object [] {descriptor.getName()})); 137 } 138 139 return result; 140 } catch (Exception e) { 141 result.addErrorDetails(smh.getLocalString 142 ("tests.componentNameConstructor", 143 "For [ {0} ]", 144 new Object [] {compName.toString()})); 145 result.failed(smh.getLocalString 146 (getClass().getName() + ".failedRef", 147 "Exception occurred : [ {0} ]", 148 new Object [] {e.getMessage()})); 149 return result; 150 } 151 } else { 152 result.addNaDetails(smh.getLocalString 153 ("tests.componentNameConstructor", 154 "For [ {0} ]", 155 new Object [] {compName.toString()})); 156 result.notApplicable(smh.getLocalString 157 (getClass().getName() + ".notApplicable", 158 "[ {0} ] not called \n with a Session or Entity bean.", 159 new Object [] {getClass()})); 160 return result; 161 } 162 } 163 164 172 173 private boolean commonToBothInterfaces(String home, String remote,String fileName) { 174 175 boolean foundHomeClassName = false; 176 boolean foundRemoteClassName = false; 177 boolean oneFailed = false; 178 179 try { 180 Class c = Class.forName(home, false, getVerifierContext().getClassLoader()); 181 if (c != null) { 182 foundHomeClassName = true; 183 result.addGoodDetails(smh.getLocalString 184 ("tests.componentNameConstructor", 185 "For [ {0} ]", 186 new Object [] {compName.toString()})); 187 result.passed(smh.getLocalString 188 (getClass().getName() + ".passed2", 189 "The referenced bean's home interface [ {0} ] exists and is loadable within [ {1} ].", 190 new Object [] {home, fileName})); 191 } else { 192 oneFailed = true; 193 result.addErrorDetails(smh.getLocalString 194 ("tests.componentNameConstructor", 195 "For [ {0} ]", 196 new Object [] {compName.toString()})); 197 result.failed(smh.getLocalString 198 (getClass().getName() + ".failed", 199 "Error: [ {0} ] class cannot be found within this jar [ {1} ].", 200 new Object [] {home,fileName})); 201 } 202 c = Class.forName(remote, false, getVerifierContext().getClassLoader()); 203 if (c != null) { 204 foundRemoteClassName = true; 205 result.addGoodDetails(smh.getLocalString 206 ("tests.componentNameConstructor", 207 "For [ {0} ]", 208 new Object [] {compName.toString()})); 209 result.passed(smh.getLocalString 210 (getClass().getName() + ".passed3", 211 "The referenced bean's remote interface [ {0} ] exists and is loadable within [ {1} ].", 212 new Object [] {remote,fileName})); 213 } else { 214 oneFailed = true; 215 result.addErrorDetails(smh.getLocalString 216 ("tests.componentNameConstructor", 217 "For [ {0} ]", 218 new Object [] {compName.toString()})); 219 result.failed(smh.getLocalString 220 (getClass().getName() + ".failed", 221 "Error: [ {0} ] class cannot be found within this jar [ {1} ].", 222 new Object [] {compName,fileName})); 223 } 224 return oneFailed; 225 } catch (Exception e) { 226 Verifier.debug(e); 227 if (!oneFailed) { 228 oneFailed = true; 229 } 230 String classStr = ""; 231 if (!foundHomeClassName) { 232 classStr = home; 233 } else if (!foundRemoteClassName) { 234 classStr = remote; 235 } 236 result.addErrorDetails(smh.getLocalString 237 ("tests.componentNameConstructor", 238 "For [ {0} ]", 239 new Object [] {compName.toString()})); 240 result.failed(smh.getLocalString 241 (getClass().getName() + ".failed", 242 "Error: class [ {0} ] cannot be found within this jar [ {1} ].", 243 new Object [] {classStr, fileName})); 244 return oneFailed; 245 } 246 } 247 } 248 249 250 | Popular Tags |