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 39 public class PrimaryKeyClassConstructor extends EjbTest implements EjbCheck { 40 41 42 51 public Result check(EjbDescriptor descriptor) { 52 53 Result result = getInitializedResult(); 54 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 55 56 if (descriptor instanceof EjbEntityDescriptor) { 57 String persistence = 58 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 59 if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) { 60 try { 63 FieldDescriptor fd = ((EjbCMPEntityDescriptor)descriptor).getPrimaryKeyFieldDesc(); 64 if (fd != null) { 65 String pkf = fd.getName(); 66 if (pkf.length() > 0) { 67 result.addNaDetails(smh.getLocalString 69 ("tests.componentNameConstructor", 70 "For [ {0} ]", 71 new Object [] {compName.toString()})); 72 result.notApplicable(smh.getLocalString 73 (getClass().getName() + ".notApplicable2", 74 "Entity Bean [ {0} ] with primekey-field non-blank, test not applicable.", 75 new Object [] {descriptor.getEjbClassName()})); 76 } 77 } else { 78 try { 79 Context context = getVerifierContext(); 80 ClassLoader jcl = context.getClassLoader(); 81 Class c = Class.forName(((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader()); 82 83 boolean foundOne = false; 84 Constructor [] constructors = c.getConstructors(); 85 for (int i = 0; i < constructors.length; i++) { 86 int modifiers = constructors[i].getModifiers(); 87 if (Modifier.isPublic(modifiers)) { 88 Class [] constructorParameterTypes; 89 constructorParameterTypes = constructors[i].getParameterTypes(); 90 if (constructorParameterTypes.length > 0) { 91 continue; 92 } else { 93 foundOne = true; 94 break; 95 } 96 } 97 } 98 99 if (foundOne) { 100 result.addGoodDetails(smh.getLocalString 101 ("tests.componentNameConstructor", 102 "For [ {0} ]", 103 new Object [] {compName.toString()})); 104 result.passed(smh.getLocalString 105 (getClass().getName() + ".passed", 106 "This primary key class [ {0} ] has a public constructor method with no parameters.", 107 new Object [] {((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName()})); 108 } else { 109 result.addErrorDetails(smh.getLocalString 110 ("tests.componentNameConstructor", 111 "For [ {0} ]", 112 new Object [] {compName.toString()})); 113 result.failed(smh.getLocalString 114 (getClass().getName() + ".failed", 115 "Error: A public constructor method with no parameters was not found in the primary key class [ {0} ].", 116 new Object [] {((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName()})); 117 } 118 } catch (ClassNotFoundException e) { 119 Verifier.debug(e); 120 result.addErrorDetails(smh.getLocalString 121 ("tests.componentNameConstructor", 122 "For [ {0} ]", 123 new Object [] {compName.toString()})); 124 result.failed(smh.getLocalString 125 (getClass().getName() + ".failedException", 126 "Error: [ {0} ] class not found.", 127 new Object [] {((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName()})); 128 } 129 } 130 } catch (NullPointerException e) { 131 result.addErrorDetails(smh.getLocalString 132 ("tests.componentNameConstructor", 133 "For [ {0} ]", 134 new Object [] {compName.toString()})); 135 result.failed(smh.getLocalString 136 (getClass().getName() + ".failedException2", 137 "Error: Primkey field not defined within [ {0} ] bean.", 138 new Object [] {descriptor.getName()})); 139 } 140 return result; 141 142 } else { result.addNaDetails(smh.getLocalString 144 ("tests.componentNameConstructor", 145 "For [ {0} ]", 146 new Object [] {compName.toString()})); 147 result.notApplicable(smh.getLocalString 148 (getClass().getName() + ".notApplicable1", 149 "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", 150 new Object [] {EjbEntityDescriptor.CONTAINER_PERSISTENCE,descriptor.getName(),persistence})); 151 return result; 152 } 153 154 } else { 155 result.addNaDetails(smh.getLocalString 156 ("tests.componentNameConstructor", 157 "For [ {0} ]", 158 new Object [] {compName.toString()})); 159 result.notApplicable(smh.getLocalString 160 (getClass().getName() + ".notApplicable", 161 "{0} expected {1} bean, but called with {2}.", 162 new Object [] {getClass(),"Entity","Session"})); 163 return result; 164 } 165 } 166 } 167 | Popular Tags |