1 23 package com.sun.enterprise.tools.verifier.tests.ejb.session; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import com.sun.enterprise.deployment.*; 27 import com.sun.enterprise.tools.verifier.*; 28 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 29 import com.sun.enterprise.tools.verifier.tests.ejb.MethodUtils; 30 import java.lang.ClassLoader ; 31 import com.sun.enterprise.tools.verifier.tests.*; 32 import java.util.*; 33 import java.lang.reflect.*; 34 35 40 public class TransactionDemarcationHomeInterface extends EjbTest implements EjbCheck { 41 Result result = null; 42 ComponentNameConstructor compName = null; 43 44 53 public Result check(EjbDescriptor descriptor) { 54 55 result = getInitializedResult(); 56 compName = getVerifierContext().getComponentNameConstructor(); 57 58 try { 64 if (descriptor instanceof EjbSessionDescriptor) { 67 String transactionType = descriptor.getTransactionType(); 68 Context context = getVerifierContext(); 69 ClassLoader jcl = context.getClassLoader(); 70 if (EjbDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) { 71 boolean oneFailed = false; 72 if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName())) { 73 Class superclass = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader()); 74 do { 75 oneFailed = commonToBothInterfaces(superclass.getName(),(EjbSessionDescriptor)descriptor, MethodDescriptor.EJB_HOME); 76 if (oneFailed == true) { 77 break; 78 } 79 superclass = superclass.getSuperclass(); 80 } while (superclass != null); 81 } 82 if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())) { 83 Class superclass = Class.forName(descriptor.getLocalHomeClassName(), false, getVerifierContext().getClassLoader()); 84 do { 85 oneFailed = commonToBothInterfaces(superclass.getName(),(EjbSessionDescriptor)descriptor, MethodDescriptor.EJB_LOCALHOME); 86 if (oneFailed == true) { 87 break; 88 } 89 superclass = superclass.getSuperclass(); 90 } while (superclass != null); 91 } 92 93 if ((oneFailed == false) && (implementsEndpoints(descriptor))) { 94 result.addNaDetails(smh.getLocalString 95 ("tests.componentNameConstructor", 96 "For [ {0} ]", 97 new Object [] {compName.toString()})); 98 result.notApplicable(smh.getLocalString 99 ("com.sun.enterprise.tools.verifier.tests.ejb.webservice.notapp", 100 "Not Applicable because, EJB [ {0} ] implements a Service Endpoint Interface.", 101 new Object [] {compName.toString()})); 102 result.setStatus(Result.NOT_APPLICABLE); 103 return result; 104 } 105 106 if (oneFailed) { 107 result.setStatus(Result.FAILED); 108 } else { 109 result.setStatus(Result.PASSED); 110 } 111 112 return result; 113 } else { 114 addNaDetails(result, compName); 116 result.notApplicable(smh.getLocalString 117 (getClass().getName() + ".notApplicable2", 118 "Bean [ {0} ] is not [ {1} ] managed, it is [ {2} ] managed.", 119 new Object [] {descriptor.getName(),EjbDescriptor.CONTAINER_TRANSACTION_TYPE,transactionType})); 120 return result; 121 } 122 123 } else { 124 addNaDetails(result, compName); 125 result.notApplicable(smh.getLocalString 126 (getClass().getName() + ".notApplicable", 127 "{0} expected {1} bean, but called with {2} bean.", 128 new Object [] {getClass(),"Session","Entity"})); 129 return result; 130 } 131 132 } catch (Throwable t) { 133 addErrorDetails(result, compName); 134 result.failed(smh.getLocalString 135 (getClass().getName() + ".failedException", 136 "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ].", 137 new Object [] {t.getMessage(), descriptor.getName()})); 138 return result; 139 } 140 141 } 142 143 150 151 152 private boolean commonToBothInterfaces(String home, EjbSessionDescriptor descriptor, String methodIntf) { 153 boolean oneFailed = false; 154 try { 155 Context context = getVerifierContext(); 156 ClassLoader jcl = context.getClassLoader(); 157 Class c = Class.forName(home, false, getVerifierContext().getClassLoader()); 158 Method methods[] = c.getDeclaredMethods(); 159 boolean lookForIt = false; 160 for (int i=0; i< methods.length; i++) { 161 try { 162 ContainerTransaction containerTransaction = null; 163 boolean resolved = true; 164 171 172 if (!descriptor.getMethodContainerTransactions().isEmpty()) { 173 for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) { 174 lookForIt = false; 175 MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement(); 176 177 181 194 195 196 if (methodDescriptor.getName().equals(MethodDescriptor.ALL_EJB_METHODS)) { 201 if (methodDescriptor.getEjbClassSymbol() == null) { 204 lookForIt = true; 205 } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) { 206 lookForIt = true; 207 } else if (methodDescriptor.getEjbClassSymbol().equals("")) { 209 lookForIt = true; 210 } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) { 211 lookForIt = false; 212 } else { 214 lookForIt = false; 217 } 218 } else if (methodDescriptor.getParameterClassNames() == null) { 219 if (((methodDescriptor.getEjbClassSymbol() == null) || 221 methodDescriptor.getEjbClassSymbol().equals("") || 222 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)|| 223 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) && 224 (methods[i].getName().equals(methodDescriptor.getName()))) { 225 lookForIt = true; 227 } else { 228 lookForIt = false; 230 } 231 } else { 232 if (((methodDescriptor.getEjbClassSymbol() == null) || 235 methodDescriptor.getEjbClassSymbol().equals("") || 236 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)|| 237 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) && 238 (methods[i].getName().equals(methodDescriptor.getName())) && 239 (MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), (new MethodDescriptor(methods[i], methodIntf)).getParameterClassNames()))) { 240 lookForIt = true; 242 } else { 243 lookForIt = false; 245 } 246 } 247 248 if (lookForIt) { 249 containerTransaction = 250 (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor); 251 252 if (containerTransaction != null) { 253 String transactionAttribute = 254 containerTransaction.getTransactionAttribute(); 255 256 if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) 262 || ContainerTransaction.SUPPORTS.equals(transactionAttribute) 263 || ContainerTransaction.REQUIRED.equals(transactionAttribute) 264 || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) 265 || ContainerTransaction.MANDATORY.equals(transactionAttribute) 266 || ContainerTransaction.NEVER.equals(transactionAttribute) 267 || (!transactionAttribute.equals(""))) { 268 if (!methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)&& 270 !methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) { 271 result.addGoodDetails(smh.getLocalString 272 (getClass().getName() + ".passed", 273 "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is not defined for home interface [ {2} ]", 274 new Object [] {transactionAttribute, methods[i].getName(),home})); 275 } else { 276 oneFailed = true; 277 addErrorDetails(result, compName); 278 result.addErrorDetails(smh.getLocalString 279 (getClass().getName() + ".failed", 280 "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid. Transaction attributes must not be specified for all methods of session bean home interface [ {2} ].", 281 new Object [] {transactionAttribute, methods[i].getName(),home})); 282 resolved = false; 283 } 284 } else { 285 addGoodDetails(result, compName); 286 result.addGoodDetails(smh.getLocalString 287 (getClass().getName() + ".passed", 288 "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is not defined for home interface [ {2} ]", 289 new Object [] {transactionAttribute, methods[i].getName(),home})); 290 } 291 } else { 292 addGoodDetails(result, compName); 293 result.addGoodDetails(smh.getLocalString 294 (getClass().getName() + ".passedException", 295 "Valid: TransactionAttribute is null for method [ {0} ]", 296 new Object [] {methodDescriptor.getName()})); 297 } 298 } 299 } 300 if (!resolved) { 303 311 oneFailed = true; 312 addErrorDetails(result, compName); 313 result.addErrorDetails(smh.getLocalString 314 (getClass().getName() + ".failed1", 315 "Error: Transaction attributes must not be specified for the methods defined in the session bean home interface [ {0} ]. Method [ {1} ] has transaction attribute defined within this bean [ {2} ].", 316 new Object [] {home, methods[i].getName(), descriptor.getName()})); 317 334 335 } else { 336 addGoodDetails(result, compName); 337 result.addGoodDetails(smh.getLocalString 338 (getClass().getName() + ".passed2", 339 "Valid: Transaction attributes must not be specified for the methods defined in the session bean home interface [ {0} ]. Method [ {1} ] has no transaction attribute defined within this bean [ {2} ].", 340 new Object [] {home, methods[i].getName(), descriptor.getName()})); 341 } 342 } else { 343 addGoodDetails(result, compName); 344 result.passed(smh.getLocalString 345 (getClass().getName() + ".passed1", 346 "Valid: There are no method permissions within this bean [ {0} ]. Transaction attributes must not be specified for the methods defined in the session bean home interface [ {1} ]. Method [ {2} ] has no transaction attribute defined.", 347 new Object [] {descriptor.getName(),home, methods[i].getName()})); 348 } 349 if (oneFailed == true) 350 return oneFailed; 351 } catch (Exception e) { 352 addErrorDetails(result, compName); 353 result.failed(smh.getLocalString 354 (getClass().getName() + ".failedException1", 355 "Error: Home interface [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", 356 new Object [] {home, e.getMessage(), descriptor.getName()})); 357 return oneFailed; 358 } 359 } return oneFailed; 361 } catch (ClassNotFoundException e) { 362 Verifier.debug(e); 363 addErrorDetails(result, compName); 364 result.failed(smh.getLocalString 365 (getClass().getName() + ".failedException", 366 "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", 367 new Object [] {home, descriptor.getName()})); 368 return oneFailed; 369 } 370 371 } 372 } 373 | Popular Tags |