1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.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.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 HomeInterfaceCreateMethodExceptionMatch extends EjbTest implements EjbCheck { 52 53 Result result = null; 54 ComponentNameConstructor compName = null; 55 boolean foundAtLeastOneCreate = false; 56 72 public Result check(EjbDescriptor descriptor) { 73 74 result = getInitializedResult(); 75 compName = getVerifierContext().getComponentNameConstructor(); 76 boolean oneFailed = false; 77 if (descriptor instanceof EjbEntityDescriptor) { 78 oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor.getLocalHomeClassName(),descriptor); 79 if (!foundAtLeastOneCreate) { 80 result.addNaDetails(smh.getLocalString 81 ("tests.componentNameConstructor", 82 "For [ {0} ]", 83 new Object [] {compName.toString()})); 84 result.addNaDetails(smh.getLocalString 85 (getClass().getName() + ".debug4", 86 "In Home Interface ", 87 new Object [] {})); 88 result.addNaDetails(smh.getLocalString 89 (getClass().getName() + ".notApplicable1", 90 "No create method was found, test not applicable." )); 91 result.setStatus(result.NOT_APPLICABLE); 92 } else { 93 if (oneFailed) { 94 result.setStatus(result.FAILED); 95 } else { 96 result.setStatus(result.PASSED); 97 } 98 } 99 return result; 100 101 } else { 102 result.addNaDetails(smh.getLocalString 103 ("tests.componentNameConstructor", 104 "For [ {0} ]", 105 new Object [] {compName.toString()})); 106 result.notApplicable(smh.getLocalString 107 (getClass().getName() + ".notApplicable", 108 "[ {0} ] expected {1} bean, but called with {2} bean.", 109 new Object [] {getClass(),"Entity","Session"})); 110 return result; 111 } 112 } 113 114 121 122 private boolean commonToBothInterfaces(String component, String local,EjbDescriptor descriptor) { 123 boolean oneFailed = false; 124 int ejbCreateMethodLoopCounter = 0; 125 try { 128 Class methodReturnType; 129 Class [] methodParameterTypes; 130 Class [] methodExceptionTypes; 131 Class [] ejbCreateMethodExceptionTypes; 132 Class [] ejbCreateMethodParameterTypes; 133 boolean ejbCreateFound = false; 134 boolean exceptionsMatch = false; 135 Vector<Method> createMethodSuffix = new Vector<Method>(); 136 137 if (component != null) { 138 Class home = Class.forName(component, false, getVerifierContext().getClassLoader()); 139 Method [] homeMethods = home.getDeclaredMethods(); 140 141 for (int i = 0; i < homeMethods.length; i++) { 142 if (homeMethods[i].getName().startsWith("create")) { 144 createMethodSuffix.addElement( (Method)homeMethods[i]); 145 foundAtLeastOneCreate = true; 146 } 147 } 148 } 149 if (local != null) { 150 Class home = Class.forName(local, false, getVerifierContext().getClassLoader()); 151 Method [] homeMethods = home.getDeclaredMethods(); 152 153 for (int i = 0; i < homeMethods.length; i++) { 154 if (homeMethods[i].getName().startsWith("create")) { 156 createMethodSuffix.addElement( (Method)homeMethods[i]); 157 foundAtLeastOneCreate = true; 158 } 159 } 160 } 161 if (foundAtLeastOneCreate == false) 162 return false; 163 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 164 165 do { 166 Method [] methods = EJBClass.getDeclaredMethods(); 167 for (int i = 0; i < methods.length; i++) { 169 ejbCreateFound = false; 170 exceptionsMatch = false; 171 if (methods[i].getName().startsWith("ejbCreate")) { 172 String matchSuffix = methods[i].getName().substring(9); 173 for (int k = 0; k < createMethodSuffix.size(); k++) { 174 if (matchSuffix.equals(((Method)(createMethodSuffix.elementAt(k))).getName().substring(6))) { 175 methodParameterTypes = ((Method)(createMethodSuffix.elementAt(k))).getParameterTypes(); 178 ejbCreateMethodParameterTypes = methods[i].getParameterTypes(); 179 if (Arrays.equals(methodParameterTypes,ejbCreateMethodParameterTypes)) { 180 ejbCreateFound = true; 181 methodExceptionTypes = ((Method)(createMethodSuffix.elementAt(k))).getExceptionTypes(); 182 ejbCreateMethodExceptionTypes = methods[i].getExceptionTypes(); 183 if (RmiIIOPUtils.isEjbFindMethodExceptionsSubsetOfFindMethodExceptions(ejbCreateMethodExceptionTypes,methodExceptionTypes)) { 194 exceptionsMatch = true; 195 ejbCreateMethodLoopCounter = k; 197 break; 198 } 199 } } 201 } 202 207 if (ejbCreateFound && exceptionsMatch) { 210 result.addGoodDetails(smh.getLocalString 211 ("tests.componentNameConstructor", 212 "For [ {0} ]", 213 new Object [] {compName.toString()})); 214 result.addGoodDetails(smh.getLocalString 215 (getClass().getName() + ".debug1", 216 "For Home Interface Method [ {0} ]", 217 new Object [] {((Method)(createMethodSuffix.elementAt(ejbCreateMethodLoopCounter))).getName()})); 218 result.addGoodDetails(smh.getLocalString 219 (getClass().getName() + ".passed", 220 "The corresponding [ {0} ] method with matching exceptions was found.", 221 new Object [] {methods[i].getName()})); 222 } else if (ejbCreateFound && !exceptionsMatch) { 223 oneFailed = true; 224 result.addErrorDetails(smh.getLocalString 225 ("tests.componentNameConstructor", 226 "For [ {0} ]", 227 new Object [] {compName.toString()})); 228 result.addErrorDetails(smh.getLocalString 229 (getClass().getName() + ".debug1", 230 "For Home Interface Method [ {0} ]", 231 new Object [] {((Method)(createMethodSuffix.elementAt(ejbCreateMethodLoopCounter))).getName()})); 232 result.addErrorDetails(smh.getLocalString 233 (getClass().getName() + ".failed", 234 "Error: No corresponding ejbCreate() method was found, where the exceptions defined by method ejbCreate() are defined within matching create() method.")); 235 logger.log(Level.FINE, getClass().getName() + ".debug1", 236 new Object [] {((Method)(createMethodSuffix.elementAt(ejbCreateMethodLoopCounter))).getName()}); 237 logger.log(Level.FINE, getClass().getName() + ".debug3", 238 new Object [] {methods[i].getName(),((Method)(createMethodSuffix.elementAt(ejbCreateMethodLoopCounter))).getName()}); 239 break; 240 } } 242 if (oneFailed == true) 243 break; 244 } 245 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!(ejbCreateFound && exceptionsMatch))); 246 247 return oneFailed; 248 } catch (ClassNotFoundException e) { 249 Verifier.debug(e); 250 result.addErrorDetails(smh.getLocalString 251 ("tests.componentNameConstructor", 252 "For [ {0} ]", 253 new Object [] {compName.toString()})); 254 result.failed(smh.getLocalString 255 (getClass().getName() + ".failedException", 256 "Error: Home (Local/Remote) interface or bean class [ {0} ] does not exist or is not loadable within bean [ {1} ]", 257 new Object [] {descriptor.getEjbClassName(),descriptor.getName()})); 258 return oneFailed; 259 } 260 } 261 } 262 | Popular Tags |