1 23 package com.sun.enterprise.tools.verifier.tests.ejb.session.createmethod; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import com.sun.enterprise.deployment.*; 27 import java.lang.ClassLoader ; 28 import com.sun.enterprise.tools.verifier.tests.*; 29 import java.util.*; 30 import java.lang.reflect.*; 31 import com.sun.enterprise.tools.verifier.*; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 34 47 public class HomeInterfaceCreateMethodMatchArgs extends EjbTest implements EjbCheck { 48 Result result = null; 49 ComponentNameConstructor compName = null; 50 boolean foundAtLeastOneCreate = false; 51 52 68 public Result check(EjbDescriptor descriptor) { 69 70 result = getInitializedResult(); 71 compName = getVerifierContext().getComponentNameConstructor(); 72 73 if (descriptor instanceof EjbSessionDescriptor) { 74 75 if (((descriptor.getHomeClassName() == null) || "".equals(descriptor.getHomeClassName())) && 76 ((descriptor.getLocalHomeClassName() == null) || "".equals(descriptor.getLocalHomeClassName()))) { 77 78 if (implementsEndpoints(descriptor)) { 79 result.addNaDetails(smh.getLocalString 80 ("tests.componentNameConstructor", 81 "For [ {0} ]", 82 new Object [] {compName.toString()})); 83 result.notApplicable(smh.getLocalString 84 ("com.sun.enterprise.tools.verifier.tests.ejb.webservice.notapp", 85 "Not Applicable because, EJB [ {0} ] implements a Service Endpoint Interface.", 86 new Object [] {compName.toString()})); 87 result.setStatus(result.NOT_APPLICABLE); 88 } 89 else { 90 91 result.addErrorDetails(smh.getLocalString 92 ("tests.componentNameConstructor", 93 "For [ {0} ]", 94 new Object [] {compName.toString()})); 95 result.addErrorDetails(smh.getLocalString 96 ("com.sun.enterprise.tools.verifier.tests.ejb.webservice.failedhome", 97 "Ejb [ {0} ] does not have local or remote Home interfaces", 98 new Object [] {descriptor.getEjbClassName()})); 99 result.setStatus(result.FAILED); 100 } 101 return result; 102 } 103 104 boolean oneFailed = false; 105 oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor.getLocalHomeClassName(),descriptor); 108 if (oneFailed) { 109 result.setStatus(result.FAILED); 110 } else { 111 result.setStatus(result.PASSED); 112 } 113 114 return result; 115 116 } else { 117 result.addNaDetails(smh.getLocalString 118 ("tests.componentNameConstructor", 119 "For [ {0} ]", 120 new Object [] {compName.toString()})); 121 result.notApplicable(smh.getLocalString 122 (getClass().getName() + ".notApplicable", 123 "[ {0} ] expected {1} bean, but called with {2} bean.", 124 new Object [] {getClass(),"Session","Entity"})); 125 return result; 126 } 127 } 128 129 135 136 137 private boolean commonToBothInterfaces(String remote, String local,EjbDescriptor descriptor) { 138 boolean oneFailed = false; 139 try { 140 Context context = getVerifierContext(); 141 ClassLoader jcl = context.getClassLoader(); 142 Class [] methodParameterTypes; 143 Class [] businessMethodParameterTypes; 144 boolean signaturesMatch = false; 145 146 boolean found = false; 147 Vector<Method> createMethodSuffix = new Vector<Method>(); 148 149 if (local != null) { 150 Class localhome = Class.forName(local, false, getVerifierContext().getClassLoader()); 151 Method [] localhomeMethods = localhome.getDeclaredMethods(); 152 for (int i = 0; i < localhomeMethods.length; i++) { 153 if (localhomeMethods[i].getName().startsWith("create")) { 155 createMethodSuffix.addElement( (Method)localhomeMethods[i]); 156 foundAtLeastOneCreate = true; 157 158 } 159 } 160 } 161 if (remote != null) { 162 Class home = Class.forName(remote, false, getVerifierContext().getClassLoader()); 163 Method [] homeMethods = home.getDeclaredMethods(); 164 for (int i = 0; i < homeMethods.length; i++) { 165 if (homeMethods[i].getName().startsWith("create")) { 167 createMethodSuffix.addElement( (Method)homeMethods[i]); 168 foundAtLeastOneCreate = true; 169 170 } 171 } 172 } 173 if (foundAtLeastOneCreate == false) { 174 result.addErrorDetails(smh.getLocalString 175 ("tests.componentNameConstructor", 176 "For [ {0} ]", 177 new Object [] {compName.toString()})); 178 result.failed(smh.getLocalString 179 (getClass().getName() + ".failedException2", 180 "Error: no create<Method> method exists!", 181 new Object [] {})); 182 return true; 183 } 184 185 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 186 do { 188 Method [] methods = EJBClass.getDeclaredMethods(); 189 for (int j = 0; j < methods.length; j++) { 191 found = false; 192 if (methods[j].getName().startsWith("ejbCreate")) { 193 found = true; 194 String matchSuffix = methods[j].getName().substring(9); 195 for (int k = 0; k < createMethodSuffix.size(); k++) { 196 signaturesMatch = false; 197 if (matchSuffix.equals(((Method)(createMethodSuffix.elementAt(k))).getName().substring(6))) { 198 methodParameterTypes = ((Method)(createMethodSuffix.elementAt(k))).getParameterTypes(); 199 businessMethodParameterTypes = methods[j].getParameterTypes(); 200 if (Arrays.equals(methodParameterTypes,businessMethodParameterTypes)) { 201 signaturesMatch = true; 202 result.addGoodDetails(smh.getLocalString 205 ("tests.componentNameConstructor", 206 "For [ {0} ]", 207 new Object [] {compName.toString()})); 208 result.addGoodDetails(smh.getLocalString 209 (getClass().getName() + ".debug1", 210 "For Home Interface Method [ {0} ]", 211 new Object [] {((Method)(createMethodSuffix.elementAt(k))).getName()})); 212 result.addGoodDetails(smh.getLocalString 213 (getClass().getName() + ".passed", 214 "The corresponding ejbCreate method with matching parameters was found.")); 215 break; 216 } 217 } 218 } 219 if (signaturesMatch == false) { 220 oneFailed = true; 221 result.addErrorDetails(smh.getLocalString 222 ("tests.componentNameConstructor", 223 "For [ {0} ]", 224 new Object [] {compName.toString()})); 225 result.addErrorDetails(smh.getLocalString 226 (getClass().getName() + ".debug3", 227 "For Home Interface", 228 new Object [] {})); 229 result.addErrorDetails(smh.getLocalString 230 (getClass().getName() + ".failed", 231 "Error: No corresponding create<Method> method with matching parameters was found." )); 232 break; 233 234 } } 236 } 237 if (oneFailed == true) 238 break; 239 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!signaturesMatch)); 240 if (found == false && foundAtLeastOneCreate == true){ 241 result.addErrorDetails(smh.getLocalString 242 ("tests.componentNameConstructor", 243 "For [ {0} ]", 244 new Object [] {compName.toString()})); 245 result.failed(smh.getLocalString 246 (getClass().getName() + ".failedException1", 247 "Error: ejbCreate<Method> method corresponding to the create<Method> method does not exist!", 248 new Object [] {})); 249 250 } 251 if (found == false && foundAtLeastOneCreate == false){ 252 result.addErrorDetails(smh.getLocalString 253 ("tests.componentNameConstructor", 254 "For [ {0} ]", 255 new Object [] {compName.toString()})); 256 result.failed(smh.getLocalString 257 (getClass().getName() + ".failedException2", 258 "Error: no create<Method> method exists!", 259 new Object [] {})); 260 } 261 return oneFailed; 262 } catch (ClassNotFoundException e) { 263 Verifier.debug(e); 264 result.addErrorDetails(smh.getLocalString 265 ("tests.componentNameConstructor", 266 "For [ {0} ]", 267 new Object [] {compName.toString()})); 268 result.failed(smh.getLocalString 269 (getClass().getName() + ".failedException", 270 "Error: Home (Local/Remote) interface or bean class [ {0} ] does not exist or is not loadable within bean [ {1} ]", 271 new Object [] {descriptor.getEjbClassName(),descriptor.getName()})); 272 oneFailed = true; 273 return oneFailed; 274 } 275 276 } 277 } 278 | Popular Tags |