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 java.lang.ClassLoader ; 27 import com.sun.enterprise.tools.verifier.tests.*; 28 import javax.ejb.EntityBean ; 29 import java.lang.reflect.*; 30 import com.sun.enterprise.deployment.*; 31 import com.sun.enterprise.tools.verifier.*; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 34 49 public class EjbCreateMethodExceptions extends EjbTest implements EjbCheck { 50 51 52 69 public Result check(EjbDescriptor descriptor) { 70 71 Result result = getInitializedResult(); 72 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 73 74 if (descriptor instanceof EjbEntityDescriptor) { 75 boolean oneFailed = false; 76 int foundWarning = 0; 77 int foundAtLeastOne = 0; 78 try { 79 Context context = getVerifierContext(); 80 ClassLoader jcl = context.getClassLoader(); 81 Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 82 83 boolean ejbCreateFound = false; 84 boolean throwsRemoteException = false; 85 do { 87 Method [] methods = c.getDeclaredMethods(); 88 for (int i = 0; i < methods.length; i++) { 89 ejbCreateFound = false; 91 throwsRemoteException = false; 92 93 if (methods[i].getName().startsWith("ejbCreate")) { 95 foundAtLeastOne++; 96 ejbCreateFound = true; 97 98 Class [] exceptions = methods[i].getExceptionTypes(); 106 for (int z = 0; z < exceptions.length; ++z) { 107 if (exceptions[z].getName().equals("java.rmi.RemoteException")) { 108 throwsRemoteException = true; 109 break; 110 } 111 } 112 113 if (ejbCreateFound && (!throwsRemoteException)) { 116 result.addGoodDetails(smh.getLocalString 117 ("tests.componentNameConstructor", 118 "For [ {0} ]", 119 new Object [] {compName.toString()})); 120 result.addGoodDetails(smh.getLocalString 121 (getClass().getName() + ".debug1", 122 "For EJB Class [ {0} ] method [ {1} ]", 123 new Object [] {descriptor.getEjbClassName(),methods[i].getName()})); 124 result.addGoodDetails(smh.getLocalString 125 (getClass().getName() + ".passed", 126 "[ {0} ] properly declares [ {1} ] method which does not throw java.rmi.RemoteException.", 127 new Object [] {descriptor.getEjbClassName(),methods[i].getName()})); 128 } else if (ejbCreateFound && throwsRemoteException) { 129 result.addWarningDetails(smh.getLocalString 130 ("tests.componentNameConstructor", 131 "For [ {0} ]", 132 new Object [] {compName.toString()})); 133 result.addWarningDetails(smh.getLocalString 134 (getClass().getName() + ".debug1", 135 "For EJB Class [ {0} ] method [ {1} ]", 136 new Object [] {descriptor.getEjbClassName(),methods[i].getName()})); 137 result.addWarningDetails(smh.getLocalString 138 (getClass().getName() + ".warning", 139 "Error: Compatibility Note:" + 140 "\n An [ {0} ] method was found, but" + 141 "\n EJB 1.0 allowed the ejbCreate method to throw the " + 142 "\n java.rmi.RemoteException to indicate a non-application" + 143 "\n exception. This practice is deprecated in EJB 1.1" + 144 "\n ---an EJB 1.1 compliant enterprise bean should" + 145 "\n throw the javax.ejb.EJBException or another " + 146 "\n RuntimeException to indicate non-application exceptions" + 147 "\n to the Container. ", 148 new Object [] {methods[i].getName()})); 149 foundWarning++; 150 break; 151 } 152 } 153 } 154 if (foundWarning > 0) 155 break; 156 } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0)); 157 158 if (foundAtLeastOne == 0) { 159 result.addNaDetails(smh.getLocalString 160 ("tests.componentNameConstructor", 161 "For [ {0} ]", 162 new Object [] {compName.toString()})); 163 result.notApplicable(smh.getLocalString 164 (getClass().getName() + ".notApplicable1", 165 "[ {0} ] does not declare any ejbCreate(...) methods.", 166 new Object [] {descriptor.getEjbClassName()})); 167 } 168 } catch (ClassNotFoundException e) { 169 Verifier.debug(e); 170 result.addErrorDetails(smh.getLocalString 171 ("tests.componentNameConstructor", 172 "For [ {0} ]", 173 new Object [] {compName.toString()})); 174 result.failed(smh.getLocalString 175 (getClass().getName() + ".failedException", 176 "Error: [ {0} ] class not found.", 177 new Object [] {descriptor.getEjbClassName()})); 178 oneFailed = true; 179 } 180 181 if (oneFailed) { 182 result.setStatus(result.FAILED); 183 } else if (foundAtLeastOne == 0) { 184 result.setStatus(result.NOT_APPLICABLE); 185 } else if (foundWarning > 0) { 186 result.setStatus(result.WARNING); 187 } else { 188 result.setStatus(result.PASSED); 189 } 190 191 return result; 192 193 } else { 194 result.addNaDetails(smh.getLocalString 195 ("tests.componentNameConstructor", 196 "For [ {0} ]", 197 new Object [] {compName.toString()})); 198 result.notApplicable(smh.getLocalString 199 (getClass().getName() + ".notApplicable", 200 "[ {0} ] expected {1} bean, but called with {2} bean.", 201 new Object [] {getClass(),"Entity","Session"})); 202 return result; 203 } 204 } 205 } 206 | Popular Tags |