FileDocCategorySizeDatePackage
StatelessCreateReturn.javaAPI DocGlassfish v2 API7144Fri May 04 22:34:08 BST 2007com.sun.enterprise.tools.verifier.tests.ejb.session.stateless

StatelessCreateReturn

public class StatelessCreateReturn extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest implements com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck
Stateless session beans home interface create method return test. The home interface of a stateless session Bean must have a create method that takes no arguments, and returns the session Bean's remote interface.

Fields Summary
boolean
foundAtLeastOneCreate
com.sun.enterprise.tools.verifier.Result
result
com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor
compName
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.EjbDescriptor descriptor)
Stateless session beans home interface create method return test. The home interface of a stateless session Bean must have a create method that takes no arguments, and returns the session Bean's remote interface.

param
descriptor the Enterprise Java Bean deployment descriptor
return
Result the results for this assertion


                                                                 
        

        result = getInitializedResult();
        compName = getVerifierContext().getComponentNameConstructor();

        if (descriptor instanceof EjbSessionDescriptor) {
            String stateType = ((EjbSessionDescriptor)descriptor).getSessionType();
            if (EjbSessionDescriptor.STATELESS.equals(stateType)) {
                // RULE: Stateless session are only allowed to have create
                //       methods with no arguments, and returns the session Bean's
                //       remote interface. The home interface must not have any
                //       other create methods.
                if (descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName()) &&
                        descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName()) )
                    commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor.getHomeClassName(),(EjbSessionDescriptor)descriptor);

                if (descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())&&
                        descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName()))
                    commonToBothInterfaces(descriptor.getLocalClassName(),descriptor.getLocalHomeClassName() ,(EjbSessionDescriptor)descriptor);

                if(result.getStatus() != Result.FAILED) {
                    addGoodDetails(result, compName);
                    result.passed(smh.getLocalString
                            (getClass().getName() +".passed",
                                    "create method is properly defined in the remote/local home interface"));
                }
                return result;
            }
        }
        return result;
    
private voidcommonToBothInterfaces(java.lang.String remote, java.lang.String home, com.sun.enterprise.deployment.EjbSessionDescriptor descriptor)
This method is responsible for the logic of the test. It is called for both local and remote interfaces.

param
descriptor the Enterprise Java Bean deployment descriptor
param
home for the Home interface of the Ejb.
param
remote Remote/Local interface

        try {
            Class c = Class.forName(home, false, getVerifierContext().getClassLoader());
            for (Method methods : c.getDeclaredMethods()) {
                if (methods.getName().startsWith("create")) {
                    Class methodReturnType = methods.getReturnType();
                    if (!(methodReturnType.getName().equals(remote))) {
                        addErrorDetails(result, compName);
                        result.addErrorDetails(smh.getLocalString
                                (getClass().getName() + ".debug1",
                                        "For Home Interface [ {0} ] Method [ {1} ]",
                                        new Object[] {home,methods.getName()}));
                        result.addErrorDetails(smh.getLocalString
                                (getClass().getName() + ".failed",
                                        "Error: A Create method was found, but the " +
                                "return type [ {0} ] was not the Remote/Local interface" ,
                                        new Object[] {methodReturnType.getName()}));

                    }
                }
            }
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString
                    (getClass().getName() + ".failedException",
                            "Error: Home/Local Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]",
                            new Object[] {home, descriptor.getName()}));
        }