1 23 package com.sun.enterprise.tools.verifier.tests.ejb; 24 25 import com.sun.enterprise.deployment.*; 26 import java.lang.ClassLoader ; 27 import java.util.*; 28 import java.lang.reflect.*; 29 import com.sun.enterprise.tools.verifier.*; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 32 53 public class ContainerTransactionStyle3 extends EjbTest implements EjbCheck { 54 private Result result = null; 55 private ComponentNameConstructor compName = null; 56 private EjbDescriptor descriptor = null; 57 private Method[] homeMethods = null; 58 private Method[] localHomeMethods = null; 59 private Method[] remoteMethods = null; 60 private Method[] localMethods = null; 61 private Method[] serviceMethods = null; 62 63 89 public Result check(EjbDescriptor descriptor) { 90 91 result = getInitializedResult(); 92 compName = getVerifierContext().getComponentNameConstructor(); 93 this.descriptor = descriptor; 94 95 if (!(descriptor instanceof EjbSessionDescriptor) && 96 !(descriptor instanceof EjbEntityDescriptor)) { 97 result.notApplicable(smh.getLocalString 98 ("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1", 99 "Test apply only to session or entity beans.")); 100 return result; 101 } 102 103 if (!descriptor.getMethodContainerTransactions().isEmpty()) 106 commonToAllInterfaces(); 107 108 if(result.getStatus() != Result.FAILED) { 109 addGoodDetails(result, compName); 110 result.passed(smh.getLocalString 111 (getClass().getName() + ".passed", 112 "Valid container transaction methods.")); 113 } 114 return result; 115 } 116 117 121 private void commonToAllInterfaces() { 122 123 boolean isTimedObject=false; 124 try { 125 ClassLoader jcl = getVerifierContext().getClassLoader(); 126 Class beanClass = Class.forName(descriptor.getEjbClassName(), false, jcl); 127 isTimedObject = javax.ejb.TimedObject .class.isAssignableFrom(beanClass); 128 } catch (ClassNotFoundException e) {} 130 initializeMethods(); 131 for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) { 132 MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement(); 133 134 if (methodDescriptor.getName().equals(MethodDescriptor.ALL_EJB_METHODS) || 135 methodDescriptor.getParameterClassNames() == null) continue; 137 138 if(isTimedObject && 139 MethodDescriptor.EJB_BEAN.equals(methodDescriptor.getEjbClassSymbol()) && 140 methodDescriptor.getName().equals("ejbTimeout")) { 141 String [] params=methodDescriptor.getJavaParameterClassNames(); 142 if(params.length==1 && params[0].trim().equals("javax.ejb.Timer")) 143 continue; } 146 Set<Method> methods = getAllInterfaceMethods(methodDescriptor); 147 148 if(!isMethodContained(methods, methodDescriptor)) { String ejbClassSymbol = methodDescriptor.getEjbClassSymbol(); 150 String intf = ejbClassSymbol; 151 if(ejbClassSymbol == null) { 152 intf = smh.getLocalString(getClass().getName() + ".msg", "any of bean"); 153 } else if(ejbClassSymbol.equals(MethodDescriptor.EJB_REMOTE)) { 154 intf = "Remote or RemoteBusiness"; 155 } else if(ejbClassSymbol.equals(MethodDescriptor.EJB_LOCAL)) { 156 intf = "Local or LocalBusiness"; 157 } 158 159 addErrorDetails(result, compName); 160 result.failed(smh.getLocalString 161 (getClass().getName() + ".failed", 162 "Error: Container Transaction method name [ {0} ] not " + 163 "defined in [ {1} ] interface(s).", 164 new Object [] {methodDescriptor.getName(), intf})); 165 } 166 } 167 } 168 169 170 private void initializeMethods() { 171 homeMethods = getMethods(descriptor.getHomeClassName()); 172 localHomeMethods = getMethods(descriptor.getLocalHomeClassName()); 173 remoteMethods = getMethods(descriptor.getRemoteClassName()); 174 remoteMethods = getBusinessMethods(descriptor.getRemoteBusinessClassNames(),remoteMethods); 175 localMethods = getMethods(descriptor.getLocalClassName()); 176 localMethods = getBusinessMethods(descriptor.getLocalBusinessClassNames(), localMethods); 177 serviceMethods = getMethods(descriptor.getWebServiceEndpointInterfaceName()); 178 } 179 180 181 private Set<Method> getAllInterfaceMethods(MethodDescriptor methodDescriptor) { 182 183 Set<Method> methods = new HashSet<Method>(); 184 185 String methodIntf = methodDescriptor.getEjbClassSymbol(); 186 if((methodIntf == null)) { 187 methods.addAll(Arrays.asList(homeMethods)); 188 methods.addAll(Arrays.asList(localHomeMethods)); 189 methods.addAll(Arrays.asList(remoteMethods)); 190 methods.addAll(Arrays.asList(localMethods)); 191 methods.addAll(Arrays.asList(serviceMethods)); 192 } else if(methodIntf.equals(MethodDescriptor.EJB_HOME)) { 193 methods.addAll(Arrays.asList(homeMethods)); 194 } else if(methodIntf.equals(MethodDescriptor.EJB_LOCALHOME)) { 195 methods.addAll(Arrays.asList(localHomeMethods)); 196 } else if(methodIntf.equals(MethodDescriptor.EJB_REMOTE)) { 197 methods.addAll(Arrays.asList(remoteMethods)); 198 } else if(methodIntf.equals(MethodDescriptor.EJB_LOCAL)) { 199 methods.addAll(Arrays.asList(localMethods)); 200 } else if(methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) { 201 methods.addAll(Arrays.asList(serviceMethods)); 202 } 203 return methods; 204 } 205 206 207 private Method[] getMethods(String clsName) { 208 if(clsName==null) 209 return new Method[]{}; 210 ClassLoader jcl = getVerifierContext().getClassLoader(); 211 try { 212 Class cls = Class.forName(clsName, false, jcl); 213 return cls.getMethods(); 214 } catch (ClassNotFoundException e) {} return new Method[]{}; 216 } 217 218 private Method[] getBusinessMethods(Set<String > classNames, Method[] intfMethods) { 219 if(!classNames.isEmpty()) { 220 221 List<Method> methods = new ArrayList<Method>(); 222 for (String clsName : classNames) { 223 Method[] methodArray = getMethods(clsName); 224 if(methodArray != null) 225 methods.addAll(Arrays.asList(methodArray)); 226 } 227 228 if(intfMethods != null) 229 methods.addAll(Arrays.asList(intfMethods)); 230 return methods.toArray(new Method[]{}); 231 } 232 return intfMethods; 233 } 234 235 236 private boolean isMethodContained(Set<Method> methods, MethodDescriptor methodDescriptor) { 237 boolean foundIt = false; 238 for (Method method : methods) { 239 if(method.getName().equals(methodDescriptor.getName()) && 240 MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), 241 (new MethodDescriptor(method)).getParameterClassNames())) { 242 foundIt = true; 243 break; 244 } 245 } 246 return foundIt; 247 } 248 } 249 | Popular Tags |