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 java.lang.reflect.*; 27 import java.util.*; 28 import com.sun.enterprise.deployment.*; 29 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 30 import com.sun.enterprise.tools.verifier.*; 31 import java.lang.ClassLoader ; 32 import com.sun.enterprise.tools.verifier.tests.*; 33 34 47 public class HomeInterfaceFindMethodMatch extends EjbTest implements EjbCheck { 48 49 Result result = null; 50 ComponentNameConstructor compName = null; 51 52 68 public Result check(EjbDescriptor descriptor) { 69 70 result = getInitializedResult(); 71 compName = getVerifierContext().getComponentNameConstructor(); 72 if (descriptor instanceof EjbEntityDescriptor && 73 ((EjbEntityDescriptor)descriptor).getPersistenceType().equals(EjbEntityDescriptor.BEAN_PERSISTENCE)) { 74 if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName())) 75 commonToBothInterfaces(descriptor.getHomeClassName(), descriptor.getRemoteClassName(), descriptor); 76 77 if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())) 78 commonToBothInterfaces(descriptor.getLocalHomeClassName(), descriptor.getLocalClassName(), descriptor); 79 80 } else { 81 addNaDetails(result, compName); 82 result.notApplicable("This test is only applicable entity beans with bean managed persistence."); 83 } 84 85 return result; 86 } 87 88 93 94 private void commonToBothInterfaces(String home, String remote, EjbDescriptor descriptor) { 95 Class [] methodParameterTypes; 96 Class [] ejbFinderMethodParameterTypes; 97 int ejbFinderMethodLoopCounter = 0; 98 try { 99 Context context = getVerifierContext(); 101 ClassLoader jcl = context.getClassLoader(); 102 Class homeInterfaceClass = Class.forName(home, false, getVerifierContext().getClassLoader()); 103 Class remoteInterfaceClass = Class.forName(remote, false, getVerifierContext().getClassLoader()); 104 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 105 Method [] homeInterfaceMethods = homeInterfaceClass.getMethods(); 106 Method [] ejbFinderMethods = EJBClass.getMethods(); 107 int z; 108 120 for (int i=0; i< homeInterfaceMethods.length; i++) { 121 if (homeInterfaceMethods[i].getName().startsWith("find")) { 122 for (z=0; z< ejbFinderMethods.length; z++) { 125 if (ejbFinderMethods[z].getName().startsWith("ejbFind")) { 126 if (homeInterfaceMethods[i].getName().toUpperCase().equals 129 (ejbFinderMethods[z].getName().toUpperCase().substring(3))) { 130 methodParameterTypes = homeInterfaceMethods[i].getParameterTypes(); 133 ejbFinderMethodParameterTypes = ejbFinderMethods[z].getParameterTypes(); 134 135 boolean returnTypeMatch = checkReturnType(homeInterfaceMethods[i], ejbFinderMethods[z], 136 remoteInterfaceClass, descriptor); 137 138 if (!returnTypeMatch) { 139 addErrorDetails(result, compName); 140 result.failed(smh.getLocalString 141 (getClass().getName() + ".failReturnType", 142 "For Home Interface [ {0} ] Method [ {1} ] return type [ {2} ] ", 143 new Object [] {homeInterfaceClass.getName(), homeInterfaceMethods[i].getName(), homeInterfaceMethods[i].getReturnType().getName()})); 144 result.addErrorDetails(smh.getLocalString 145 (getClass().getName() + ".failReturnType1", 146 "Error: does not match with return type [ {0} ] of corresponding ejbFind<METHOD>(...).", 147 new Object [] {ejbFinderMethods[z].getReturnType().getName()})); 148 149 } 150 if (!Arrays.equals(methodParameterTypes,ejbFinderMethodParameterTypes)) { 151 152 addErrorDetails(result, compName); 153 result.failed(smh.getLocalString 154 (getClass().getName() + ".debug1", 155 "For Home Interface [ {0} ] Method [ {1} ]", 156 new Object [] {homeInterfaceClass.getName(),homeInterfaceMethods[i].getName()})); 157 result.addErrorDetails(smh.getLocalString 158 (getClass().getName() + ".failed", 159 "Error: A corresponding [ {0} ] method was found, but the parameters did not match.", 160 new Object [] {"ejb"+homeInterfaceMethods[i].getName().toUpperCase().substring(0,1)+homeInterfaceMethods[i].getName().substring(1)})); 161 } 162 163 ejbFinderMethodLoopCounter = z; 165 break; 166 } } } 170 if (z==ejbFinderMethods.length) { 171 addErrorDetails(result, compName); 174 result.failed(smh.getLocalString 175 (getClass().getName() + ".debug1", 176 "For Home Interface [ {0} ] Method [ {1} ]", 177 new Object [] {homeInterfaceClass.getName(),homeInterfaceMethods[i].getName()})); 178 result.addErrorDetails(smh.getLocalString 179 (getClass().getName() + ".failed1", 180 "Error: No corresponding ejbFind<METHOD>(...) method was found." )); 181 } 182 183 if(result.getStatus()!=Result.FAILED){ 184 addGoodDetails(result, compName); 185 result.passed(smh.getLocalString 187 (getClass().getName() + ".debug1", 188 "For Home Interface [ {0} ] Method [ {1} ]", 189 new Object [] {homeInterfaceClass.getName(),homeInterfaceMethods[i].getName()})); 190 result.addGoodDetails(smh.getLocalString 191 (getClass().getName() + ".passed", 192 "The corresponding [ {0} ] method with matching parameters was found.", 193 new Object [] {ejbFinderMethods[ejbFinderMethodLoopCounter].getName()})); 194 195 } 196 197 } } 200 } catch (ClassNotFoundException e) { 201 Verifier.debug(e); 202 result.addErrorDetails(smh.getLocalString 203 ("tests.componentNameConstructor", 204 "For [ {0} ]", 205 new Object [] {compName.toString()})); 206 result.failed(smh.getLocalString 207 (getClass().getName() + ".failedException", 208 "Error: Home interface [ {0} ] or EJB Class [ {1} ] does not exist or is not loadable.", 209 new Object [] {descriptor.getHomeClassName(),descriptor.getEjbClassName()})); 210 } 212 } 213 214 private boolean checkReturnType(Method homeFinderMethod, Method beanFinderMethod, Class remote, EjbDescriptor descriptor){ 215 Class homeMethodtype = homeFinderMethod.getReturnType(); 216 Class beanMethodType = beanFinderMethod.getReturnType(); 217 218 if (homeMethodtype.getName().equals(remote.getName())) { 219 return beanMethodType.getName().equals(((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName()); 220 } else return homeMethodtype.getName().equals(beanMethodType.getName()); 221 } 222 } 223 | Popular Tags |