1 23 package com.sun.enterprise.tools.verifier.tests.ejb.session; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import java.util.logging.Level ; 27 28 import com.sun.enterprise.tools.verifier.tests.*; 29 import com.sun.enterprise.deployment.EjbDescriptor; 30 import com.sun.enterprise.deployment.EjbSessionDescriptor; 31 import com.sun.enterprise.tools.verifier.*; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 34 42 public class EjbClassImplementsComponentInterface extends EjbTest implements EjbCheck { 43 Result result = null; 44 ComponentNameConstructor compName = null; 45 57 public Result check(EjbDescriptor descriptor) { 58 result = getInitializedResult(); 59 compName = getVerifierContext().getComponentNameConstructor(); 60 if (descriptor instanceof EjbSessionDescriptor) { 61 if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName())) 62 commonToBothInterfaces(descriptor.getRemoteClassName(),(EjbSessionDescriptor)descriptor); 63 if(descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName())) 64 commonToBothInterfaces(descriptor.getLocalClassName(),(EjbSessionDescriptor)descriptor); 65 } 66 if(result.getStatus()!=Result.FAILED && result.getStatus()!=Result.WARNING) { 67 addGoodDetails(result, compName); 68 result.addGoodDetails(smh.getLocalString 69 (getClass().getName() + ".passed", 70 "Bean class does not implement the enterprise Bean's remote interface")); 71 } 72 return result; 73 } 74 75 private void commonToBothInterfaces(String component, EjbSessionDescriptor descriptor) { 76 try { 77 Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 78 Class rc = Class.forName(component, false, getVerifierContext().getClassLoader()); 79 do { 81 for (Class interfaces : c.getInterfaces()) { 82 logger.log(Level.FINE, getClass().getName() + ".debug1", 83 new Object [] {interfaces.getName()}); 84 if (interfaces.getName().equals(rc.getName())) { 85 addWarningDetails(result, compName); 87 result.warning(smh.getLocalString 88 (getClass().getName() + ".warning", 89 "Warning: [ {0} ] class implments the " + 90 "enterprise Bean's remote interface [ {1} ]. " + 91 "It is recommended that the enterprise bean class not" + 92 " implement the remote interface to prevent " + 93 "inadvertent passing of this as a method argument or result. ", 94 new Object [] {descriptor.getEjbClassName(),rc.getName()})); 95 break; 96 } 97 } 98 } while ((c=c.getSuperclass()) != null); 99 } catch (ClassNotFoundException e) { 100 Verifier.debug(e); 101 addErrorDetails(result, compName); 102 result.failed(smh.getLocalString 103 (getClass().getName() + ".failedException", 104 "Error: [ {0} ] class not found.", 105 new Object [] {descriptor.getEjbClassName()})); 106 } 107 } 108 } 109 | Popular Tags |