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