1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.ejbfindermethod; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import java.lang.reflect.*; 27 import java.util.*; 28 import com.sun.enterprise.deployment.EjbEntityDescriptor; 29 import com.sun.enterprise.deployment.EjbDescriptor; 30 import com.sun.enterprise.deployment.MethodDescriptor; 31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 32 import com.sun.enterprise.tools.verifier.*; 33 import java.lang.ClassLoader ; 34 import com.sun.enterprise.tools.verifier.tests.*; 35 36 50 public class EjbFinderMethodStatic extends EjbTest implements EjbCheck { 51 52 53 70 public Result check(EjbDescriptor descriptor) { 71 72 Result result = getInitializedResult(); 73 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 74 75 if (descriptor instanceof EjbEntityDescriptor) { 76 String persistence = 77 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 78 if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) { 79 80 boolean ejbFindMethodFound = false; 81 boolean isStatic = false; 82 boolean oneFailed = false; 83 int findMethodModifiers = 0; 84 int foundAtLeastOne = 0; 85 try { 86 Context context = getVerifierContext(); 88 ClassLoader jcl = context.getClassLoader(); 89 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 90 do { 92 Method [] ejbFinderMethods = EJBClass.getDeclaredMethods(); 93 94 for (int j = 0; j < ejbFinderMethods.length; ++j) { 95 isStatic = false; 96 ejbFindMethodFound = false; 97 98 if (ejbFinderMethods[j].getName().startsWith("ejbFind")) { 99 ejbFindMethodFound = true; 100 foundAtLeastOne++; 101 102 findMethodModifiers = ejbFinderMethods[j].getModifiers(); 104 if (Modifier.isStatic(findMethodModifiers)) { 105 isStatic = true; 106 } 107 108 if (ejbFindMethodFound && !isStatic) { 109 result.addGoodDetails(smh.getLocalString 110 ("tests.componentNameConstructor", 111 "For [ {0} ]", 112 new Object [] {compName.toString()})); 113 result.addGoodDetails(smh.getLocalString 114 (getClass().getName() + ".debug1", 115 "For EJB Class [ {0} ] Finder Method [ {1} ]", 116 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 117 result.addGoodDetails(smh.getLocalString 118 (getClass().getName() + ".passed", 119 "A non-static [ {0} ] method was found.", 120 new Object [] {ejbFinderMethods[j].getName()})); 121 } else if (ejbFindMethodFound && isStatic) { 122 oneFailed = true; 123 result.addErrorDetails(smh.getLocalString 124 ("tests.componentNameConstructor", 125 "For [ {0} ]", 126 new Object [] {compName.toString()})); 127 result.addErrorDetails(smh.getLocalString 128 (getClass().getName() + ".debug1", 129 "For EJB Class [ {0} ] Finder Method [ {1} ]", 130 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 131 result.addErrorDetails(smh.getLocalString 132 (getClass().getName() + ".failed", 133 "Error: A static [ {0} ] method was found, but [ {1} ] cannot be declared as static.", 134 new Object [] {ejbFinderMethods[j].getName(),ejbFinderMethods[j].getName()})); 135 } 136 } 137 } 138 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (foundAtLeastOne == 0)); 139 140 if (foundAtLeastOne == 0) { 141 result.addNaDetails(smh.getLocalString 142 ("tests.componentNameConstructor", 143 "For [ {0} ]", 144 new Object [] {compName.toString()})); 145 result.notApplicable(smh.getLocalString 146 (getClass().getName() + ".notApplicable1", 147 "[ {0} ] does not declare any ejbFind<METHOD>(...) methods.", 148 new Object [] {descriptor.getEjbClassName()})); 149 } 150 151 } catch (ClassNotFoundException e) { 152 Verifier.debug(e); 153 result.addErrorDetails(smh.getLocalString 154 ("tests.componentNameConstructor", 155 "For [ {0} ]", 156 new Object [] {compName.toString()})); 157 result.failed(smh.getLocalString 158 (getClass().getName() + ".failedException", 159 "Error: EJB Class [ {1} ] does not exist or is not loadable.", 160 new Object [] {descriptor.getEjbClassName()})); 161 oneFailed = true; 162 } 163 164 if (oneFailed) { 165 result.setStatus(result.FAILED); 166 } else if (foundAtLeastOne == 0) { 167 result.setStatus(result.NOT_APPLICABLE); 168 } else { 169 result.setStatus(result.PASSED); 170 } 171 172 return result; 173 174 } else { result.addNaDetails(smh.getLocalString 176 ("tests.componentNameConstructor", 177 "For [ {0} ]", 178 new Object [] {compName.toString()})); 179 result.notApplicable(smh.getLocalString 180 (getClass().getName() + ".notApplicable2", 181 "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", 182 new Object [] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistence})); 183 return result; 184 } 185 186 } else { 187 result.addNaDetails(smh.getLocalString 188 ("tests.componentNameConstructor", 189 "For [ {0} ]", 190 new Object [] {compName.toString()})); 191 result.notApplicable(smh.getLocalString 192 (getClass().getName() + ".notApplicable", 193 "[ {0} ] expected {1} bean, but called with {2} bean.", 194 new Object [] {getClass(),"Entity","Session"})); 195 return result; 196 } 197 } 198 } 199 | Popular Tags |