1 23 package com.sun.enterprise.tools.verifier.tests.ejb.ejb30; 24 25 import com.sun.enterprise.tools.verifier.Result; 26 import com.sun.enterprise.deployment.EjbSessionDescriptor; 27 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor; 28 29 import java.lang.reflect.Method ; 30 31 39 public class EJBCreatePostConstruct extends SessionBeanTest { 40 41 public Result check(EjbSessionDescriptor descriptor) { 42 43 if(descriptor.isStateless() && 44 descriptor.hasPostConstructMethod() && 45 hasEJBCreateMethod(descriptor.getEjbClassName())) { 46 for (LifecycleCallbackDescriptor callbackDesc : 47 descriptor.getPostConstructDescriptors()) { 48 String cmName = callbackDesc.getLifecycleCallbackMethod(); 49 if(!cmName.contains("ejbCreate")) { 50 addErrorDetails(result, compName); 51 result.failed(smh.getLocalString 52 (getClass().getName()+".failed", 53 "Wrong postconstruct method [ {0} ]", 54 new Object [] {cmName})); 55 } 56 } 57 } 58 59 if(result.getStatus() != Result.FAILED) { 60 addGoodDetails(result, compName); 61 result.passed(smh.getLocalString 62 (getClass().getName()+".passed", 63 "Valid postcontruct method(s) in Bean")); 64 } 65 66 return result; 67 } 68 69 private boolean hasEJBCreateMethod(String beanClassName) { 70 try { 71 ClassLoader jcl = getVerifierContext().getClassLoader(); 72 Class bean = Class.forName(beanClassName, false, jcl); 73 Method [] methods = bean.getMethods(); 74 for (Method method : methods) 75 if(method.getName().contains("ejbCreate")) 76 return true; 77 } catch (ClassNotFoundException e) {} return false; 79 } 80 } 81 | Popular Tags |