1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.ejbfindbyprimarykey; 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.EjbDescriptor; 30 import com.sun.enterprise.deployment.MethodDescriptor; 31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 32 import com.sun.enterprise.tools.verifier.*; 33 import java.lang.ClassLoader ; 34 import com.sun.enterprise.tools.verifier.tests.*; 35 36 50 public class EjbFindByPrimaryKeyException extends EjbTest implements EjbCheck { 51 52 53 70 public Result check(EjbDescriptor descriptor) { 71 72 Result result = getInitializedResult(); 73 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 74 75 if (descriptor instanceof EjbEntityDescriptor) { 76 String persistentType = 77 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 78 if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistentType)) { 79 boolean ejbFindByPrimaryKeyMethodFound = false; 80 boolean throwsRemoteException = false; 81 boolean oneFailed = false; 82 int foundWarning = 0; 83 try { 84 Context context = getVerifierContext(); 86 ClassLoader jcl = context.getClassLoader(); 87 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 88 do { 90 Method [] ejbFinderMethods = EJBClass.getDeclaredMethods(); 91 92 for (int j = 0; j < ejbFinderMethods.length; ++j) { 93 if (ejbFinderMethods[j].getName().equals("ejbFindByPrimaryKey")) { 94 ejbFindByPrimaryKeyMethodFound = true; 97 98 Class [] exceptions = ejbFinderMethods[j].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 (ejbFindByPrimaryKeyMethodFound && (!throwsRemoteException)) { 114 result.addGoodDetails(smh.getLocalString 115 ("tests.componentNameConstructor", 116 "For [ {0} ]", 117 new Object [] {compName.toString()})); 118 result.addGoodDetails(smh.getLocalString 119 (getClass().getName() + ".debug1", 120 "For EJB Class [ {0} ] Finder Method [ {1} ]", 121 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 122 result.addGoodDetails(smh.getLocalString 123 (getClass().getName() + ".passed", 124 "[ {0} ] declares [ {1} ] method, which properly does not throw java.rmi.RemoteException", 125 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 126 } else if (ejbFindByPrimaryKeyMethodFound && throwsRemoteException) { 127 result.addWarningDetails(smh.getLocalString 128 ("tests.componentNameConstructor", 129 "For [ {0} ]", 130 new Object [] {compName.toString()})); 131 result.addWarningDetails(smh.getLocalString 132 (getClass().getName() + ".debug1", 133 "For EJB Class [ {0} ] Finder Method [ {1} ]", 134 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 135 result.addWarningDetails(smh.getLocalString 136 (getClass().getName() + ".warning", 137 "Error: Compatibility Note:" + 138 "\n An [ {0} ] method was found, but" + 139 "\n EJB 1.0 allowed the ejbFindByPrimaryKey method to throw " + 140 "\n the java.rmi.RemoteException to indicate a non-application" + 141 "\n exception. This practice is deprecated in EJB 1.1" + 142 "\n ---an EJB 1.1 compliant enterprise bean should" + 143 "\n throw the javax.ejb.EJBException or another " + 144 "\n RuntimeException to indicate non-application exceptions" + 145 "\n to the Container. ", 146 new Object [] {ejbFinderMethods[j].getName()})); 147 foundWarning++; 148 } 149 break; 151 } 152 } 153 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!ejbFindByPrimaryKeyMethodFound)); 154 155 if (!ejbFindByPrimaryKeyMethodFound) { 156 oneFailed = true; 157 result.addErrorDetails(smh.getLocalString 158 ("tests.componentNameConstructor", 159 "For [ {0} ]", 160 new Object [] {compName.toString()})); 161 result.addErrorDetails(smh.getLocalString 162 (getClass().getName() + ".debug3", 163 "For EJB Class [ {0} ]", 164 new Object [] {descriptor.getEjbClassName()})); 165 result.addErrorDetails(smh.getLocalString 166 (getClass().getName() + ".failed", 167 "Error: No ejbFindByPrimaryKey method was found in bean class.")); 168 } 169 } catch (ClassNotFoundException e) { 170 Verifier.debug(e); 171 result.addErrorDetails(smh.getLocalString 172 ("tests.componentNameConstructor", 173 "For [ {0} ]", 174 new Object [] {compName.toString()})); 175 result.failed(smh.getLocalString 176 (getClass().getName() + ".failedException", 177 "Error: EJB Class [ {0} ] does not exist or is not loadable.", 178 new Object [] {descriptor.getEjbClassName()})); 179 oneFailed = true; 180 } 181 182 if (oneFailed) { 183 result.setStatus(result.FAILED); 184 } else if (foundWarning > 0) { 185 result.setStatus(result.WARNING); 186 } else { 187 result.setStatus(result.PASSED); 188 } 189 190 } else { result.addNaDetails(smh.getLocalString 192 ("tests.componentNameConstructor", 193 "For [ {0} ]", 194 new Object [] {compName.toString()})); 195 result.notApplicable(smh.getLocalString 196 (getClass().getName() + ".notApplicable2", 197 "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]", 198 new Object [] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistentType})); 199 } 200 return result; 201 202 } else { 203 result.addNaDetails(smh.getLocalString 204 ("tests.componentNameConstructor", 205 "For [ {0} ]", 206 new Object [] {compName.toString()})); 207 result.notApplicable(smh.getLocalString 208 (getClass().getName() + ".notApplicable", 209 "[ {0} ] expected {1} bean, but called with {2} bean.", 210 new Object [] {getClass(),"Entity","Session"})); 211 return result; 212 } 213 } 214 } 215 | Popular Tags |