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 EjbFindByPrimaryKeyFinal 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 boolean ejbFindByPrimaryKeyMethodFound = false; 70 boolean isFinal = false; 71 boolean oneFailed = false; 72 int findMethodModifiers = 0; 73 try { 74 Context context = getVerifierContext(); 76 ClassLoader jcl = context.getClassLoader(); 77 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 78 do { 80 Method [] ejbFinderMethods = EJBClass.getDeclaredMethods(); 81 82 for (int j = 0; j < ejbFinderMethods.length; ++j) { 83 if (ejbFinderMethods[j].getName().equals("ejbFindByPrimaryKey")) { 84 ejbFindByPrimaryKeyMethodFound = true; 87 88 findMethodModifiers = ejbFinderMethods[j].getModifiers(); 90 if (Modifier.isFinal(findMethodModifiers)) { 91 isFinal = true; 92 } 93 94 if (ejbFindByPrimaryKeyMethodFound && !isFinal) { 95 result.addGoodDetails(smh.getLocalString 96 ("tests.componentNameConstructor", 97 "For [ {0} ]", 98 new Object [] {compName.toString()})); 99 result.addGoodDetails(smh.getLocalString 100 (getClass().getName() + ".debug1", 101 "For EJB Class [ {0} ] Finder method [ {1} ]", 102 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 103 result.addGoodDetails(smh.getLocalString 104 (getClass().getName() + ".passed", 105 "A non-final [ {0} ] method was found.", 106 new Object [] {ejbFinderMethods[j].getName()})); 107 } else if (ejbFindByPrimaryKeyMethodFound && isFinal) { 108 oneFailed = true; 109 result.addErrorDetails(smh.getLocalString 110 ("tests.componentNameConstructor", 111 "For [ {0} ]", 112 new Object [] {compName.toString()})); 113 result.addErrorDetails(smh.getLocalString 114 (getClass().getName() + ".debug1", 115 "For EJB Class [ {0} ] Finder method [ {1} ]", 116 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 117 result.addErrorDetails(smh.getLocalString 118 (getClass().getName() + ".failed", 119 "Error: A final [ {0} ] method was found, but [ {1} ] cannot be declared as final.", 120 new Object [] {ejbFinderMethods[j].getName(),ejbFinderMethods[j].getName()})); 121 } 122 break; 124 } 125 } 126 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!ejbFindByPrimaryKeyMethodFound)); 127 128 if (!ejbFindByPrimaryKeyMethodFound) { 129 oneFailed = true; 130 result.addErrorDetails(smh.getLocalString 131 ("tests.componentNameConstructor", 132 "For [ {0} ]", 133 new Object [] {compName.toString()})); 134 result.addErrorDetails(smh.getLocalString 135 (getClass().getName() + ".debug3", 136 "For EJB Class [ {0} ]", 137 new Object [] {descriptor.getEjbClassName()})); 138 result.addErrorDetails(smh.getLocalString 139 (getClass().getName() + ".failed1", 140 "Error: No ejbFindByPrimaryKey method was found in bean class.")); 141 } 142 143 } catch (ClassNotFoundException e) { 144 Verifier.debug(e); 145 result.addErrorDetails(smh.getLocalString 146 ("tests.componentNameConstructor", 147 "For [ {0} ]", 148 new Object [] {compName.toString()})); 149 result.failed(smh.getLocalString 150 (getClass().getName() + ".failedException", 151 "Error: EJB Class [ {0} ] does not exist or is not loadable.", 152 new Object [] {descriptor.getEjbClassName()})); 153 oneFailed = true; 154 } 155 156 if (oneFailed) { 157 result.setStatus(result.FAILED); 158 } else { 159 result.setStatus(result.PASSED); 160 } 161 162 } else { result.addNaDetails(smh.getLocalString 164 ("tests.componentNameConstructor", 165 "For [ {0} ]", 166 new Object [] {compName.toString()})); 167 result.notApplicable(smh.getLocalString 168 (getClass().getName() + ".notApplicable2", 169 "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]", 170 new Object [] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistentType})); 171 } 172 return result; 173 174 } else { 175 result.addNaDetails(smh.getLocalString 176 ("tests.componentNameConstructor", 177 "For [ {0} ]", 178 new Object [] {compName.toString()})); 179 result.notApplicable(smh.getLocalString 180 (getClass().getName() + ".notApplicable", 181 "[ {0} ] expected {1} bean, but called with {2} bean.", 182 new Object [] {getClass(),"Entity","Session"})); 183 return result; 184 } 185 } 186 } 187 | Popular Tags |