1 23 package com.sun.enterprise.tools.verifier.tests.ejb.elements; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 27 import com.sun.enterprise.tools.verifier.Result; 28 import com.sun.enterprise.tools.verifier.Verifier; 29 import com.sun.enterprise.deployment.MethodDescriptor; 30 import com.sun.enterprise.deployment.EjbDescriptor; 31 32 import java.lang.reflect.Method ; 33 import java.util.*; 34 35 42 public abstract class MethodsExist extends EjbTest { 43 44 protected Result result = null; 45 protected ComponentNameConstructor compName = null; 46 private List<Method > methods = null; 47 48 49 protected void checkMethodStyles(MethodDescriptor methodDescriptor, 50 EjbDescriptor descriptor) { 51 52 if (methodDescriptor.getName().equals(MethodDescriptor.ALL_EJB_METHODS)) 53 return; 55 if (methodDescriptor.getParameterClassNames() == null) checkStyle(methodDescriptor, descriptor, true); 57 else checkStyle(methodDescriptor, descriptor, false); 59 } 60 61 private void checkStyle(MethodDescriptor methodDescriptor, 62 EjbDescriptor descriptor, 63 boolean isCheckStyle2) { 64 65 String methodName = methodDescriptor.getName(); 66 67 if (methodDescriptor.getEjbClassSymbol() != null) { 69 if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) { 70 Set<String > interfaces= new HashSet<String >(descriptor.getRemoteBusinessClassNames()); 72 if(descriptor.getRemoteClassName()!=null) 73 interfaces.add(descriptor.getRemoteClassName()); 74 75 if(!contains(methodDescriptor, getAllMethods(interfaces), isCheckStyle2)) 76 logFailure(methodName, "remote"); 77 78 } else if(methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) { 79 Set<String > interfaces= new HashSet<String >(descriptor.getLocalBusinessClassNames()); 81 if(descriptor.getLocalClassName()!=null) 82 interfaces.add(descriptor.getLocalClassName()); 83 84 if(!contains(methodDescriptor, getAllMethods(interfaces), isCheckStyle2)) 85 logFailure(methodName, "local"); 86 87 } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) { 88 89 if(!contains(methodDescriptor, getAllMethods(descriptor.getHomeClassName()), isCheckStyle2)) 90 logFailure(methodName, "home"); 91 92 } else if(methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) { 93 94 if(!contains(methodDescriptor, getAllMethods(descriptor.getLocalHomeClassName()), isCheckStyle2)) 95 logFailure(methodName, "localhome"); 96 97 } else if(methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_WEB_SERVICE)) { 98 99 String endpointIntfName = descriptor.getWebServiceEndpointInterfaceName(); 100 if(!contains(methodDescriptor, getAllMethods(endpointIntfName), isCheckStyle2)) 101 logFailure(methodName, "localhome"); 102 103 } 104 } else { if(!contains(methodDescriptor, getAllMethods(descriptor), true)) 109 logFailure(methodDescriptor.getName(), "any of component or home"); 110 } 111 } 112 113 118 private boolean contains(MethodDescriptor method1, List<Method > methods, boolean isStyle2) { 119 for (Method method : methods) { 120 if(isStyle2) { if(method.getName().equals(method1.getName())) 122 return true; 123 } else if (method.getName().equals(method1.getName()) && 124 Arrays.equals(new MethodDescriptor().getParameterClassNamesFor(method), 125 method1.getParameterClassNames())) 126 return true; 127 } 128 return false; 129 } 130 131 135 private List<Method > getAllMethods(EjbDescriptor descriptor) { 136 if(methods!=null) 137 return methods; 138 139 methods = new ArrayList<Method >(); 140 Set<String > interfaces = descriptor.getLocalBusinessClassNames(); 141 142 interfaces.addAll(descriptor.getRemoteBusinessClassNames()); 143 if(descriptor.getRemoteClassName()!=null) 144 interfaces.add(descriptor.getRemoteClassName()); 145 if(descriptor.getLocalClassName()!=null) 146 interfaces.add(descriptor.getLocalClassName()); 147 if(descriptor.getHomeClassName()!=null) 148 interfaces.add(descriptor.getHomeClassName()); 149 if(descriptor.getLocalHomeClassName()!=null) 150 interfaces.add(descriptor.getLocalHomeClassName()); 151 if(descriptor.getWebServiceEndpointInterfaceName()!=null) 152 interfaces.add(descriptor.getWebServiceEndpointInterfaceName()); 153 154 for (String intf : interfaces) { 155 Class intfClass = loadClass(intf); 156 if(intfClass==null) continue; 158 methods.addAll(Arrays.asList(intfClass.getMethods())); 159 } 160 return methods; 161 } 162 163 164 private List<Method > getAllMethods(String intf) { 165 Class intfClass = loadClass(intf); 166 return (intfClass==null)? new ArrayList<Method >():Arrays.asList(intfClass.getMethods()); 167 } 168 169 170 private List<Method > getAllMethods(Set<String > interfaces) { 171 List<Method > methods = new ArrayList<Method >(); 172 for (String intf : interfaces) { 173 Class intfClass = loadClass(intf); 174 if(intfClass==null) 175 continue; 176 methods.addAll(Arrays.asList(intfClass.getMethods())); 177 } 178 return methods; 179 } 180 181 private Class loadClass(String className) { 182 Class intfClass = null; 183 try { 184 intfClass = Class.forName(className, 185 false, 186 getVerifierContext().getClassLoader()); 187 } catch (ClassNotFoundException e) { 188 Verifier.debug(e); 189 addErrorDetails(result, compName); 190 result.failed(smh.getLocalString 191 (getClass().getName() + ".failedException", 192 "Error: Interface class not found. [ {0} ]", 193 new Object [] {className})); 194 } 195 return intfClass; 196 } 197 198 private void logFailure(String msg1, String msg2) { 199 addErrorDetails(result, compName); 200 result.failed(smh.getLocalString 201 (getClass().getName() + ".failed", 202 "Error: Method name [ {0} ] not defined in {1} interface.", 203 new Object [] {msg1, msg2})); 204 } 205 206 } 207 | Popular Tags |