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.lang.reflect.*; 33 import com.sun.enterprise.deployment.MethodDescriptor; 34 import java.util.*; 35 36 44 public class TransactionDemarcationComponentInterface extends EjbTest implements EjbCheck { 45 Result result = null; 46 ComponentNameConstructor compName = null; 47 48 static String [] EJBObjectMethods = 49 { "getEJBHome", "getHandle", "getPrimaryKey","getEJBLocalHome","isIdentical","remove" 50 }; 51 52 53 65 public Result check(EjbDescriptor descriptor) { 66 67 result = getInitializedResult(); 68 compName = getVerifierContext().getComponentNameConstructor(); 69 70 71 try { 77 if (descriptor instanceof EjbSessionDescriptor) { 82 String transactionType = descriptor.getTransactionType(); 83 if (EjbDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) { 84 boolean oneFailed = false; 85 if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName())) 86 oneFailed = commonToBothInterfaces(descriptor.getRemoteClassName(),(EjbSessionDescriptor)descriptor, MethodDescriptor.EJB_REMOTE); 87 if(oneFailed == false) { 88 if(descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName())) 89 oneFailed = commonToBothInterfaces(descriptor.getLocalClassName(),(EjbSessionDescriptor)descriptor, MethodDescriptor.EJB_LOCAL); 90 } 91 105 if (oneFailed) { 106 result.setStatus(result.FAILED); 107 } else { 108 result.setStatus(result.PASSED); 109 } 110 return result; 111 112 } else { 113 result.addNaDetails(smh.getLocalString 115 ("tests.componentNameConstructor", 116 "For [ {0} ]", 117 new Object [] {compName.toString()})); 118 result.notApplicable(smh.getLocalString 119 (getClass().getName() + ".notApplicable2", 120 "Bean [ {0} ] is not [ {1} ] managed, it is [ {2} ] managed.", 121 new Object [] {descriptor.getName(),EjbDescriptor.CONTAINER_TRANSACTION_TYPE,transactionType})); 122 return result; 123 } 124 } else { 125 result.addNaDetails(smh.getLocalString 126 ("tests.componentNameConstructor", 127 "For [ {0} ]", 128 new Object [] {compName.toString()})); 129 result.notApplicable(smh.getLocalString 130 (getClass().getName() + ".notApplicable", 131 "{0} expected {1} bean, but called with {2} bean.", 132 new Object [] {getClass(),"Session","Entity"})); 133 return result; 134 } 135 } catch (Throwable t) { 136 result.addErrorDetails(smh.getLocalString 137 ("tests.componentNameConstructor", 138 "For [ {0} ]", 139 new Object [] {compName.toString()})); 140 result.failed(smh.getLocalString 141 (getClass().getName() + ".failedException1", 142 "Error: Component interface does not contain class [ {0} ] within bean [ {1} ]", 143 new Object [] {t.getMessage(), descriptor.getName()})); 144 return result; 145 } 146 147 } 148 149 155 156 157 private boolean commonToBothInterfaces(String component, EjbSessionDescriptor descriptor, String methodIntf) { 158 boolean oneFailed = false; 159 try { 160 Arrays.sort(EJBObjectMethods); 161 162 Context context = getVerifierContext(); 164 ClassLoader jcl = context.getClassLoader(); 165 Class componentInterfaceClass = Class.forName(component, false, getVerifierContext().getClassLoader()); 166 Method [] componentInterfaceMethods = componentInterfaceClass.getMethods(); 167 168 boolean lookForIt = false; 169 for (int i = 0; i < componentInterfaceMethods.length; i++) { 170 if (Arrays.binarySearch(EJBObjectMethods, componentInterfaceMethods[i].getName()) < 0) { 171 172 try { 173 ContainerTransaction containerTransaction = null; 174 boolean resolved = false; 175 182 183 if (!descriptor.getMethodContainerTransactions().isEmpty()) { 184 185 for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) { 186 lookForIt = false; 187 188 MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement(); 189 190 194 207 208 if (methodDescriptor.getName().equals(MethodDescriptor.ALL_EJB_METHODS)) { 213 if (methodDescriptor.getEjbClassSymbol() == null) { 216 lookForIt = true; 217 } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)|| 218 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) { 219 lookForIt = true; 220 } else if (methodDescriptor.getEjbClassSymbol().equals("")) { 222 lookForIt = true; 223 } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)|| 224 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) { 225 lookForIt = false; 226 } else { 228 lookForIt = false; 231 } 232 233 234 } else if (methodDescriptor.getParameterClassNames() == null) { 235 236 237 if (((methodDescriptor.getEjbClassSymbol() == null) || 239 methodDescriptor.getEjbClassSymbol().equals("") || 240 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE) || 241 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) && 242 (componentInterfaceMethods[i].getName().equals(methodDescriptor.getName()))) { 243 lookForIt = true; 245 } else { 246 lookForIt = false; 248 } 249 250 251 } else { 252 253 256 if (((methodDescriptor.getEjbClassSymbol() == null) || 257 methodDescriptor.getEjbClassSymbol().equals("") || 258 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)|| 259 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) && 260 (componentInterfaceMethods[i].getName().equals(methodDescriptor.getName())) && 261 (MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), (new MethodDescriptor(componentInterfaceMethods[i], methodIntf)).getParameterClassNames()))) { 262 lookForIt = true; 264 } else { 265 lookForIt = false; 267 } 268 269 } 270 271 if (lookForIt) { 272 containerTransaction = 273 (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor); 274 if (containerTransaction != null) { 275 String transactionAttribute = 276 containerTransaction.getTransactionAttribute(); 277 278 if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) 284 || ContainerTransaction.SUPPORTS.equals(transactionAttribute) 285 || ContainerTransaction.REQUIRED.equals(transactionAttribute) 286 || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) 287 || ContainerTransaction.MANDATORY.equals(transactionAttribute) 288 || ContainerTransaction.NEVER.equals(transactionAttribute) 289 || (!transactionAttribute.equals(""))) { 290 addGoodDetails(result, compName); 291 result.addGoodDetails(smh.getLocalString 292 (getClass().getName() + ".passed", 293 "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is defined for component interface [ {2} ]", 294 new Object [] {transactionAttribute, componentInterfaceMethods[i].getName(),component})); 295 resolved = true; 296 } else { 297 oneFailed = true; 298 addErrorDetails(result, compName); 299 result.addErrorDetails(smh.getLocalString 300 (getClass().getName() + ".failed", 301 "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid. Transaction attributes must be defined for all methods of component interface [ {2} ].", 302 new Object [] {transactionAttribute, componentInterfaceMethods[i].getName(),component})); 303 } 304 } else { 305 oneFailed = true; 306 addErrorDetails(result, compName); 307 result.addErrorDetails(smh.getLocalString 308 (getClass().getName() + ".failedException", 309 "Error: TransactionAttribute is null for method [ {0} ]", 310 new Object [] {methodDescriptor.getName()})); 311 } 312 } 313 } 314 if (!resolved) { 317 324 oneFailed = true; 325 addErrorDetails(result, compName); 326 result.addErrorDetails(smh.getLocalString 327 (getClass().getName() + ".failed1", 328 "Error: Transaction attributes must be specified for the methods defined in the component interface [ {0} ]. Method [ {1} ] has no transaction attribute defined within this bean [ {2} ].", 329 new Object [] {component, componentInterfaceMethods[i].getName(),descriptor.getName()})); 330 345 } 346 } else { 347 oneFailed = true; 348 addErrorDetails(result, compName); 349 result.addErrorDetails(smh.getLocalString 350 (getClass().getName() + ".failed2", 351 "Error: There are no transaction attributes within this bean [ {0} ]. Transaction attributes must be specified for the methods defined in the component interface [ {1} ]. Method [ {2} ] has no transaction attribute defined.", 352 new Object [] {descriptor.getName(),component, componentInterfaceMethods[i].getName()})); 353 } 354 if(oneFailed == true) 355 return oneFailed; 356 } catch (Exception e) { 357 addErrorDetails(result, compName); 358 result.failed(smh.getLocalString 359 (getClass().getName() + ".failedException1", 360 "Error: Component interface [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", 361 new Object [] {component, e.getMessage(), descriptor.getName()})); 362 return oneFailed; 363 } 364 } else { if(componentInterfaceMethods[i].getName().equals("remove")) { 367 for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) { 368 MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement(); 369 if(methodDescriptor.getName().equals("remove")) { 370 oneFailed = true; 371 addErrorDetails(result, compName); 372 result.failed(smh.getLocalString 373 (getClass().getName() + ".failedExcep", 374 "Error: Method [ {0} ] should not be assigned a transaction attribute.", 375 new Object [] {methodDescriptor.getName()})); 376 break; 377 } 378 } 379 } 380 } 381 } return oneFailed; 383 } catch (ClassNotFoundException e) { 384 Verifier.debug(e); 385 addErrorDetails(result, compName); 386 result.failed(smh.getLocalString 387 (getClass().getName() + ".failedException2", 388 "Error: Component interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", 389 new Object [] {component,descriptor.getName()})); 390 return oneFailed; 391 } 392 } 393 } 394 | Popular Tags |