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