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.EjbDescriptor; 27 import com.sun.enterprise.deployment.EjbSessionDescriptor; 28 import com.sun.enterprise.deployment.MethodDescriptor; 29 import java.lang.ClassLoader ; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 import java.util.*; 32 import java.lang.reflect.*; 33 import com.sun.enterprise.tools.verifier.*; 34 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils; 35 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 36 37 50 public class HomeInterfaceCreateMethodExceptionMatch extends EjbTest implements EjbCheck { 51 Result result = null; 52 ComponentNameConstructor compName = null; 53 boolean foundAtLeastOneCreate = false; 54 55 56 72 public Result check(EjbDescriptor descriptor) { 73 74 result = getInitializedResult(); 75 compName = getVerifierContext().getComponentNameConstructor(); 76 77 if (descriptor instanceof EjbSessionDescriptor) { 78 if (((descriptor.getHomeClassName() == null) || "".equals(descriptor.getHomeClassName())) && 79 ((descriptor.getLocalHomeClassName() == null) || "".equals(descriptor.getLocalHomeClassName()))) { 80 81 if (implementsEndpoints(descriptor)) { 82 83 result.addNaDetails(smh.getLocalString 84 ("tests.componentNameConstructor", 85 "For [ {0} ]", 86 new Object [] {compName.toString()})); 87 result.notApplicable(smh.getLocalString 88 ("com.sun.enterprise.tools.verifier.tests.ejb.webservice.notapp", 89 "Not Applicable because, EJB [ {0} ] implements a Service Endpoint Interface.", 90 new Object [] {compName.toString()})); 91 result.setStatus(result.NOT_APPLICABLE); 92 } 93 else { 94 95 result.addErrorDetails(smh.getLocalString 96 ("tests.componentNameConstructor", 97 "For [ {0} ]", 98 new Object [] {compName.toString()})); 99 result.addErrorDetails(smh.getLocalString 100 ("com.sun.enterprise.tools.verifier.tests.ejb.webservice.failedhome", 101 "Ejb [ {0} ] does not have local or remote Home interfaces", 102 new Object [] {descriptor.getEjbClassName()})); 103 result.setStatus(result.FAILED); 104 return result; 105 106 } 107 return result; 108 } 109 110 boolean oneFailed = false; 111 112 oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor.getLocalHomeClassName(),(EjbSessionDescriptor)descriptor); 113 114 if (oneFailed) { 115 result.setStatus(result.FAILED); 116 } else { 117 result.setStatus(result.PASSED); 118 } 119 return result; 120 121 } else { 122 result.addNaDetails(smh.getLocalString 123 ("tests.componentNameConstructor", 124 "For [ {0} ]", 125 new Object [] {compName.toString()})); 126 result.notApplicable(smh.getLocalString 127 (getClass().getName() + ".notApplicable", 128 "[ {0} ] expected {1} bean, but called with {2} bean.", 129 new Object [] {getClass(),"Session","Entity"})); 130 return result; 131 } 132 } 133 134 140 141 private boolean commonToBothInterfaces(String home, String local,EjbSessionDescriptor descriptor) { 142 boolean oneFailed = false; 143 int ejbCreateMethodLoopCounter = 0; 144 try { 147 Context context = getVerifierContext(); 148 ClassLoader jcl = context.getClassLoader(); 149 Class methodReturnType; 150 Class [] methodParameterTypes; 151 Class [] methodExceptionTypes; 152 Class [] ejbCreateMethodExceptionTypes; 153 Class [] ejbCreateMethodParameterTypes; 154 boolean ejbCreateFound = false; 155 boolean exceptionsMatch = false; 156 Vector<Method> createMethodSuffix = new Vector<Method>(); 157 158 if (home != null) { 159 Class c = Class.forName(home, false, getVerifierContext().getClassLoader()); 160 Method [] homeMethods = c.getDeclaredMethods(); 161 for (int i = 0; i < homeMethods.length; i++) { 162 if (homeMethods[i].getName().startsWith("create")) { 164 createMethodSuffix.addElement( (Method)homeMethods[i]); 165 foundAtLeastOneCreate = true; 166 } 167 } 168 } 169 if (local != null) { 170 Class c = Class.forName(local, false, getVerifierContext().getClassLoader()); 171 Method [] homeMethods = c.getDeclaredMethods(); 172 for (int i = 0; i < homeMethods.length; i++) { 173 if (homeMethods[i].getName().startsWith("create")) { 175 createMethodSuffix.addElement( (Method)homeMethods[i]); 176 foundAtLeastOneCreate = true; 177 } 178 } 179 } 180 if (foundAtLeastOneCreate == false) { 181 result.addErrorDetails(smh.getLocalString 182 ("tests.componentNameConstructor", 183 "For [ {0} ]", 184 new Object [] {compName.toString()})); 185 result.failed(smh.getLocalString 186 (getClass().getName() + ".failedException2", 187 "Error: no create<Method> method exists!", 188 new Object [] {})); 189 return true; 190 } 191 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 192 193 do { 194 Method [] methods = EJBClass.getDeclaredMethods(); 195 for (int i = 0; i < methods.length; i++) { 197 ejbCreateFound = false; 198 exceptionsMatch = false; 199 if (methods[i].getName().startsWith("ejbCreate")) { 200 String matchSuffix = methods[i].getName().substring(9); 201 for (int k = 0; k < createMethodSuffix.size(); k++) { 202 if (matchSuffix.equals(((Method)(createMethodSuffix.elementAt(k))).getName().substring(6))) { 203 methodParameterTypes = ((Method)(createMethodSuffix.elementAt(k))).getParameterTypes(); 206 ejbCreateMethodParameterTypes = methods[i].getParameterTypes(); 207 if (Arrays.equals(methodParameterTypes,ejbCreateMethodParameterTypes)) { 208 ejbCreateFound = true; 209 methodExceptionTypes = ((Method)(createMethodSuffix.elementAt(k))).getExceptionTypes(); 210 ejbCreateMethodExceptionTypes = methods[i].getExceptionTypes(); 211 if (RmiIIOPUtils.isEjbFindMethodExceptionsSubsetOfFindMethodExceptions(ejbCreateMethodExceptionTypes,methodExceptionTypes)) { 212 exceptionsMatch = true; 213 ejbCreateMethodLoopCounter = k; 215 break; 216 } 217 } } } 220 221 226 if (ejbCreateFound && exceptionsMatch) { 229 result.addGoodDetails(smh.getLocalString 230 ("tests.componentNameConstructor", 231 "For [ {0} ]", 232 new Object [] {compName.toString()})); 233 result.addGoodDetails(smh.getLocalString 234 (getClass().getName() + ".debug1", 235 "For Home Interface Method [ {0} ]", 236 new Object [] {((Method)(createMethodSuffix.elementAt(ejbCreateMethodLoopCounter))).getName()})); 237 result.addGoodDetails(smh.getLocalString 238 (getClass().getName() + ".passed", 239 "The corresponding [ {0} ] method with matching exceptions was found.", 240 new Object [] {methods[i].getName()})); 241 } 242 243 if (ejbCreateFound && !exceptionsMatch) { 244 oneFailed = true; 245 result.addErrorDetails(smh.getLocalString 246 ("tests.componentNameConstructor", 247 "For [ {0} ]", 248 new Object [] {compName.toString()})); 249 result.addErrorDetails(smh.getLocalString 250 (getClass().getName() + ".debug1", 251 "For Home Interface Method [ {0} ]", 252 new Object [] {((Method)(createMethodSuffix.elementAt(ejbCreateMethodLoopCounter))).getName()})); 253 result.addErrorDetails(smh.getLocalString 254 (getClass().getName() + ".failed", 255 "Error: A corresponding [ {0} ] method was found, but the exceptions defined by method [ {1} ] are not defined within matching create() method.", 256 new Object [] {"ejb"+methods[i].getName().toUpperCase().substring(0,1)+methods[i].getName().substring(1),"ejb"+methods[i].getName().toUpperCase().substring(0,1)+methods[i].getName().substring(1)})); 257 } else if (!ejbCreateFound) { 258 oneFailed = true; 261 result.addErrorDetails(smh.getLocalString 262 ("tests.componentNameConstructor", 263 "For [ {0} ]", 264 new Object [] {compName.toString()})); 265 result.addErrorDetails(smh.getLocalString 266 (getClass().getName() + ".debug1", 267 "For Home Interface Method [ {0} ]", 268 new Object [] {((Method)(createMethodSuffix.elementAt(ejbCreateMethodLoopCounter))).getName()})); 269 result.addErrorDetails(smh.getLocalString 270 (getClass().getName() + ".failed1", 271 "Error: No corresponding ejbCreate method was found." )); 272 break; 273 } } } if (oneFailed == true) 277 break; 278 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!(ejbCreateFound && exceptionsMatch))); 279 return oneFailed; 280 } catch (ClassNotFoundException e) { 281 Verifier.debug(e); 282 result.addErrorDetails(smh.getLocalString 283 ("tests.componentNameConstructor", 284 "For [ {0} ]", 285 new Object [] {compName.toString()})); 286 result.failed(smh.getLocalString 287 (getClass().getName() + ".failedException", 288 "Error: Home (Remote/Local) interface or Bean class [ {0} ] does not exist or is not loadable within bean [ {1} ]", 289 new Object [] {descriptor.getEjbClassName(),descriptor.getName()})); 290 return oneFailed; 291 } 292 } 293 } 294 | Popular Tags |