1 23 package com.sun.enterprise.tools.verifier.tests.ejb.session.stateless; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import com.sun.enterprise.deployment.EjbDescriptor; 27 import com.sun.enterprise.deployment.EjbSessionDescriptor; 28 import java.lang.ClassLoader ; 29 import com.sun.enterprise.tools.verifier.tests.*; 30 import java.lang.reflect.*; 31 import com.sun.enterprise.tools.verifier.*; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 34 39 public class StatelessEjbCreateHome extends EjbTest implements EjbCheck { 40 41 42 51 public Result check(EjbDescriptor descriptor) { 52 53 Result result = getInitializedResult(); 54 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 55 56 if (descriptor instanceof EjbSessionDescriptor) { 57 String stateType = ((EjbSessionDescriptor)descriptor).getSessionType(); 58 if (EjbSessionDescriptor.STATELESS.equals(stateType)) { 59 try { 62 Context context = getVerifierContext(); 63 ClassLoader jcl = context.getClassLoader(); 64 Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 65 Method m= null; 66 int foundThisManyTimes = 0; 67 do { 69 Method methods[] = c.getDeclaredMethods(); 70 for (int i=0; i< methods.length; i++) { 71 if (!methods[i].getName().equals("ejbCreate")){ 72 continue; 73 } 74 if (foundThisManyTimes == 0) { 75 m = methods[i]; 76 foundThisManyTimes++; 77 } else { 78 foundThisManyTimes++; 79 } 80 } 81 } while (((c = c.getSuperclass()) != null) && (m == null)); 82 83 if ((m != null) && (foundThisManyTimes == 1)) { 86 Class cc[] = m.getParameterTypes(); 87 if (cc.length > 0) { 88 result.addErrorDetails(smh.getLocalString 89 ("tests.componentNameConstructor", 90 "For [ {0} ]", 91 new Object [] {compName.toString()})); 92 result.failed(smh.getLocalString 93 (getClass().getName() + ".failed", 94 "Error: The ejbCreate method has one or more parameters \n" + 95 "within bean [ {0} ]. Stateless session are only allowed \n" + 96 "to have ejbCreate methods with no arguments.", 97 new Object [] {descriptor.getEjbClassName()})); 98 } else { 99 result.addGoodDetails(smh.getLocalString 100 ("tests.componentNameConstructor", 101 "For [ {0} ]", 102 new Object [] {compName.toString()})); 103 result.passed(smh.getLocalString 104 (getClass().getName() + ".passed", 105 "Valid: This bean's [ {0} ] ejbCreate method has no parameters." 106 + "\n Stateless session beans can only have a ejbCreate method" 107 + "\n with no parameters.", 108 new Object [] {descriptor.getEjbClassName()})); 109 } 110 } else if ((m != null) && (foundThisManyTimes > 1)) { 111 result.addErrorDetails(smh.getLocalString 114 ("tests.componentNameConstructor", 115 "For [ {0} ]", 116 new Object [] {compName.toString()})); 117 result.failed(smh.getLocalString 118 (getClass().getName() + ".failed2", 119 "Error: [ {0} ] ejbCreate methods exists within bean [ {1} ]. The EJB class must have only one ejbCreate method for stateless session bean. ", 120 new Object [] {new Integer (foundThisManyTimes),descriptor.getEjbClassName()})); 121 } else { 122 result.addErrorDetails(smh.getLocalString 125 ("tests.componentNameConstructor", 126 "For [ {0} ]", 127 new Object [] {compName.toString()})); 128 result.failed(smh.getLocalString 129 (getClass().getName() + ".failed3", 130 "Error: No ejbCreate method exists within bean [ {0} ]", 131 new Object [] {descriptor.getEjbClassName()})); 132 } 133 } catch (ClassNotFoundException e) { 134 Verifier.debug(e); 135 result.addErrorDetails(smh.getLocalString 136 ("tests.componentNameConstructor", 137 "For [ {0} ]", 138 new Object [] {compName.toString()})); 139 result.failed(smh.getLocalString 140 (getClass().getName() + ".failedException", 141 "Error: Class [ {0} ] not found within bean [ {1} ]", 142 new Object [] {descriptor.getEjbClassName(), descriptor.getName()})); 143 } 144 return result; 145 146 } else if (EjbSessionDescriptor.STATEFUL.equals(stateType)) { 147 result.addNaDetails(smh.getLocalString 148 ("tests.componentNameConstructor", 149 "For [ {0} ]", 150 new Object [] {compName.toString()})); 151 result.notApplicable(smh.getLocalString 152 (getClass().getName() + ".notApplicable1", 153 "{0} expected {1} Session bean, but called with {2} Session bean.", 154 new Object [] {getClass(),EjbSessionDescriptor.STATELESS,stateType})); 155 return result; 156 } else { 157 result.addErrorDetails(smh.getLocalString 158 ("tests.componentNameConstructor", 159 "For [ {0} ]", 160 new Object [] {compName.toString()})); 161 result.failed(smh.getLocalString 162 (getClass().getName() + ".failed4", 163 "Error: [ {0} ] is not valid stateType within bean [ {1} ].", 164 new Object [] {stateType, descriptor.getName()})); 165 return result; 166 } 167 } else { 168 result.addNaDetails(smh.getLocalString 169 ("tests.componentNameConstructor", 170 "For [ {0} ]", 171 new Object [] {compName.toString()})); 172 result.notApplicable(smh.getLocalString 173 (getClass().getName() + ".notApplicable", 174 "[ {0} ] expected {1} bean, but called with {2} bean.", 175 new Object [] {getClass(),"Session","Entity"})); 176 return result; 177 } 178 } 179 } 180 | Popular Tags |