1 23 package com.sun.enterprise.tools.verifier.tests.ejb.businessmethod; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import java.lang.reflect.*; 27 import java.util.Set ; 28 29 import com.sun.enterprise.deployment.*; 30 import com.sun.enterprise.tools.verifier.*; 31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbUtils; 33 import com.sun.enterprise.tools.verifier.tests.*; 34 35 47 public class BusinessMethodException extends EjbTest implements EjbCheck { 48 Result result = null; 49 ComponentNameConstructor compName = null; 50 51 67 public Result check(EjbDescriptor descriptor) { 68 69 result = getInitializedResult(); 70 compName = getVerifierContext().getComponentNameConstructor(); 71 72 if ((descriptor instanceof EjbSessionDescriptor) || 73 (descriptor instanceof EjbEntityDescriptor)) { 74 if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName())) 75 commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor); 76 77 if(descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName())) 78 commonToBothInterfaces(descriptor.getLocalClassName(),descriptor); 79 80 Set <String > localAndRemoteInterfaces = descriptor.getLocalBusinessClassNames(); 81 localAndRemoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames()); 82 83 for (String localOrRemoteIntf : localAndRemoteInterfaces) 84 commonToBothInterfaces(localOrRemoteIntf, descriptor); 85 } 86 87 if(result.getStatus() != Result.FAILED && 88 result.getStatus() != Result.WARNING) { 89 addGoodDetails(result, compName); 90 result.passed(smh.getLocalString 91 (getClass().getName() + ".passed", 92 "Proper declaration of business method(s) found.")); 93 } 94 return result; 95 } 96 97 102 103 104 private void commonToBothInterfaces(String intf, EjbDescriptor descriptor) { 105 try { 106 Class intfClass = Class.forName(intf, 107 false, 108 getVerifierContext().getClassLoader()); 109 110 for (Method remoteMethod : intfClass.getMethods()) { 111 if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBObject")|| 113 remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBLocalObject")) 114 continue; 115 116 Class beanClass = Class.forName(descriptor.getEjbClassName(), 117 false, 118 getVerifierContext().getClassLoader()); 119 120 for (Method method: beanClass.getMethods()) { 121 if (method.getName().equals(remoteMethod.getName())) { 122 123 Class [] exceptions = method.getExceptionTypes(); 131 if (EjbUtils.isValidRemoteException(exceptions)) { 132 addWarningDetails(result, compName); 133 result.warning(smh.getLocalString 134 (getClass().getName() + ".failed", 135 "Error: Compatibility Note:" + 136 "\n A public business method [ {0} ] was found, but" + 137 "\n EJB 1.0 allowed the business methods to throw the " + 138 "\n java.rmi.RemoteException to indicate a non-application" + 139 "\n exception. This practice is deprecated in EJB 1.1" + 140 "\n ---an EJB 1.1 compliant enterprise bean should" + 141 "\n throw the javax.ejb.EJBException or another " + 142 "\n RuntimeException to indicate non-application exceptions" + 143 "\n to the Container. ", 144 new Object [] {method.getName()})); 145 } 146 } 147 } 148 } 149 150 } catch (Exception e) { 151 Verifier.debug(e); 152 addErrorDetails(result, compName); 153 result.failed(smh.getLocalString 154 (getClass().getName() + ".failedException", 155 "Error: Remote interface [ {0} ] or bean class [ {1} ] " + 156 "does not exist or is not loadable within bean [ {2} ].", 157 new Object [] {intf,descriptor.getEjbClassName(),descriptor.getName()})); 158 } 159 } 160 } 161 | Popular Tags |