1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.ejbfindermethod; 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.EjbEntityDescriptor; 29 import com.sun.enterprise.deployment.EjbCMPEntityDescriptor; 30 import com.sun.enterprise.deployment.EjbDescriptor; 31 import com.sun.enterprise.deployment.MethodDescriptor; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbUtils; 34 import com.sun.enterprise.tools.verifier.*; 35 import java.lang.ClassLoader ; 36 import com.sun.enterprise.tools.verifier.tests.*; 37 38 57 public class EjbFinderMethodException extends EjbTest implements EjbCheck { 58 59 60 82 public Result check(EjbDescriptor descriptor) { 83 84 Result result = getInitializedResult(); 85 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 86 87 if (descriptor instanceof EjbEntityDescriptor) { 88 String persistence = 89 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 90 if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) { 91 92 boolean ejbFindMethodFound = false; 93 boolean throwsRemoteException = false; 94 boolean throwsFinderException = false; 95 boolean isValidFinderException = false; 96 boolean oneFailed = false; 97 int foundWarning = 0; 98 int foundAtLeastOne = 0; 99 try { 100 Context context = getVerifierContext(); 102 ClassLoader jcl = context.getClassLoader(); 103 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 104 do { 106 Method [] ejbFinderMethods = EJBClass.getDeclaredMethods(); 107 108 for (int j = 0; j < ejbFinderMethods.length; ++j) { 109 throwsRemoteException = false; 110 throwsFinderException = false; 111 ejbFindMethodFound = false; 112 113 if (ejbFinderMethods[j].getName().startsWith("ejbFind")) { 114 ejbFindMethodFound = true; 115 foundAtLeastOne++; 116 117 Class [] exceptions = ejbFinderMethods[j].getExceptionTypes(); 125 if (EjbUtils.isValidRemoteException(exceptions)) { 126 throwsRemoteException = true; 127 } 128 129 if (EjbUtils.isValidFinderException(exceptions)) { 130 throwsFinderException = true; 131 } 132 133 if (ejbFindMethodFound && throwsRemoteException == false && throwsFinderException == true) { 134 result.addGoodDetails(smh.getLocalString 135 ("tests.componentNameConstructor", 136 "For [ {0} ]", 137 new Object [] {compName.toString()})); 138 result.addGoodDetails(smh.getLocalString 139 (getClass().getName() + ".debug1", 140 "For EJB Class [ {0} ] Finder Method [ {1} ]", 141 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 142 result.addGoodDetails(smh.getLocalString 143 (getClass().getName() + ".passed", 144 "[ {0} ] declares [ {1} ] method, which properly does not throw java.rmi.RemoteException, but throws FinderException", 145 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 146 } else if (ejbFindMethodFound && throwsRemoteException == true) { 147 if (descriptor instanceof EjbCMPEntityDescriptor){ 148 if(((EjbCMPEntityDescriptor) descriptor).getCMPVersion()==EjbCMPEntityDescriptor.CMP_2_x){ 149 150 result.addErrorDetails(smh.getLocalString 151 ("tests.componentNameConstructor", 152 "For [ {0} ]", 153 new Object [] {compName.toString()})); 154 result.addErrorDetails(smh.getLocalString 155 (getClass().getName() + ".debug1", 156 "For EJB Class [ {0} ] Finder method [ {1} ]", 157 new Object [] {descriptor.getEjbClassName(),ejbFinderMethods[j].getName()})); 158 result.addErrorDetails(smh.getLocalString 159 (getClass().getName() + ".error", 160 "Error: Compatibility Note:" + 161 "\n An [ {0} ] method was found, but" + 162 "\n EJB 1.0 allowed the ejbFind<METHOD> method to throw the " + 163 "\n java.rmi.RemoteException to indicate a non-application" + 164 "\n exception. This practice was deprecated in EJB 1.1" + 165 "\n ---an EJB 2.0 compliant enterprise bean must" + 166 "\n throw the javax.ejb.EJBException or another " + 167 "\n RuntimeException to indicate non-application exceptions" + 168 "\n to the Container. ", 169 new Object [] {ejbFinderMethods[j].getName()})); 170 oneFailed = true; 171 } else { 172 foundWarning++; 174 result.addWarningDetails(smh.getLocalString 175 ("tests.componentNameConstructor", 176 "For [ {0} ]", 177 new Object [] {compName.toString()})); 178 result.addWarningDetails(smh.getLocalString 179 (getClass().getName() + ".debug1", 180 "For EJB Class [ {0} ] Finder method [ {1} ]", 181 new Object [] {descriptor.getEjbClassName(),ejbFinderMethods[j].getName()})); 182 result.addWarningDetails(smh.getLocalString 183 (getClass().getName() + ".warning", 184 "Error: Compatibility Note:" + 185 "\n An [ {0} ] method was found, but" + 186 "\n EJB 1.0 allowed the ejbFind<METHOD> method to throw the " + 187 "\n java.rmi.RemoteException to indicate a non-application" + 188 "\n exception. This practice is deprecated in EJB 1.1" + 189 "\n ---an EJB 1.1 compliant enterprise bean should" + 190 "\n throw the javax.ejb.EJBException or another " + 191 "\n RuntimeException to indicate non-application exceptions" + 192 "\n to the Container. ", 193 new Object [] {ejbFinderMethods[j].getName()})); 194 } 195 }else{ 196 result.addNaDetails(smh.getLocalString 197 ("tests.componentNameConstructor", 198 "For [ {0} ]", 199 new Object [] {compName.toString()})); 200 result.notApplicable(smh.getLocalString 201 (getClass().getName() + ".notApplicable1", 202 "[ {0} ] does not declare any ejbFind<METHOD>(...) methods.", 203 new Object [] {descriptor.getEjbClassName()})); 204 } 205 } else if (ejbFindMethodFound && throwsFinderException == false) { 206 result.addErrorDetails(smh.getLocalString 207 ("tests.componentNameConstructor", 208 "For [ {0} ]", 209 new Object [] {compName.toString()})); 210 result.addErrorDetails(smh.getLocalString 211 (getClass().getName() + ".debug1", 212 "For EJB Class [ {0} ] Finder method [ {1} ]", 213 new Object [] {descriptor.getEjbClassName(),ejbFinderMethods[j].getName()})); 214 result.addErrorDetails(smh.getLocalString 215 (getClass().getName() + ".error1", 216 "Error: ejbFind[Method] [ {0} ] does not throw FinderException", 217 new Object [] {ejbFinderMethods[j].getName()})); 218 oneFailed = true; 219 } 220 } 221 } 222 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (foundAtLeastOne == 0)); 223 224 if (foundAtLeastOne == 0) { 225 result.addNaDetails(smh.getLocalString 226 ("tests.componentNameConstructor", 227 "For [ {0} ]", 228 new Object [] {compName.toString()})); 229 result.notApplicable(smh.getLocalString 230 (getClass().getName() + ".notApplicable1", 231 "[ {0} ] does not declare any ejbFind<METHOD>(...) methods.", 232 new Object [] {descriptor.getEjbClassName()})); 233 } 234 235 } catch (ClassNotFoundException e) { 236 Verifier.debug(e); 237 result.addErrorDetails(smh.getLocalString 238 ("tests.componentNameConstructor", 239 "For [ {0} ]", 240 new Object [] {compName.toString()})); 241 result.failed(smh.getLocalString 242 (getClass().getName() + ".failedException", 243 "Error: EJB Class [ {1} ] does not exist or is not loadable.", 244 new Object [] {descriptor.getEjbClassName()})); 245 oneFailed = true; 246 } 247 248 if (oneFailed) { 249 result.setStatus(result.FAILED); 250 } else if (foundAtLeastOne == 0) { 251 result.setStatus(result.NOT_APPLICABLE); 252 } else if (foundWarning > 0) { 253 result.setStatus(result.WARNING); 254 } else { 255 result.setStatus(result.PASSED); 256 } 257 258 return result; 259 260 } else { result.addNaDetails(smh.getLocalString 262 ("tests.componentNameConstructor", 263 "For [ {0} ]", 264 new Object [] {compName.toString()})); 265 result.notApplicable(smh.getLocalString 266 (getClass().getName() + ".notApplicable2", 267 "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", 268 new Object [] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistence})); 269 return result; 270 } 271 272 } else { 273 result.addNaDetails(smh.getLocalString 274 ("tests.componentNameConstructor", 275 "For [ {0} ]", 276 new Object [] {compName.toString()})); 277 result.notApplicable(smh.getLocalString 278 (getClass().getName() + ".notApplicable", 279 "[ {0} ] expected {1} bean, but called with {2} bean.", 280 new Object [] {getClass(),"Entity","Session"})); 281 return result; 282 } 283 } 284 } 285 | Popular Tags |