1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity; 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.MethodUtils; 29 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 import java.lang.reflect.*; 32 import java.util.*; 33 34 35 43 public class TransactionDemarcationComponentInterface extends EjbTest implements EjbCheck { 44 45 static String [] EJBObjectMethods = 46 { "getEJBHome", "getHandle", "getEJBLocalHome", "getPrimaryKey", "isIdentical" 47 }; 48 Result result = null; 49 ComponentNameConstructor compName = null; 50 51 52 64 public Result check(EjbDescriptor descriptor) { 65 66 result = getInitializedResult(); 67 compName = getVerifierContext().getComponentNameConstructor(); 68 69 try { 75 81 if (descriptor instanceof EjbEntityDescriptor) { 82 boolean oneFailed = false; 83 if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName())) 84 oneFailed = commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor, MethodDescriptor.EJB_REMOTE); 85 if(oneFailed == false) { 86 if(descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName())) 87 oneFailed = commonToBothInterfaces(descriptor.getLocalClassName(),descriptor, MethodDescriptor.EJB_LOCAL); 88 } 89 if (oneFailed) { 90 result.setStatus(Result.FAILED); 91 } else { 92 result.setStatus(Result.PASSED); 93 } 94 return result; 95 96 } else { 97 addNaDetails(result, compName); 98 result.notApplicable(smh.getLocalString 99 (getClass().getName() + ".notApplicable", 100 "{0} expected {1} bean, but called with {2} bean.", 101 new Object [] {getClass(),"Entity","Session"})); 102 return result; 103 } 104 } catch (Throwable t) { 105 addErrorDetails(result, compName); 106 result.failed(smh.getLocalString 107 (getClass().getName() + ".failedException1", 108 "Error: Component interface does not contain class [ {0} ] within bean [ {1} ]", 109 new Object [] { t.getMessage(), descriptor.getName()})); 110 return result; 111 } 112 } 113 114 120 121 private boolean commonToBothInterfaces(String component, EjbDescriptor descriptor, String methodIntf) { 122 boolean oneFailed = false; 123 try { 124 Arrays.sort(EJBObjectMethods); 125 126 Class componentInterfaceClass = Class.forName(component, false, getVerifierContext().getClassLoader()); 128 Method [] componentInterfaceMethods = componentInterfaceClass.getDeclaredMethods(); 129 boolean lookForIt = false; 130 131 for (int i = 0; i < componentInterfaceMethods.length; i++) { 132 if (Arrays.binarySearch(EJBObjectMethods, componentInterfaceMethods[i].getName()) < 0) { 133 try { 134 ContainerTransaction containerTransaction = null; 135 boolean resolved = false; 136 143 144 if (!descriptor.getMethodContainerTransactions().isEmpty()) { 145 for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) { 146 lookForIt = false; 147 MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement(); 148 149 153 169 170 if (methodDescriptor.getName().equals(MethodDescriptor.ALL_EJB_METHODS)) { 175 if (methodDescriptor.getEjbClassSymbol() == null) { 178 lookForIt = true; 179 } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) { 180 lookForIt = true; 181 } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) { 183 lookForIt = true; 184 }else if (methodDescriptor.getEjbClassSymbol().equals("")) { 185 lookForIt = true; 186 } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) { 187 lookForIt = false; 188 } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) { 189 lookForIt = false; 190 }else { 191 lookForIt = false; 194 } 195 196 197 } else if (methodDescriptor.getParameterClassNames() == null) { 198 199 200 if (((methodDescriptor.getEjbClassSymbol() == null) || 202 methodDescriptor.getEjbClassSymbol().equals("") || 203 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)|| 204 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) && 205 (componentInterfaceMethods[i].getName().equals(methodDescriptor.getName()))) { 206 lookForIt = true; 208 } else { 209 lookForIt = false; 211 } 212 213 214 } else { 215 216 219 if (((methodDescriptor.getEjbClassSymbol() == null) || 220 methodDescriptor.getEjbClassSymbol().equals("") || 221 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)|| 222 methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL))&& 223 (componentInterfaceMethods[i].getName().equals(methodDescriptor.getName()))&& 224 (MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), (new MethodDescriptor(componentInterfaceMethods[i], methodIntf)).getParameterClassNames()))) { 225 lookForIt = true; 227 } else { 228 lookForIt = false; 230 } 231 232 } 233 234 if (lookForIt) { 235 containerTransaction = 236 (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor); 237 if (containerTransaction != null) { 238 String transactionAttribute = 239 containerTransaction.getTransactionAttribute(); 240 241 if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) 247 || ContainerTransaction.SUPPORTS.equals(transactionAttribute) 248 || ContainerTransaction.REQUIRED.equals(transactionAttribute) 249 || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) 250 || ContainerTransaction.MANDATORY.equals(transactionAttribute) 251 || ContainerTransaction.NEVER.equals(transactionAttribute) 252 || (!transactionAttribute.equals(""))) { 253 addGoodDetails(result, compName); 254 result.addGoodDetails(smh.getLocalString 255 (getClass().getName() + ".passed", 256 "Valid: [ {0} ] TransactionAttribute [ {1} ] for method [ {2} ] is valid. Transaction attributes must be defined for all methods except getEJBHome, getHandle, getPrimaryKey, and isIdentical methods of component interface [ {3} ].", 257 new Object [] {componentInterfaceMethods[i].getName(), transactionAttribute, methodDescriptor.getName(),component})); 258 resolved = true; 259 } else { 260 oneFailed = true; 261 addErrorDetails(result, compName); 262 result.addErrorDetails(smh.getLocalString 263 (getClass().getName() + ".failed", 264 "Error: [ {0} ] TransactionAttribute [ {1} ] for method [ {2} ] is not valid. Transaction attributes must be defined for all methods except getEJBHome, getHandle, getPrimaryKey, and isIdentical methods of component interface [ {3} ]", 265 new Object [] {componentInterfaceMethods[i].getName(), transactionAttribute, methodDescriptor.getName(),component})); 266 } 267 } else { 268 oneFailed = true; 269 addErrorDetails(result, compName); 270 result.addErrorDetails(smh.getLocalString 271 (getClass().getName() + ".failedException", 272 "Error: TransactionAttribute is null for method [ {0} ]", 273 new Object [] {methodDescriptor.getName()})); 274 } 275 } 276 } 277 if (!resolved) { 280 287 oneFailed = true; 288 addErrorDetails(result, compName); 289 result.addErrorDetails(smh.getLocalString 290 (getClass().getName() + ".failed1", 291 "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} ].", 292 new Object [] {component, componentInterfaceMethods[i].getName(),descriptor.getName()})); 293 } 294 309 } else { 310 oneFailed = true; 311 addErrorDetails(result, compName); 312 result.addErrorDetails(smh.getLocalString 313 (getClass().getName() + ".failed2", 314 "Error: There are no method permissions 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.", 315 new Object [] {descriptor.getName(),component, componentInterfaceMethods[i].getName()})); 316 } 317 if(oneFailed == true && i==componentInterfaceMethods.length-1) 318 return oneFailed; 319 else 320 continue; 321 } catch (Exception e) { 322 addErrorDetails(result, compName); 323 result.failed(smh.getLocalString 324 (getClass().getName() + ".failedException1", 325 "Error: Component interface [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", 326 new Object [] {component, e.getMessage(), descriptor.getName()})); 327 oneFailed = true; 328 return oneFailed; 329 } 330 } else { 332 oneFailed = true; 333 addErrorDetails(result, compName); 334 result.failed(smh.getLocalString 335 (getClass().getName() + ".failedExcep", 336 "Error: Method [ {0} ] should not be assigned a transaction attribute.", 337 new Object [] {componentInterfaceMethods[i].getName()})); 338 339 } 340 } return oneFailed; 342 } catch (ClassNotFoundException e) { 343 Verifier.debug(e); 344 addErrorDetails(result, compName); 345 result.failed(smh.getLocalString 346 (getClass().getName() + ".failedException2", 347 "Error: Component interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", 348 new Object [] {component,descriptor.getName()})); 349 oneFailed = true; 350 return oneFailed; 351 } 352 353 } 354 } 355 356 | Popular Tags |