1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.ejbcreatemethod; 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 EjbCreateMatchesCreate 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 EjbEntityDescriptor) { 74 boolean oneFailed = false; 75 oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor.getLocalHomeClassName(),descriptor); 78 if (oneFailed) { 79 result.setStatus(result.FAILED); 80 } else { 81 if(foundAtLeastOneCreate == false) 82 { 83 result.setStatus(Result.NOT_APPLICABLE); 84 } 85 else 86 result.setStatus(result.PASSED); 87 } 88 89 return result; 90 91 } else { 92 result.addNaDetails(smh.getLocalString 93 ("tests.componentNameConstructor", 94 "For [ {0} ]", 95 new Object [] {compName.toString()})); 96 result.notApplicable(smh.getLocalString 97 (getClass().getName() + ".notApplicable", 98 "[ {0} ] expected {1} bean, but called with {2} bean.", 99 new Object [] {getClass(),"Session","Entity"})); 100 return result; 101 } 102 } 103 104 110 111 112 private boolean commonToBothInterfaces(String remote, String local,EjbDescriptor descriptor) { 113 boolean oneFailed = false; 114 try { 115 Context context = getVerifierContext(); 116 ClassLoader jcl = context.getClassLoader(); 117 Class [] methodParameterTypes; 118 Class [] businessMethodParameterTypes; 119 boolean signaturesMatch = false; 120 121 boolean found = false; 122 Vector<Method> createMethodSuffix = new Vector<Method>(); 123 124 if (local != null) { 125 Class localhome = Class.forName(local, false, getVerifierContext().getClassLoader()); 126 Method [] localhomeMethods = localhome.getDeclaredMethods(); 127 for (int i = 0; i < localhomeMethods.length; i++) { 128 if (localhomeMethods[i].getName().startsWith("create")) { 130 createMethodSuffix.addElement( (Method)localhomeMethods[i]); 131 foundAtLeastOneCreate = true; 132 133 } 134 } 135 } 136 if (remote != null) { 137 Class home = Class.forName(remote, false, getVerifierContext().getClassLoader()); 138 Method [] homeMethods = home.getDeclaredMethods(); 139 for (int i = 0; i < homeMethods.length; i++) { 140 if (homeMethods[i].getName().startsWith("create")) { 142 createMethodSuffix.addElement( (Method)homeMethods[i]); 143 foundAtLeastOneCreate = true; 144 145 } 146 } 147 } 148 if (foundAtLeastOneCreate == false) { 149 result.addNaDetails(smh.getLocalString 150 ("tests.componentNameConstructor", 151 "For [ {0} ]", 152 new Object [] {compName.toString()})); 153 result.notApplicable(smh.getLocalString 154 (getClass().getName() + ".notApplicable1", 155 "[ {0} ]`s home/localhome does not declare any create<Method> methods.", 156 new Object [] {descriptor.getEjbClassName()})); 157 return false; 158 } 159 160 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 161 do { 163 Method [] methods = EJBClass.getMethods(); 164 for (int k = 0; k < createMethodSuffix.size(); k++) { 166 for (int j = 0; j < methods.length; j++) { 167 found = false; 168 if (methods[j].getName().startsWith("ejbCreate")) { 169 found = true; 170 String matchSuffix = methods[j].getName().substring(9); 171 signaturesMatch = false; 172 if (matchSuffix.equals(((Method)(createMethodSuffix.elementAt(k))).getName().substring(6))) { 173 methodParameterTypes = ((Method)(createMethodSuffix.elementAt(k))).getParameterTypes(); 174 businessMethodParameterTypes = methods[j].getParameterTypes(); 175 if (Arrays.equals(methodParameterTypes,businessMethodParameterTypes)) { 176 signaturesMatch = true; 177 result.addGoodDetails(smh.getLocalString 180 ("tests.componentNameConstructor", 181 "For [ {0} ]", 182 new Object [] {compName.toString()})); 183 result.addGoodDetails(smh.getLocalString 184 (getClass().getName() + ".debug1", 185 "For Home Interface Method [ {0} ]", 186 new Object [] {((Method)(createMethodSuffix.elementAt(k))).getName()})); 187 result.addGoodDetails(smh.getLocalString 188 (getClass().getName() + ".passed", 189 "The corresponding ejbCreate method with matching parameters was found.")); 190 break; 191 } 192 } 193 } 194 } 195 if (signaturesMatch == false) { 196 oneFailed = true; 197 result.addErrorDetails(smh.getLocalString 198 ("tests.componentNameConstructor", 199 "For [ {0} ]", 200 new Object [] {compName.toString()})); 201 result.addErrorDetails(smh.getLocalString 202 (getClass().getName() + ".debug3", 203 "For Home Interface", 204 new Object [] {})); 205 result.addErrorDetails(smh.getLocalString 206 (getClass().getName() + ".failed", 207 "Error: No corresponding ejbCreate<Method> method with matching parameters was found." )); 208 break; 209 210 } 211 } 212 if (oneFailed == true) 213 break; 214 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!signaturesMatch)); 215 if (found == false && foundAtLeastOneCreate == true){ 216 result.addErrorDetails(smh.getLocalString 217 ("tests.componentNameConstructor", 218 "For [ {0} ]", 219 new Object [] {compName.toString()})); 220 result.failed(smh.getLocalString 221 (getClass().getName() + ".failedException1", 222 "Error: ejbCreate<Method> method corresponding to the create<Method> method does not exist!", 223 new Object [] {})); 224 225 } 226 if (found == false && foundAtLeastOneCreate == false){ 227 result.addErrorDetails(smh.getLocalString 228 ("tests.componentNameConstructor", 229 "For [ {0} ]", 230 new Object [] {compName.toString()})); 231 result.failed(smh.getLocalString 232 (getClass().getName() + ".failedException2", 233 "Error: no create<Method> method exists!", 234 new Object [] {})); 235 } 236 return oneFailed; 237 } catch (ClassNotFoundException e) { 238 Verifier.debug(e); 239 result.addErrorDetails(smh.getLocalString 240 ("tests.componentNameConstructor", 241 "For [ {0} ]", 242 new Object [] {compName.toString()})); 243 result.failed(smh.getLocalString 244 (getClass().getName() + ".failedException", 245 "Error: Home (Local/Remote) interface or bean class [ {0} ] does not exist or is not loadable within bean [ {1} ]", 246 new Object [] {descriptor.getEjbClassName(),descriptor.getName()})); 247 oneFailed = true; 248 return oneFailed; 249 } 250 251 } 252 } 253 | Popular Tags |