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.Method ; 27 28 import com.sun.enterprise.deployment.*; 29 import com.sun.enterprise.tools.verifier.*; 30 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 31 import com.sun.enterprise.tools.verifier.tests.*; 32 33 42 43 public class BusinessMethodExceptionCheck extends EjbTest implements EjbCheck { 44 Result result = null; 45 ComponentNameConstructor compName = null; 46 47 48 61 62 public Result check(EjbDescriptor descriptor) { 63 64 result = getInitializedResult(); 65 compName = getVerifierContext().getComponentNameConstructor(); 66 67 if (descriptor instanceof EjbSessionDescriptor) { 68 if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName())) { 69 commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor); 70 } 71 if(descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName())) { 72 commonToBothInterfaces(descriptor.getLocalClassName(),descriptor); 73 } 74 75 } 76 if(result.getStatus() != Result.FAILED && 77 result.getStatus() != Result.WARNING) { 78 addGoodDetails(result, compName); 79 result.passed(smh.getLocalString 80 (getClass().getName() + ".passed", 81 "All the exceptions defined in the throws clause of the matching "+ 82 "business methods are defined in the throws clause of the method "+ 83 "of the remote interface ")); 84 } 85 return result; 86 } 87 88 89 95 96 97 98 private void commonToBothInterfaces(String intf,EjbDescriptor descriptor) { 99 try { 100 Class intfClass = Class.forName(intf, false, getVerifierContext().getClassLoader()); 101 Class beanClass = Class.forName(descriptor.getEjbClassName(), 102 false, 103 getVerifierContext().getClassLoader()); 104 for (Method remoteMethod : intfClass.getMethods()) { 105 106 if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBObject")|| 108 remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBLocalObject")) 109 continue; 110 111 Class [] parameterTypes = remoteMethod.getParameterTypes(); 112 Method method =getMethod(beanClass,remoteMethod.getName(),parameterTypes); 113 if(method == null) 114 continue; 115 Class [] remoteExceptions = remoteMethod.getExceptionTypes(); 116 Class [] exceptions = method.getExceptionTypes(); 117 118 123 for (Class exception : exceptions) { 124 boolean foundOne = false; 125 for (Class remoteException : remoteExceptions) 126 if(remoteException.getName().equals(exception.getName())) { 127 foundOne = true; 128 break; 129 } 130 if(!foundOne) { 131 addWarningDetails(result, compName); 132 result.warning(smh.getLocalString 133 (getClass().getName() + ".warning", 134 "Not Compatible Exception: A public business " + 135 "method [ {0} ] was found, but according to " + 136 "the EJB specification, all the exceptions " + 137 "defined in the throws clause of the matching " + 138 "method of the session bean class must be " + 139 "defined in the throws clause of the method " + 140 "of the remote interface. Exception [ {1} ] " + 141 "is not defined in the bean's remote interface.", 142 new Object [] {method.getName(),exception.getName()})); 143 } 144 } } } catch (Exception e) { 147 Verifier.debug(e); 148 addErrorDetails(result, compName); 149 result.addErrorDetails(smh.getLocalString 150 (getClass().getName() + ".failed", 151 "Remote interface [ {0} ] or bean class [ {1} ] does " + 152 "not exist or is not loadable within bean [ {2} ].", 153 new Object [] {intf,descriptor.getEjbClassName(),descriptor.getName()})); 154 } } 157 } 158 159 | Popular Tags |