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