1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.pkmultiplefield; 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 javax.ejb.EntityBean ; 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 38 public class PrimaryKeyClassModifier extends EjbTest implements EjbCheck { 39 40 41 49 public Result check(EjbDescriptor descriptor) { 50 51 Result result = getInitializedResult(); 52 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 53 54 if (descriptor instanceof EjbEntityDescriptor) { 55 String persistence = 56 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 57 if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) { 58 try { 61 FieldDescriptor fd = ((EjbCMPEntityDescriptor)descriptor).getPrimaryKeyFieldDesc(); 62 if (fd != null) { 63 String pkf = fd.getName(); 64 if (pkf.length() > 0) { 65 result.addNaDetails(smh.getLocalString 67 ("tests.componentNameConstructor", 68 "For [ {0} ]", 69 new Object [] {compName.toString()})); 70 result.notApplicable(smh.getLocalString 71 (getClass().getName() + ".notApplicable2", 72 "Entity Bean [ {0} ] with primekey-field non-blank, test not applicable.", 73 new Object [] {descriptor.getEjbClassName()})); 74 } 75 } else { 76 try { 77 Context context = getVerifierContext(); 78 ClassLoader jcl = context.getClassLoader(); 79 Class c = Class.forName(((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader()); 80 81 boolean isPublic = false; 82 int modifiers = c.getModifiers(); 83 if (Modifier.isPublic(modifiers)) { 84 isPublic = true; 85 } 86 87 if (isPublic) { 88 result.addGoodDetails(smh.getLocalString 89 ("tests.componentNameConstructor", 90 "For [ {0} ]", 91 new Object [] {compName.toString()})); 92 result.passed(smh.getLocalString 93 (getClass().getName() + ".passed", 94 "[ {0} ] properly declares public class modifier.", 95 new Object [] {((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName()})); 96 } else if (!isPublic) { 97 result.addErrorDetails(smh.getLocalString 98 ("tests.componentNameConstructor", 99 "For [ {0} ]", 100 new Object [] {compName.toString()})); 101 result.failed(smh.getLocalString 102 (getClass().getName() + ".failed", 103 "Error: Ejb primary key class [ {0} ] was found, but was not declared as public. The primary key class [ {1} ] must be defined as public.", 104 new Object [] {((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName(),((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName()})); 105 } 106 } catch (ClassNotFoundException e) { 107 Verifier.debug(e); 108 result.addErrorDetails(smh.getLocalString 109 ("tests.componentNameConstructor", 110 "For [ {0} ]", 111 new Object [] {compName.toString()})); 112 result.failed(smh.getLocalString 113 (getClass().getName() + ".failedException", 114 "Error: [ {0} ] class not found.", 115 new Object [] {((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName()})); 116 } 117 } 118 } catch (NullPointerException e) { 119 result.addErrorDetails(smh.getLocalString 120 ("tests.componentNameConstructor", 121 "For [ {0} ]", 122 new Object [] {compName.toString()})); 123 result.failed(smh.getLocalString 124 (getClass().getName() + ".failedException2", 125 "Error: Primkey field not defined within [ {0} ] bean.", 126 new Object [] {descriptor.getName()})); 127 } 128 return result; 129 130 } else { 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 "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", 138 new Object [] {EjbEntityDescriptor.CONTAINER_PERSISTENCE,descriptor.getName(),persistence})); 139 return result; 140 } 141 142 } else { 143 result.addNaDetails(smh.getLocalString 144 ("tests.componentNameConstructor", 145 "For [ {0} ]", 146 new Object [] {compName.toString()})); 147 result.notApplicable(smh.getLocalString 148 (getClass().getName() + ".notApplicable", 149 "{0} expected {1} bean, but called with {2}.", 150 new Object [] {getClass(),"Entity","Session"})); 151 return result; 152 } 153 } 154 } 155 | Popular Tags |