1 23 package com.sun.enterprise.tools.verifier.tests.ejb.session.stateless; 24 25 import java.lang.reflect.Method ; 26 27 import com.sun.enterprise.deployment.EjbDescriptor; 28 import com.sun.enterprise.deployment.EjbSessionDescriptor; 29 import com.sun.enterprise.tools.verifier.Result; 30 import com.sun.enterprise.tools.verifier.Verifier; 31 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 34 35 40 public class StatelessCreateOnlyOne extends EjbTest implements EjbCheck { 41 Result result = null; 42 ComponentNameConstructor compName = null; 43 44 53 public Result check(EjbDescriptor descriptor) { 54 55 result = getInitializedResult(); 56 compName = getVerifierContext().getComponentNameConstructor(); 57 58 if (descriptor instanceof EjbSessionDescriptor) { 59 String stateType = ((EjbSessionDescriptor)descriptor).getSessionType(); 60 if (EjbSessionDescriptor.STATELESS.equals(stateType)) { 61 if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName())) 66 commonToBothInterfaces(descriptor.getHomeClassName(),(EjbSessionDescriptor)descriptor); 67 if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())) 68 commonToBothInterfaces(descriptor.getLocalHomeClassName(),(EjbSessionDescriptor)descriptor); 69 } 70 } 71 if (result.getStatus() != Result.FAILED) { 72 addGoodDetails(result, compName); 73 result.passed(smh.getLocalString 74 (getClass().getName() + ".passed", 75 "The bean's Home Interface has exactly one create Method defined")); 76 } 77 return result; 78 } 79 80 85 86 private void commonToBothInterfaces(String home, EjbSessionDescriptor descriptor) { 87 try { 88 int count = 0; 89 Class c = Class.forName(home, false, getVerifierContext().getClassLoader()); 90 for(Method methods : c.getDeclaredMethods()) { 91 if (methods.getName().equals("create")) 92 count++; 93 } 94 if(count!=1) { 95 addErrorDetails(result, compName); 96 result.failed(smh.getLocalString 97 (getClass().getName() + ".failed", 98 "Error: [ {0} ] Create methods exists within bean [ {1} ]. " + 99 "The home interface must have only one create method for stateless session bean.", 100 new Object [] {new Integer (count),home})); 101 } 102 } catch (ClassNotFoundException e) { 103 Verifier.debug(e); 104 result.addErrorDetails(smh.getLocalString 105 ("tests.componentNameConstructor", 106 "For [ {0} ]", 107 new Object [] {compName.toString()})); 108 result.failed(smh.getLocalString 109 (getClass().getName() + ".failedException", 110 "Error: Class [ {0} ] not found within bean [ {1} ]", 111 new Object [] {home, descriptor.getName()})); 112 } 113 } 114 } 115 | Popular Tags |