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 HomeMethodRmiIIOPReturn 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 addNaDetails(result, compName); 71 result.notApplicable(smh.getLocalString 72 (getClass().getName() + ".notApplicable1", 73 " [ {0} ] does not have a remote home interface. ", 74 new Object [] {descriptor.getEjbClassName()})); 75 return result; 76 } 77 ClassLoader jcl = getVerifierContext().getClassLoader(); 78 Class rc = Class.forName(descriptor.getHomeClassName(), false, jcl); 79 80 Class methodReturnType; 81 boolean homeMethodFound = false; 82 boolean isLegalRMIIIOPReturn = false; 83 for (Method remoteMethod : rc.getMethods()) { 84 85 if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBHome")) 87 continue; 88 if (remoteMethod.getName().startsWith("create") || 89 remoteMethod.getName().startsWith("find") || 90 remoteMethod.getName().startsWith("remove")) 91 continue; 92 93 Class c = Class.forName(descriptor.getEjbClassName(), false, jcl); 95 do { 97 98 for (Method method : c.getDeclaredMethods()) { 99 100 homeMethodFound = false; 102 isLegalRMIIIOPReturn = false; 103 String methodName = "ejbHome" + Character.toUpperCase(remoteMethod.getName().charAt(0)) + remoteMethod.getName().substring(1); 104 if (method.getName().equals(methodName)) { 105 foundAtLeastOne++; 106 homeMethodFound = true; 107 methodReturnType = method.getReturnType(); 111 if (RmiIIOPUtils.isValidRmiIIOPReturnType(methodReturnType)) { 112 isLegalRMIIIOPReturn = true; 114 } 116 if (homeMethodFound && isLegalRMIIIOPReturn ) { 119 addGoodDetails(result, compName); 120 result.addGoodDetails(smh.getLocalString 121 (getClass().getName() + ".passed", 122 "[ {0} ] properly declares ejbHome<METHOD> method [ {1} ] with valid RMI-IIOP return type.", 123 new Object [] {descriptor.getEjbClassName(),method.getName()})); 124 } else if (homeMethodFound && !isLegalRMIIIOPReturn) { 125 oneFailed = true; 126 addErrorDetails(result, compName); 127 result.addErrorDetails(smh.getLocalString 128 (getClass().getName() + ".failed", 129 "Error: ejbHome<METHOD> method [ {0} ] was found, but ejbHome<METHOD> method has illegal return value. ejbHome<METHOD> methods return type must be legal types for RMI-IIOP.", 130 new Object [] {method.getName()})); 131 } 132 } 133 } 134 if (oneFailed == true) 135 break; 136 } while (((c = c.getSuperclass()) != null) && (!homeMethodFound)); 137 } 138 if (foundAtLeastOne == 0) { 139 addNaDetails(result, compName); 140 result.notApplicable(smh.getLocalString 141 (getClass().getName() + ".notApplicable1", 142 " [ {0} ] does not declare any ejbHome<METHOD> methods. ", 143 new Object [] {descriptor.getEjbClassName()})); 144 } 145 } catch (ClassNotFoundException e) { 146 Verifier.debug(e); 147 oneFailed = true; 148 addErrorDetails(result, compName); 149 result.failed(smh.getLocalString 150 (getClass().getName() + ".failedException", 151 "Error: Remote interface [ {0} ] or bean class [ {1} ] does not exist or is not loadable within bean [ {2} ].", 152 new Object [] {descriptor.getRemoteClassName(),descriptor.getEjbClassName(),descriptor.getName()})); 153 } 154 155 if (oneFailed) { 156 result.setStatus(Result.FAILED); 157 } else if (foundAtLeastOne == 0) { 158 result.setStatus(Result.NOT_APPLICABLE); 159 } else { 160 result.setStatus(Result.PASSED); 161 } 162 163 return result; 164 165 } else { 166 addNaDetails(result, compName); 167 result.notApplicable(smh.getLocalString 168 (getClass().getName() + ".notApplicable", 169 "{0} expected {1} bean or {2} bean, but called with {3}.", 170 new Object [] {getClass(),"Session","Entity",descriptor.getName()})); 171 return result; 172 } 173 } 174 } 175 | Popular Tags |