1 23 24 29 30 package com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp; 31 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 33 import java.lang.reflect.*; 34 import com.sun.enterprise.deployment.*; 35 import com.sun.enterprise.tools.verifier.Result; 36 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 37 44 public class CmpEjbNoInvalidCreateMethod extends EjbTest implements EjbCheck { 45 46 47 54 public Result check(EjbDescriptor descriptor) { 55 56 Result result = getInitializedResult(); 57 try { 58 59 if (descriptor instanceof EjbCMPEntityDescriptor) { 60 String persistence = 61 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 62 if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence) && 63 ((EjbCMPEntityDescriptor)descriptor).getCMPVersion()==EjbCMPEntityDescriptor.CMP_1_1) { 64 65 try { 66 Class c = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader()); 67 Method [] methods = c.getDeclaredMethods(); 68 boolean oneFailed = false; 69 for (int i=0;i<methods.length;i++) { 70 Method aMethod = methods[i]; 71 if (aMethod.getName().startsWith("create")) { 72 if (!aMethod.getName().endsWith("create")) { 73 result.addErrorDetails(smh.getLocalString 74 (getClass().getName() + ".failed", 75 "CMP 1.1 entity beans are not authorized to define [ {0} ] method", 76 new Object [] {aMethod.getName()})); 77 oneFailed = true; 78 } 79 } 80 } 81 if (oneFailed) { 82 result.setStatus(Result.FAILED); 83 } else { 84 result.passed(smh.getLocalString 85 (getClass().getName() + ".passed", 86 "No create<METHOD> defined for this CMP 1.1 entity bean [ {0} ] ", 87 new Object [] {descriptor.getName()})); 88 } 89 return result; 90 } catch(ClassNotFoundException cnfe) { 91 result.failed(smh.getLocalString 92 (getClass().getName() + ".failedException", 93 "Error: [ {0} ] class not found.", 94 new Object [] {descriptor.getHomeClassName()})); 95 return result; 96 } 97 } 98 } 99 } catch(Exception e) { 100 e.printStackTrace(); 101 } 102 result.notApplicable(smh.getLocalString 103 (getClass().getName() + ".notApplicable", 104 "[ {0} ] is not a CMP 1.1 Entity Bean.", 105 new Object [] {descriptor.getName()})); 106 return result; 107 } 108 } 109 | Popular Tags |