1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.findermethod; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import com.sun.enterprise.deployment.EjbDescriptor; 27 import com.sun.enterprise.deployment.EjbEntityDescriptor; 28 import java.lang.ClassLoader ; 29 import com.sun.enterprise.tools.verifier.tests.*; 30 import java.util.*; 31 import java.util.logging.Level ; 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 51 public class HomeInterfaceFindMethodExceptionMatch extends EjbTest implements EjbCheck { 52 Result result = null; 53 ComponentNameConstructor compName = null; 54 71 public Result check(EjbDescriptor descriptor) { 72 73 result = getInitializedResult(); 74 compName = getVerifierContext().getComponentNameConstructor(); 75 boolean oneFailed = false; 76 if (descriptor instanceof EjbEntityDescriptor) { 77 String persistence = 78 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 79 if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) { 80 if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName())) { 81 oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor); 82 } 83 if(oneFailed == false) { 84 if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())) { 85 oneFailed = commonToBothInterfaces(descriptor.getLocalHomeClassName(),descriptor); 86 } 87 } 88 89 if (oneFailed) { 90 result.setStatus(result.FAILED); 91 } else { 92 result.setStatus(result.PASSED); 93 } 94 95 return result; 96 } else { result.addNaDetails(smh.getLocalString 98 ("tests.componentNameConstructor", 99 "For [ {0} ]", 100 new Object [] {compName.toString()})); 101 result.notApplicable(smh.getLocalString 102 (getClass().getName() + ".notApplicable2", 103 "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", 104 new Object [] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistence})); 105 return result; 106 } 107 108 } else { 109 result.addNaDetails(smh.getLocalString 110 ("tests.componentNameConstructor", 111 "For [ {0} ]", 112 new Object [] {compName.toString()})); 113 result.notApplicable(smh.getLocalString 114 (getClass().getName() + ".notApplicable", 115 "[ {0} ] expected {1} bean, but called with {2} bean.", 116 new Object [] {getClass(),"Entity","Session"})); 117 return result; 118 } 119 } 120 121 128 129 private boolean commonToBothInterfaces(String home, EjbDescriptor descriptor) { 130 boolean oneFailed = false; 131 int ejbFinderMethodLoopCounter = 0; 132 try { 135 Context context = getVerifierContext(); 136 ClassLoader jcl = context.getClassLoader(); 137 Class c = Class.forName(home, false, getVerifierContext().getClassLoader()); 138 Method methods[] = c.getDeclaredMethods(); 139 Class methodReturnType; 140 Class [] methodParameterTypes; 141 Class [] methodExceptionTypes; 142 Class [] ejbFinderMethodExceptionTypes; 143 Class [] ejbFinderMethodParameterTypes; 144 boolean ejbFinderFound = false; 145 boolean signaturesMatch = false; 146 boolean exceptionsMatch = false; 147 148 149 for (int i=0; i< methods.length; i++) { 150 if (methods[i].getName().startsWith("find")) { 151 ejbFinderFound = false; 153 signaturesMatch = false; 154 exceptionsMatch = false; 155 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 157 do { 159 Method [] ejbFinderMethods = EJBClass.getDeclaredMethods(); 160 for (int z=0; z< ejbFinderMethods.length; z++) { 162 if (ejbFinderMethods[z].getName().startsWith("ejbFind")) { 163 if (methods[i].getName().toUpperCase().equals 166 (ejbFinderMethods[z].getName().toUpperCase().substring(3))) { 167 170 ejbFinderFound = true; 171 methodParameterTypes = methods[i].getParameterTypes(); 172 ejbFinderMethodParameterTypes = ejbFinderMethods[z].getParameterTypes(); 173 if (Arrays.equals(methodParameterTypes,ejbFinderMethodParameterTypes)) { 174 signaturesMatch = true; 175 176 methodExceptionTypes = methods[i].getExceptionTypes(); 177 ejbFinderMethodExceptionTypes = ejbFinderMethods[z].getExceptionTypes(); 178 179 196 if (RmiIIOPUtils.isEjbFindMethodExceptionsSubsetOfFindMethodExceptions(ejbFinderMethodExceptionTypes,methodExceptionTypes)) { 197 exceptionsMatch = true; 198 ejbFinderMethodLoopCounter = z; 200 break; 201 } 202 } } } } 208 213 if (ejbFinderFound && signaturesMatch && exceptionsMatch) { 216 result.addGoodDetails(smh.getLocalString 217 ("tests.componentNameConstructor", 218 "For [ {0} ]", 219 new Object [] {compName.toString()})); 220 result.addGoodDetails(smh.getLocalString 221 (getClass().getName() + ".debug1", 222 "For Home Interface [ {0} ] Method [ {1} ]", 223 new Object [] {c.getName(),methods[i].getName()})); 224 result.addGoodDetails(smh.getLocalString 225 (getClass().getName() + ".passed", 226 "The corresponding [ {0} ] method with matching exceptions was found.", 227 new Object [] {ejbFinderMethods[ejbFinderMethodLoopCounter].getName()})); 228 } else if (ejbFinderFound && signaturesMatch && !exceptionsMatch) { 229 logger.log(Level.FINE, getClass().getName() + ".debug1", 230 new Object [] {c.getName(),methods[i].getName()}); 231 logger.log(Level.FINE, getClass().getName() + ".debug3", 232 new Object [] {"ejb"+methods[i].getName().toUpperCase().substring(0,1)+methods[i].getName().substring(1)}); 233 logger.log(Level.FINE, getClass().getName() + ".debug2"); 234 235 } else if (ejbFinderFound && !signaturesMatch) { 236 logger.log(Level.FINE, getClass().getName() + ".debug1", 237 new Object [] {c.getName(),methods[i].getName()}); 238 logger.log(Level.FINE, getClass().getName() + ".debug4", 239 new Object [] {"ejb"+methods[i].getName().toUpperCase().substring(0,1)+methods[i].getName().substring(1)}); 240 logger.log(Level.FINE, getClass().getName() + ".debug2"); 241 242 } 243 244 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!(ejbFinderFound && signaturesMatch && exceptionsMatch))); 245 246 247 if (!ejbFinderFound && !signaturesMatch && !exceptionsMatch) { 248 oneFailed = true; 249 result.addErrorDetails(smh.getLocalString 250 ("tests.componentNameConstructor", 251 "For [ {0} ]", 252 new Object [] {compName.toString()})); 253 result.addErrorDetails(smh.getLocalString 254 (getClass().getName() + ".debug1", 255 "For Home Interface [ {0} ] Method [ {1} ]", 256 new Object [] {c.getName(),methods[i].getName()})); 257 result.addErrorDetails(smh.getLocalString 258 (getClass().getName() + ".failed", 259 "Error: No corresponding [ {0} ] method with matching signatures was found." , 260 new Object [] {"ejb"+methods[i].getName().toUpperCase().substring(0,1)+methods[i].getName().substring(1)})); 261 } } } return oneFailed; 265 266 } catch (ClassNotFoundException e) { 267 Verifier.debug(e); 268 result.addErrorDetails(smh.getLocalString 269 ("tests.componentNameConstructor", 270 "For [ {0} ]", 271 new Object [] {compName.toString()})); 272 result.failed(smh.getLocalString 273 (getClass().getName() + ".failedException", 274 "Error: Home interface [ {0} ] or EJB class [ {1} ] does not exist or is not loadable within bean [ {2} ]", 275 new Object [] {home, descriptor.getEjbClassName(),descriptor.getName()})); 276 return oneFailed; 277 } 278 } 279 } 280 | Popular Tags |