1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.ejbfindbyprimarykey; 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 45 public class EjbFindByPrimaryKeyStatic extends EjbTest implements EjbCheck { 46 47 48 60 public Result check(EjbDescriptor descriptor) { 61 62 Result result = getInitializedResult(); 63 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 64 65 if (descriptor instanceof EjbEntityDescriptor) { 66 String persistentType = 67 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 68 if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistentType)) { 69 70 boolean ejbFindByPrimaryKeyMethodFound = false; 71 boolean isStatic = false; 72 boolean oneFailed = false; 73 int findMethodModifiers = 0; 74 try { 75 Context context = getVerifierContext(); 77 ClassLoader jcl = context.getClassLoader(); 78 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 79 do { 81 Method [] ejbFinderMethods = EJBClass.getDeclaredMethods(); 82 83 for (int j = 0; j < ejbFinderMethods.length; ++j) { 84 if (ejbFinderMethods[j].getName().equals("ejbFindByPrimaryKey")) { 85 ejbFindByPrimaryKeyMethodFound = true; 88 89 findMethodModifiers = ejbFinderMethods[j].getModifiers(); 91 if (Modifier.isStatic(findMethodModifiers)) { 92 isStatic = true; 93 } 94 95 if (ejbFindByPrimaryKeyMethodFound && !isStatic) { 96 result.addGoodDetails(smh.getLocalString 97 ("tests.componentNameConstructor", 98 "For [ {0} ]", 99 new Object [] {compName.toString()})); 100 result.addGoodDetails(smh.getLocalString 101 (getClass().getName() + ".debug1", 102 "For EJB Class [ {0} ] Finder Method [ {1} ]", 103 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 104 result.addGoodDetails(smh.getLocalString 105 (getClass().getName() + ".passed", 106 "A non-static [ {0} ] method was found.", 107 new Object [] {ejbFinderMethods[j].getName()})); 108 } else if (ejbFindByPrimaryKeyMethodFound && isStatic) { 109 oneFailed = true; 110 result.addErrorDetails(smh.getLocalString 111 ("tests.componentNameConstructor", 112 "For [ {0} ]", 113 new Object [] {compName.toString()})); 114 result.addErrorDetails(smh.getLocalString 115 (getClass().getName() + ".debug1", 116 "For EJB Class [ {0} ] Finder Method [ {1} ]", 117 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 118 result.addErrorDetails(smh.getLocalString 119 (getClass().getName() + ".failed", 120 "Error: A static [ {0} ] method was found, but [ {1} ] cannot be declared as static.", 121 new Object [] {ejbFinderMethods[j].getName(),ejbFinderMethods[j].getName()})); 122 } 123 break; 125 } 126 } 127 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!ejbFindByPrimaryKeyMethodFound)); 128 129 if (!ejbFindByPrimaryKeyMethodFound) { 130 oneFailed = true; 131 result.addErrorDetails(smh.getLocalString 132 ("tests.componentNameConstructor", 133 "For [ {0} ]", 134 new Object [] {compName.toString()})); 135 result.addErrorDetails(smh.getLocalString 136 (getClass().getName() + ".debug3", 137 "For EJB Class [ {0} ]", 138 new Object [] {descriptor.getEjbClassName()})); 139 result.addErrorDetails(smh.getLocalString 140 (getClass().getName() + ".failed1", 141 "Error: No ejbFindByPrimaryKey method was found in bean class.")); 142 } 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: EJB Class [ {0} ] does not exist or is not loadable.", 153 new Object [] {descriptor.getEjbClassName()})); 154 oneFailed = true; 155 } 156 157 if (oneFailed) { 158 result.setStatus(result.FAILED); 159 } else { 160 result.setStatus(result.PASSED); 161 } 162 163 } else { result.addNaDetails(smh.getLocalString 165 ("tests.componentNameConstructor", 166 "For [ {0} ]", 167 new Object [] {compName.toString()})); 168 result.notApplicable(smh.getLocalString 169 (getClass().getName() + ".notApplicable2", 170 "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]", 171 new Object [] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistentType})); 172 } 173 return result; 174 175 } else { 176 result.addNaDetails(smh.getLocalString 177 ("tests.componentNameConstructor", 178 "For [ {0} ]", 179 new Object [] {compName.toString()})); 180 result.notApplicable(smh.getLocalString 181 (getClass().getName() + ".notApplicable", 182 "[ {0} ] expected {1} bean, but called with {2} bean.", 183 new Object [] {getClass(),"Entity","Session"})); 184 return result; 185 } 186 } 187 } 188 | Popular Tags |