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 import java.util.Arrays ; 29 30 import com.sun.enterprise.deployment.*; 31 import com.sun.enterprise.tools.verifier.*; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 import com.sun.enterprise.tools.verifier.tests.*; 34 35 42 public class BusinessMethodFinal extends EjbTest implements EjbCheck { 43 Result result = null; 44 ComponentNameConstructor compName = null; 45 46 56 public Result check(EjbDescriptor descriptor) { 57 58 result = getInitializedResult(); 59 compName = getVerifierContext().getComponentNameConstructor(); 60 61 if ((descriptor instanceof EjbSessionDescriptor) || 62 (descriptor instanceof EjbEntityDescriptor)) { 63 64 if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName())) 65 commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor); 66 67 if(descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName())) 68 commonToBothInterfaces(descriptor.getLocalClassName(),descriptor); 69 70 Set <String > localAndRemoteInterfaces = descriptor.getLocalBusinessClassNames(); 71 localAndRemoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames()); 72 73 for (String localOrRemoteIntf : localAndRemoteInterfaces) 74 commonToBothInterfaces(localOrRemoteIntf, descriptor); 75 } 76 if(result.getStatus() != Result.FAILED) { 77 addGoodDetails(result, compName); 78 result.passed(smh.getLocalString 79 (getClass().getName() + ".passed", 80 "Proper declaration of business method(s) found.")); 81 } 82 return result; 83 } 84 85 92 93 private void commonToBothInterfaces(String intf,EjbDescriptor descriptor) { 94 try { 95 Class intfClass = Class.forName(intf, 96 false, 97 getVerifierContext().getClassLoader()); 98 99 for (Method remoteMethod : intfClass.getMethods()) { 100 101 if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBObject")|| 103 remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBLocalObject") || 104 remoteMethod.getDeclaringClass().getName().equals("java.lang.Object")) 105 continue; 106 107 Class beanClass = Class.forName(descriptor.getEjbClassName(), 108 false, 109 getVerifierContext().getClassLoader()); 110 for (Method method : beanClass.getMethods()) { 111 112 if (method.getName().equals(remoteMethod.getName())) { 113 Class parms[] = method.getParameterTypes(); 114 Class remoteParams[] = remoteMethod.getParameterTypes(); 115 116 if (Arrays.equals(parms, remoteParams) && 117 Modifier.isFinal(method.getModifiers())) { 118 addErrorDetails(result, compName); 119 result.failed(smh.getLocalString 120 (getClass().getName() + ".failed", 121 "Error: final business method [ {0} ] was " + 122 "found, but business method cannot be declared as final.", 123 new Object [] {method.getName()})); 124 } 125 } 126 } 127 } 128 } catch (ClassNotFoundException e) { 129 Verifier.debug(e); 130 addErrorDetails(result, compName); 131 result.failed(smh.getLocalString 132 (getClass().getName() + ".failedException", 133 "Error: Remote interface [ {0} ] or bean class [ {1} ] " + 134 "does not exist or is not loadable within bean [ {2} ].", 135 new Object [] {intf,descriptor.getEjbClassName(),descriptor.getName()})); 136 } 137 } 138 } 139 | Popular Tags |