1 23 package com.sun.enterprise.tools.verifier.tests.ejb.homeintf; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import java.lang.ClassLoader ; 27 import java.lang.reflect.Method ; 28 29 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 30 import com.sun.enterprise.tools.verifier.tests.ejb.EjbUtils; 31 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 32 import com.sun.enterprise.tools.verifier.Result; 33 import com.sun.enterprise.tools.verifier.Verifier; 34 import com.sun.enterprise.deployment.EjbDescriptor; 35 import com.sun.enterprise.deployment.EjbSessionDescriptor; 36 import com.sun.enterprise.deployment.EjbEntityDescriptor; 37 38 50 public class HomeMethodException extends EjbTest implements EjbCheck { 51 Result result = null; 52 ComponentNameConstructor compName = null; 53 54 69 public Result check(EjbDescriptor descriptor) { 70 71 result = getInitializedResult(); 72 compName = getVerifierContext().getComponentNameConstructor(); 73 74 if ((descriptor instanceof EjbSessionDescriptor) || 75 (descriptor instanceof EjbEntityDescriptor)) { 76 if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName())) { 77 commonToBothInterfaces(descriptor.getHomeClassName(),descriptor); 78 } 79 if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())) { 80 commonToBothInterfaces(descriptor.getLocalHomeClassName(),descriptor); 81 } 82 83 } 84 if(result.getStatus()!=Result.FAILED && 85 result.getStatus() != Result.WARNING) { 86 addGoodDetails(result, compName); 87 result.passed(smh.getLocalString 88 (getClass().getName() + ".passed", 89 "Valid Home method(s).")); 90 } 91 return result; 92 } 93 94 102 103 104 private void commonToBothInterfaces(String home,EjbDescriptor descriptor) { 105 try { 106 ClassLoader jcl = getVerifierContext().getClassLoader(); 107 Class rc = Class.forName(home, false, jcl); 108 109 for (Method homeMethod : rc.getMethods()) { 110 111 if (homeMethod.getDeclaringClass().getName().equals("javax.ejb.EJBHome")|| 112 homeMethod.getDeclaringClass().getName().equals("javax.ejb.EJBLocalHome")) 113 continue; 114 if (homeMethod.getName().startsWith("create") || 115 homeMethod.getName().startsWith("find") || 116 homeMethod.getName().startsWith("remove")) 117 continue; 118 119 Class beanClass = Class.forName(descriptor.getEjbClassName(), false, jcl); 120 121 for (Method method : beanClass.getMethods()) { 122 123 String methodName = "ejbHome" + 124 Character.toUpperCase(homeMethod.getName().charAt(0)) + 125 homeMethod.getName().substring(1); 126 127 if (method.getName().equals(methodName)) { 128 129 Class [] exceptions = method.getExceptionTypes(); 137 if(EjbUtils.isValidRemoteException(exceptions)) { 138 addWarningDetails(result, compName); 139 result.warning(smh.getLocalString 140 (getClass().getName() + ".warning", 141 "Error: Compatibility Note:" + 142 "\n A public Home method [ {0} ] was found, but" + 143 "\n EJB 1.0 allowed the 'ejbHome' methods to throw the " + 144 "\n java.rmi.RemoteException to indicate a non-application" + 145 "\n exception. This practice is deprecated in EJB 1.1" + 146 "\n ---an EJB 1.1 compliant enterprise bean should" + 147 "\n throw the javax.ejb.EJBException or another " + 148 "\n RuntimeException to indicate non-application exceptions" + 149 "\n to the Container. ", 150 new Object [] {method.getName()})); 151 } 152 153 } 154 } 155 156 } 157 158 } catch (Exception e) { 159 Verifier.debug(e); 160 addErrorDetails(result, compName); 161 result.failed(smh.getLocalString 162 (getClass().getName() + ".failedException", 163 "Error: Remote interface [ {0} ] or bean class [ {1} ] does " + 164 "not exist or is not loadable within bean [ {2} ].", 165 new Object [] {home,descriptor.getEjbClassName(),descriptor.getName()})); 166 } 167 } 168 } 169 | Popular Tags |