1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.ejbcreatemethod; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import java.lang.ClassLoader ; 27 import com.sun.enterprise.tools.verifier.tests.*; 28 import javax.ejb.EntityBean ; 29 import java.lang.reflect.*; 30 import com.sun.enterprise.deployment.*; 31 import com.sun.enterprise.tools.verifier.*; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 34 45 public class EjbCreateMethodStatic extends EjbTest implements EjbCheck { 46 47 48 62 public Result check(EjbDescriptor descriptor) { 63 64 Result result = getInitializedResult(); 65 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 66 67 if (descriptor instanceof EjbEntityDescriptor) { 68 boolean oneFailed = false; 69 int foundAtLeastOne = 0; 70 try { 71 Context context = getVerifierContext(); 72 ClassLoader jcl = context.getClassLoader(); 73 Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 74 75 boolean ejbCreateFound = false; 76 boolean isStatic = false; 77 do { 79 Method [] methods = c.getDeclaredMethods(); 80 for (int i = 0; i < methods.length; i++) { 81 ejbCreateFound = false; 83 isStatic = false; 84 85 if (methods[i].getName().startsWith("ejbCreate")) { 87 foundAtLeastOne++; 88 ejbCreateFound = true; 89 90 int modifiers = methods[i].getModifiers(); 92 if (Modifier.isStatic(modifiers)){ 93 isStatic = true; 94 } 95 96 if (ejbCreateFound && isStatic) { 99 oneFailed = true; 100 result.addErrorDetails(smh.getLocalString 101 ("tests.componentNameConstructor", 102 "For [ {0} ]", 103 new Object [] {compName.toString()})); 104 result.addErrorDetails(smh.getLocalString 105 (getClass().getName() + ".debug1", 106 "For EJB Class [ {0} ] method [ {1} ]", 107 new Object [] {descriptor.getEjbClassName(),methods[i].getName()})); 108 result.addErrorDetails(smh.getLocalString 109 (getClass().getName() + ".failed", 110 "Error: A static [ {0} ] method was found, but [ {1} ] cannot be declared as static.", 111 new Object [] {methods[i].getName(),methods[i].getName()})); 112 break; 113 } 114 } 115 } 116 if (oneFailed == true) 117 break; 118 } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0)); 119 120 if (foundAtLeastOne == 0) { 121 result.addNaDetails(smh.getLocalString 122 ("tests.componentNameConstructor", 123 "For [ {0} ]", 124 new Object [] {compName.toString()})); 125 result.notApplicable(smh.getLocalString 126 (getClass().getName() + ".notApplicable1", 127 "[ {0} ] does not declare any ejbCreate(...) methods.", 128 new Object [] {descriptor.getEjbClassName()})); 129 } 130 if (oneFailed == false && foundAtLeastOne > 0) { 131 result.addGoodDetails(smh.getLocalString 132 ("tests.componentNameConstructor", 133 "For [ {0} ]", 134 new Object [] {compName.toString()})); 135 result.addGoodDetails(smh.getLocalString 136 (getClass().getName() + ".debug1", 137 "For EJB Class [ {0} ]", 138 new Object [] {descriptor.getEjbClassName()})); 139 result.addGoodDetails(smh.getLocalString 140 (getClass().getName() + ".passed", 141 "[ {0} ] properly declares non-static ejbCreate<method> method.", 142 new Object [] {descriptor.getEjbClassName()})); 143 } 144 } catch (ClassNotFoundException e) { 145 Verifier.debug(e); 146 result.addErrorDetails(smh.getLocalString 147 ("tests.componentNameConstructor", 148 "For [ {0} ]", 149 new Object [] {compName.toString()})); 150 result.failed(smh.getLocalString 151 (getClass().getName() + ".failedException", 152 "Error: [ {0} ] class not found.", 153 new Object [] {descriptor.getEjbClassName()})); 154 oneFailed = true; 155 } 156 157 if (oneFailed) { 158 result.setStatus(result.FAILED); 159 } else if (foundAtLeastOne == 0) { 160 result.setStatus(result.NOT_APPLICABLE); 161 } else { 162 result.setStatus(result.PASSED); 163 } 164 165 return result; 166 167 } else { 168 result.addNaDetails(smh.getLocalString 169 ("tests.componentNameConstructor", 170 "For [ {0} ]", 171 new Object [] {compName.toString()})); 172 result.notApplicable(smh.getLocalString 173 (getClass().getName() + ".notApplicable", 174 "[ {0} ] expected {1} bean, but called with {2} bean.", 175 new Object [] {getClass(),"Entity","Session"})); 176 return result; 177 } 178 } 179 } 180 | Popular Tags |