1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp; 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 java.lang.reflect.*; 29 import com.sun.enterprise.deployment.*; 30 import com.sun.enterprise.tools.verifier.*; 31 import java.util.*; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 34 41 public class CmpFieldsTransient extends EjbTest implements EjbCheck { 42 43 44 55 public Result check(EjbDescriptor descriptor) { 56 57 Result result = getInitializedResult(); 58 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 59 60 if (descriptor instanceof EjbEntityDescriptor) { 61 String persistence = 62 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 63 if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) { 64 65 if (EjbCMPEntityDescriptor.CMP_1_1 != ((EjbCMPEntityDescriptor) descriptor).getCMPVersion()) { 67 result.addNaDetails(smh.getLocalString 68 ("tests.componentNameConstructor", 69 "For [ {0} ]", 70 new Object [] {compName.toString()})); 71 result.notApplicable(smh.getLocalString 72 ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.notApplicable3", 73 "Test do not apply to this cmp-version of container managed persistence EJBs")); 74 return result; 75 } 76 boolean oneFailed = false; 77 boolean badField = false; 78 for (Iterator itr = 79 ((EjbCMPEntityDescriptor)descriptor).getPersistenceDescriptor().getCMPFields().iterator(); 80 itr.hasNext();) { 81 82 FieldDescriptor nextPersistentField = (FieldDescriptor)itr.next(); 83 badField = false; 84 boolean foundField = false; 85 86 Class c1 = null; 88 try { 89 Class c = Class.forName(((EjbEntityDescriptor)descriptor).getEjbClassName(), false, getVerifierContext().getClassLoader()); 90 do { 92 try { 93 c1 = c; 94 Field f = c.getDeclaredField(nextPersistentField.getName()); 95 96 foundField = true; 97 int modifiers = f.getModifiers(); 98 if (!Modifier.isTransient(modifiers)) { 99 continue; 100 } else { 101 if (!oneFailed) { 102 oneFailed = true; 103 } 104 badField = true; 105 } 106 107 if (badField) { 108 result.addErrorDetails(smh.getLocalString 109 ("tests.componentNameConstructor", 110 "For [ {0} ]", 111 new Object [] {compName.toString()})); 112 result.failed(smh.getLocalString 113 (getClass().getName() + ".failed", 114 "Error: Field [ {0} ] defined within entity bean class [ {1} ] is defined as transient. Container managed field must not be defined in the entity bean class as transient.", 115 new Object [] {nextPersistentField.getName(),c.getName()})); 116 } 117 } catch (NoSuchFieldException e) { 118 foundField = false; 119 } 120 } while (((c = c.getSuperclass()) != null) && (!foundField)); 121 if (!foundField) { 122 if (!oneFailed) { 123 oneFailed = true; 124 } 125 result.addErrorDetails(smh.getLocalString 126 ("tests.componentNameConstructor", 127 "For [ {0} ]", 128 new Object [] {compName.toString()})); 129 result.failed(smh.getLocalString 130 (getClass().getName() + ".failedException1", 131 "Error: [ {0} ] field not found within class [ {1} ]", 132 new Object [] {nextPersistentField.getName(),((EjbEntityDescriptor)descriptor).getEjbClassName()})); 133 } 134 135 } catch (ClassNotFoundException e) { 136 Verifier.debug(e); 137 if (!oneFailed) { 138 oneFailed = true; 139 } 140 result.addErrorDetails(smh.getLocalString 141 ("tests.componentNameConstructor", 142 "For [ {0} ]", 143 new Object [] {compName.toString()})); 144 result.failed(smh.getLocalString 145 (getClass().getName() + ".failedException", 146 "Error: [ {0} ] class not found.", 147 new Object [] {((EjbEntityDescriptor)descriptor).getEjbClassName()})); 148 } 149 if (!oneFailed) { 150 result.addGoodDetails(smh.getLocalString 151 ("tests.componentNameConstructor", 152 "For [ {0} ]", 153 new Object [] {compName.toString()})); 154 result.passed(smh.getLocalString 155 (getClass().getName() + ".passed", 156 "This entity bean class [ {0} ] has defined [ {1} ] container managed field as non-transient field.", 157 new Object [] {c1.getName(),nextPersistentField.getName()})); 158 } 159 } 160 if (oneFailed) { 161 result.setStatus(Result.FAILED); 162 } else { 163 result.setStatus(Result.PASSED); 164 } 165 return result; 166 167 } else { result.addNaDetails(smh.getLocalString 169 ("tests.componentNameConstructor", 170 "For [ {0} ]", 171 new Object [] {compName.toString()})); 172 result.notApplicable(smh.getLocalString 173 (getClass().getName() + ".notApplicable1", 174 "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", 175 new Object [] {EjbEntityDescriptor.CONTAINER_PERSISTENCE,descriptor.getName(),persistence})); 176 return result; 177 } 178 } else { 179 result.addNaDetails(smh.getLocalString 180 ("tests.componentNameConstructor", 181 "For [ {0} ]", 182 new Object [] {compName.toString()})); 183 result.notApplicable(smh.getLocalString 184 (getClass().getName() + ".notApplicable", 185 "{0} expected {1} bean, but called with {2}.", 186 new Object [] {getClass(),"Entity","Session"})); 187 return result; 188 } 189 } 190 } 191 | Popular Tags |