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 com.sun.enterprise.deployment.*; 28 import com.sun.enterprise.tools.verifier.*; 29 import com.sun.enterprise.tools.verifier.tests.ejb.*; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 import java.util.*; 32 33 42 public class BusinessMethodMatchesWithDD extends EjbTest implements EjbCheck { 43 44 Result result = null; 45 ComponentNameConstructor compName = null; 46 47 58 public Result check(EjbDescriptor descriptor) { 59 60 result = getInitializedResult(); 61 compName = getVerifierContext().getComponentNameConstructor(); 62 63 if ((descriptor instanceof EjbSessionDescriptor) || 64 (descriptor instanceof EjbEntityDescriptor)) { 65 66 if(descriptor.getRemoteClassName() != null && 67 !"".equals(descriptor.getRemoteClassName())) 68 commonToBothInterfaces(descriptor.getRemoteClassName(), 69 descriptor, 70 MethodDescriptor.EJB_REMOTE); 71 72 if(descriptor.getLocalClassName() != null && 73 !"".equals(descriptor.getLocalClassName())) 74 commonToBothInterfaces(descriptor.getLocalClassName(), 75 descriptor, 76 MethodDescriptor.EJB_LOCAL); 77 } 78 79 if(result.getStatus() != Result.FAILED) { 80 addGoodDetails(result, compName); 81 result.passed(smh.getLocalString 82 (getClass().getName() + ".passed", 83 "Business method(s) are valid.")); 84 } 85 return result; 86 } 87 88 96 97 private void commonToBothInterfaces(String intf, 98 EjbDescriptor descriptor, 99 String methodIntf) { 100 try { 101 Class intfClass = Class.forName(intf, false, getVerifierContext().getClassLoader()); 102 103 boolean found = false; 104 Set allMethods = new HashSet(); 105 106 for (Iterator e = 107 descriptor.getPermissionedMethodsByPermission().values().iterator();e.hasNext();) { 108 Set methodDescriptors = (Set) e.next(); 109 if (methodDescriptors != null) 110 allMethods.addAll(methodDescriptors); 111 } 112 for (Enumeration e = 113 descriptor.getMethodContainerTransactions().keys();e.hasMoreElements();) { 114 allMethods.add(e.nextElement()); 115 } 116 117 for (Method remoteMethod : intfClass.getMethods()) { 118 found = false; 119 120 if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBObject")) 122 continue; 123 if (!remoteMethod.getName().startsWith("ejb") && 124 !remoteMethod.getName().equals("class$") && 125 !remoteMethod.getName().equals("setSessionContext")) { 126 127 Iterator methods = allMethods.iterator(); 128 while (methods.hasNext()) { 129 MethodDescriptor methodDescriptor = (MethodDescriptor)methods.next(); 130 131 if (methodDescriptor.getName().equals(remoteMethod.getName())) { 132 if (MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), 133 (new MethodDescriptor(remoteMethod,methodIntf)).getParameterClassNames())) { 134 found = true; 135 break; 136 } 137 } 138 } 139 } 140 if (!found) { 141 addErrorDetails(result, compName); 142 result.failed(smh.getLocalString 143 (getClass().getName() + ".failed", 144 "Error: Business method [ {0} ] is not defined " + 145 "in the deployment descriptor.", 146 new Object [] {remoteMethod.getName()})); 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: Component interface [ {0} ] does not exist " + 156 "or is not loadable within bean [ {1} ].", 157 new Object [] {intf,descriptor.getName()})); 158 } 159 } 160 } 161 | Popular Tags |