1 23 package com.sun.enterprise.tools.verifier.tests.ejb; 24 25 import com.sun.enterprise.deployment.*; 26 import com.sun.enterprise.tools.verifier.*; 27 import java.util.*; 28 import java.lang.reflect.Array ; 29 import com.sun.enterprise.tools.verifier.tests.*; 30 31 39 public class TransactionDemarcationType extends EjbTest implements EjbCheck { 40 41 static String [] EJBObjectMethods = 42 { 43 "getHomeHandle", "getEJBMetaData", 44 "getEJBHome", "getEJBLocalHome","getHandle", 45 "getPrimaryKey", "isIdentical" 46 }; 47 48 49 61 public Result check(EjbDescriptor descriptor) { 62 63 Result result = getInitializedResult(); 64 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 65 66 try { 72 if ((descriptor instanceof EjbSessionDescriptor) || 73 (descriptor instanceof EjbEntityDescriptor)) { 74 boolean oneFailed = false; 75 String transactionType = descriptor.getTransactionType(); 76 if (EjbDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) { 77 try { 78 Arrays.sort(EJBObjectMethods); 79 ContainerTransaction containerTransaction = null; 80 if (!descriptor.getMethodContainerTransactions().isEmpty()) { 81 for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) { 82 MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement(); 83 if (Arrays.binarySearch(EJBObjectMethods, methodDescriptor.getName()) < 0) { 84 containerTransaction = 85 (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor); 86 87 if (containerTransaction != null || 88 containerTransaction.getTransactionAttribute()!=null) { 89 String transactionAttribute = 90 containerTransaction.getTransactionAttribute(); 91 92 if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) 98 || ContainerTransaction.SUPPORTS.equals(transactionAttribute) 99 || ContainerTransaction.REQUIRED.equals(transactionAttribute) 100 || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) 101 || ContainerTransaction.MANDATORY.equals(transactionAttribute) 102 || ContainerTransaction.NEVER.equals(transactionAttribute)) { 103 addGoodDetails(result, compName); 104 result.addGoodDetails(smh.getLocalString 105 (getClass().getName() + ".passed", 106 "TransactionAttribute [ {0} ] for method [ {1} ] is valid.", 107 new Object [] {transactionAttribute, methodDescriptor.getName()})); 108 } else { 109 oneFailed = true; 110 addErrorDetails(result, compName); 111 result.addErrorDetails(smh.getLocalString 112 (getClass().getName() + ".failed", 113 "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid.", 114 new Object [] {transactionAttribute, methodDescriptor.getName()})); 115 } 116 } else { 117 if(getVerifierContext().getJavaEEVersion().compareTo(SpecVersionMapper.JavaEEVersion_5)<0) { 119 oneFailed = true; 120 addErrorDetails(result, compName); 121 result.addErrorDetails(smh.getLocalString 122 (getClass().getName() + ".failedException", 123 "Error: TransactionAttribute is null for method [ {0} ]", 124 new Object [] {methodDescriptor.getName()})); 125 } 126 127 } 128 } else { 130 String ejbClass = methodDescriptor.getEjbClassSymbol(); 134 135 139 149 boolean session = descriptor instanceof EjbSessionDescriptor; 150 boolean entity = descriptor instanceof EjbEntityDescriptor; 151 if (((ejbClass == null) 152 || ejbClass.equals(MethodDescriptor.EJB_HOME) 153 || ejbClass.equals(MethodDescriptor.EJB_LOCALHOME)) 154 && session) { 155 oneFailed = true; 156 addErrorDetails(result, compName); 157 result.addErrorDetails(smh.getLocalString 158 (getClass().getName() + ".failedHome", 159 "Error: TransactionAttribute for method [ {0} ] is not valid. Home or Local Home interface methods of a session bean must not hvae a transaction attribute.", 160 new Object [] {methodDescriptor.getName()})); 161 } 162 else if (((ejbClass == null) 165 || ejbClass.equals(MethodDescriptor.EJB_REMOTE) 166 || ejbClass.equals(MethodDescriptor.EJB_LOCAL)) 167 && session && methodDescriptor.getName().equals("remove")) { 168 if (methodDescriptor.getParameterClassNames() == null 171 || methodDescriptor.getParameterClassNames().length == 0 ) { 172 oneFailed = true; 174 addErrorDetails(result, compName); 175 result.addErrorDetails(smh.getLocalString 176 (getClass().getName() + ".failedComp", 177 "Error: TransactionAttribute for method [ {0} ] is not valid. 'remove' method in Remote/Local interface of a session bean must not have a transaction attribute.", 178 new Object [] {methodDescriptor.getName()})); 179 } else { 180 addGoodDetails(result, compName); 181 result.addGoodDetails(smh.getLocalString 182 (getClass().getName() + ".passedTest", 183 "TransactionAttribute for method [ {0} ] is valid.", 184 new Object [] {methodDescriptor.getName()})); 185 } 186 } 187 else if (((ejbClass == null) 188 || ejbClass.equals(MethodDescriptor.EJB_HOME) 189 || ejbClass.equals(MethodDescriptor.EJB_LOCALHOME)) 190 && entity) { 191 if (methodDescriptor.getParameterClassNames() == null 192 || methodDescriptor.getParameterClassNames().length == 0) { 193 oneFailed = true; 195 addErrorDetails(result, compName); 196 result.addErrorDetails(smh.getLocalString 197 (getClass().getName() + ".failed1", 198 "Error: TransactionAttribute for method [ {0} ] is not valid. ", 199 new Object [] {methodDescriptor.getName()})); 200 } else { 201 addGoodDetails(result, compName); 202 result.addGoodDetails(smh.getLocalString 203 (getClass().getName() + ".passedTest", 204 "TransactionAttribute for method [ {0} ] is valid.", 205 new Object [] { methodDescriptor.getName()})); 206 } 207 } 208 else if (((ejbClass == null) 209 || ejbClass.equals(MethodDescriptor.EJB_REMOTE) 210 || ejbClass.equals(MethodDescriptor.EJB_LOCAL)) 211 && entity) { 212 if ((methodDescriptor.getName()).equals("isIdentical")) { 213 if(methodDescriptor.getParameterClassNames() == null 214 || methodDescriptor.getParameterClassNames().length == 0 ) { 215 addGoodDetails(result, compName); 216 result.addGoodDetails(smh.getLocalString 217 (getClass().getName() + ".passedTest", 218 "TransactionAttribute for method [ {0} ] is valid.", 219 new Object [] {methodDescriptor.getName()})); 220 } else { 221 String [] paramList = methodDescriptor.getParameterClassNames(); 222 if(Array.getLength(paramList) == 1) { 223 if (paramList[0].equals("javax.ejb.EJBObject")) { 224 oneFailed = true; 226 addErrorDetails(result, compName); 227 result.addErrorDetails(smh.getLocalString 228 (getClass().getName() + ".failed1", 229 "Error: TransactionAttribute for method [ {0} ] is not valid.", 230 new Object [] { methodDescriptor.getName()})); 231 } 232 else { 233 addGoodDetails(result, compName); 234 result.addGoodDetails(smh.getLocalString 235 (getClass().getName() + ".passedTest", 236 "TransactionAttribute for method [ {0} ] is valid.", 237 new Object [] { methodDescriptor.getName()})); 238 } 239 } else { 240 addGoodDetails(result, compName); 241 result.addGoodDetails(smh.getLocalString 242 (getClass().getName() + ".passedTest", 243 "TransactionAttribute for method [ {0} ] is valid.", 244 new Object [] { methodDescriptor.getName()})); 245 } 246 } 247 } 248 else { if ((methodDescriptor.getName()).equals("remove")) { 250 addGoodDetails(result, compName); 251 result.addGoodDetails(smh.getLocalString 252 (getClass().getName() + ".passedTest", 253 "TransactionAttribute for method [ {0} ] is valid.", 254 new Object [] { methodDescriptor.getName()})); 255 } 256 else { 257 if (methodDescriptor.getParameterClassNames() == null 258 || methodDescriptor.getParameterClassNames().length == 0) { 259 oneFailed = true; 261 addErrorDetails(result, compName); 262 result.failed(smh.getLocalString 263 (getClass().getName() + ".failedException1", 264 "Error: [ {0} ] should not have a Transaction Attribute", 265 new Object [] {methodDescriptor.getName()})); 266 } 267 } 268 } 269 } 270 } 271 } 272 } else { 273 addNaDetails(result, compName); 274 result.notApplicable(smh.getLocalString 275 (getClass().getName() + ".notApplicable1", 276 "There are no method permissions within this bean [ {0} ]", 277 new Object [] {descriptor.getName()})); 278 } 279 280 } catch (Exception e) { 281 oneFailed = true; 282 addErrorDetails(result, compName); 283 result.failed(smh.getLocalString 284 (getClass().getName() + ".failedException2", 285 "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", 286 new Object [] {descriptor.getName(), e.getMessage(), descriptor.getName()})); 287 return result; 288 } 289 if (oneFailed) { 290 result.setStatus(Result.FAILED); 291 } else { 292 result.setStatus(Result.PASSED); 293 } 294 return result; 295 } else { 296 addNaDetails(result, compName); 298 result.notApplicable(smh.getLocalString 299 (getClass().getName() + ".notApplicable2", 300 "Bean [ {0} ] is not {1} managed, it is [ {2} ] managed.", 301 new Object [] {descriptor.getName(),EjbDescriptor.CONTAINER_TRANSACTION_TYPE,transactionType})); 302 } 303 return result; 304 } else { 305 addNaDetails(result, compName); 306 result.notApplicable(smh.getLocalString 307 (getClass().getName() + ".notApplicable", 308 "[ {0} ] not called \n with a Session or Entity bean.", 309 new Object [] {getClass()})); 310 return result; 311 } 312 } catch (Throwable t) { 313 addErrorDetails(result, compName); 314 result.failed(smh.getLocalString 315 (getClass().getName() + ".failedException2", 316 "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", 317 new Object [] {descriptor.getName(), t.getMessage(), descriptor.getName()})); 318 return result; 319 } 320 321 } 322 } 323 | Popular Tags |