1 23 package com.sun.enterprise.tools.verifier.tests.ejb.homeintf; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import java.lang.ClassLoader ; 27 import java.lang.reflect.Method ; 28 29 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 30 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils; 31 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 32 import com.sun.enterprise.tools.verifier.Result; 33 import com.sun.enterprise.tools.verifier.Verifier; 34 import com.sun.enterprise.deployment.EjbDescriptor; 35 import com.sun.enterprise.deployment.EjbSessionDescriptor; 36 import com.sun.enterprise.deployment.EjbEntityDescriptor; 37 38 45 public class HomeMethodRmiIIOPArgs extends EjbTest implements EjbCheck { 46 47 48 49 59 public Result check(EjbDescriptor descriptor) { 60 61 Result result = getInitializedResult(); 62 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 63 64 if ((descriptor instanceof EjbSessionDescriptor) || 65 (descriptor instanceof EjbEntityDescriptor)) { 66 boolean oneFailed = false; 67 int foundAtLeastOne = 0; 68 try { 69 if(descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) { 70 result.addNaDetails(smh.getLocalString 71 ("tests.componentNameConstructor", 72 "For [ {0} ]", 73 new Object [] {compName.toString()})); 74 result.notApplicable(smh.getLocalString 75 (getClass().getName() + ".notApplicable1", 76 " [ {0} ] does not have a remote home interface. ", 77 new Object [] {descriptor.getEjbClassName()})); 78 return result; 79 } 80 81 ClassLoader jcl = getVerifierContext().getClassLoader(); 82 Class rc = Class.forName(descriptor.getHomeClassName(), false, jcl); 83 84 Class [] homeMethodParameterTypes; 85 boolean homeMethodFound = false; 86 boolean isLegalRMIIIOP = false; 87 88 for (Method remoteMethod : rc.getMethods()) { 89 90 if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBHome")) 92 continue; 93 if (remoteMethod.getName().startsWith("create") || 94 remoteMethod.getName().startsWith("find") || 95 remoteMethod.getName().startsWith("remove")) 96 continue; 97 98 Class c = Class.forName(descriptor.getEjbClassName(), false, jcl); 100 do { 102 103 for (Method method : c.getDeclaredMethods()) { 104 isLegalRMIIIOP = false; 105 homeMethodFound = false; 106 107 String methodName = "ejbHome" + Character.toUpperCase(remoteMethod.getName().charAt(0)) + remoteMethod.getName().substring(1); 108 109 if (method.getName().equals(methodName)) { 110 foundAtLeastOne++; 111 homeMethodFound = true; 112 113 homeMethodParameterTypes = method.getParameterTypes(); 115 if (RmiIIOPUtils.isValidRmiIIOPParameters(homeMethodParameterTypes)) { 116 isLegalRMIIIOP = true; 118 } 119 120 if (homeMethodFound && isLegalRMIIIOP ) { 123 addGoodDetails(result, compName); 124 result.addGoodDetails(smh.getLocalString 125 (getClass().getName() + ".passed", 126 "[ {0} ] properly declares ejbHome<Method> method " + 127 "[ {1} ] with valid RMI-IIOP parameter types.", 128 new Object [] {descriptor.getEjbClassName(),method.getName()})); 129 } else if (homeMethodFound && !isLegalRMIIIOP) { 130 oneFailed = true; 131 addErrorDetails(result, compName); 132 result.addErrorDetails(smh.getLocalString 133 (getClass().getName() + ".failed", 134 "Error: ejbHome<Method> method [ {0} ] was found, " + 135 "but ejbHome<Method> method has illegal parameter " + 136 "values. ejbHome<Method> methods arguments types " + 137 "must be legal types for RMI-IIOP.", 138 new Object [] {method.getName()})); 139 break; 140 } 141 } 142 } 143 if (oneFailed == true) 144 break; 145 } while (((c = c.getSuperclass()) != null) && (!homeMethodFound)); 146 } 147 if (foundAtLeastOne == 0) { 148 addNaDetails(result, compName); 149 result.notApplicable(smh.getLocalString 150 (getClass().getName() + ".notApplicable1", 151 " [ {0} ] does not declare any ejbHome<Method> methods. ", 152 new Object [] {descriptor.getEjbClassName()})); 153 } 154 } catch (ClassNotFoundException e) { 155 Verifier.debug(e); 156 oneFailed = true; 157 addErrorDetails(result, compName); 158 result.failed(smh.getLocalString 159 (getClass().getName() + ".failedException", 160 "Error: Remote interface [ {0} ] or bean class [ {1} ] does not " + 161 "exist or is not loadable within bean [ {2} ].", 162 new Object [] {descriptor.getRemoteClassName(),descriptor.getEjbClassName(),descriptor.getName()})); 163 } 164 165 if (oneFailed) { 166 result.setStatus(Result.FAILED); 167 } else if (foundAtLeastOne == 0) { 168 result.setStatus(Result.NOT_APPLICABLE); 169 } else { 170 result.setStatus(Result.PASSED); 171 } 172 173 return result; 174 175 } else { 176 addNaDetails(result, compName); 177 result.notApplicable(smh.getLocalString 178 (getClass().getName() + ".notApplicable", 179 "{0} expected {1} bean or {2} bean, but called with {3}.", 180 new Object [] {getClass(),"Session","Entity",descriptor.getName()})); 181 return result; 182 } 183 } 184 } 185 | Popular Tags |