1 23 package com.sun.enterprise.tools.verifier.tests.ejb; 24 25 import java.util.logging.Level ; 26 27 import com.sun.enterprise.deployment.EjbDescriptor; 28 import com.sun.enterprise.deployment.EjbEntityDescriptor; 29 import com.sun.enterprise.deployment.EjbSessionDescriptor; 30 import com.sun.enterprise.tools.verifier.Result; 31 import com.sun.enterprise.tools.verifier.Verifier; 32 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 33 34 39 public class EjbBeanType 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 EjbSessionDescriptor) || 57 (descriptor instanceof EjbEntityDescriptor)) { 58 59 try { 60 Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 61 boolean validBean = false; 62 do { 64 Class [] interfaces = c.getInterfaces(); 65 for (int i = 0; i < interfaces.length; i++) { 66 logger.log(Level.FINE, getClass().getName() + ".debug1", 67 new Object [] {interfaces[i].getName()}); 68 69 if (interfaces[i].getName().equals("javax.ejb.EntityBean") && 70 (descriptor instanceof EjbEntityDescriptor)) { 71 validBean = true; 72 result.addGoodDetails(smh.getLocalString 73 ("tests.componentNameConstructor", 74 "For [ {0} ]", 75 new Object [] {compName.toString()})); 76 result.passed(smh.getLocalString 77 (getClass().getName() + ".passed", 78 "[ {0} ] properly implements the {1}Bean interface.", 79 new Object [] {descriptor.getEjbClassName(),"Entity"})); 80 break; 81 } else if (interfaces[i].getName().equals("javax.ejb.SessionBean") && 82 descriptor instanceof EjbSessionDescriptor) { 83 validBean = true; 84 result.addGoodDetails(smh.getLocalString 85 ("tests.componentNameConstructor", 86 "For [ {0} ]", 87 new Object [] {compName.toString()})); 88 result.passed(smh.getLocalString 89 (getClass().getName() + ".passed", 90 "[ {0} ] properly implements the {1}Bean interface.", 91 new Object [] {descriptor.getEjbClassName(),"Session"})); 92 break; 93 } 94 } 95 } while ((((c=c.getSuperclass()) != null) && (!validBean))); 96 97 98 if (!validBean){ 99 result.addErrorDetails(smh.getLocalString 100 ("tests.componentNameConstructor", 101 "For [ {0} ]", 102 new Object [] {compName.toString()})); 103 result.failed(smh.getLocalString 104 (getClass().getName() + ".failed", 105 "Error: [ {0} ] is not a valid bean. The bean provider must use the appropriate {1} or {2} element to declare the bean type.", 106 new Object [] {descriptor.getEjbClassName(),"session","entity"})); 107 } 108 } catch (ClassNotFoundException e) { 109 Verifier.debug(e); 110 result.addErrorDetails(smh.getLocalString 111 ("tests.componentNameConstructor", 112 "For [ {0} ]", 113 new Object [] {compName.toString()})); 114 result.failed(smh.getLocalString 115 (getClass().getName() + ".failedException", 116 "Error: [ {0} ] class not found.", 117 new Object [] {descriptor.getEjbClassName()})); 118 } 119 return result; 120 121 } else { 122 result.addNaDetails(smh.getLocalString 123 ("tests.componentNameConstructor", 124 "For [ {0} ]", 125 new Object [] {compName.toString()})); 126 result.notApplicable(smh.getLocalString 127 (getClass().getName() + ".notApplicable", 128 "[ {0} ] not called with a Session or Entity Bean.", 129 new Object [] {getClass()})); 130 return result; 131 } 132 } 133 } 134 | Popular Tags |