FileDocCategorySizeDatePackage
ApplicationExceptionComponentInterfaceMethods.javaAPI DocGlassfish v2 API7098Fri May 04 22:33:32 BST 2007com.sun.enterprise.tools.verifier.tests.ejb

ApplicationExceptionComponentInterfaceMethods

public class ApplicationExceptionComponentInterfaceMethods extends EjbTest implements EjbCheck
The Bean Provider defines the application exceptions in the throws clauses of the methods of the remote interface. An application exception is an exception defined in the throws clause of a method in the Bean's remote interface, other than java.rmi.RemoteException. An application exception must not be defined as a subclass of the java.lang.RuntimeException, or of the java.rmi.RemoteException. These are reserved for system exceptions. The javax.ejb.CreateException, javax.ejb.RemoveException, javax.ejb.FinderException, and subclasses thereof, are considered to be application exceptions.

Fields Summary
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)
The Bean Provider defines the application exceptions in the throws clauses of the methods of the remote interface. An application exception is an exception defined in the throws clause of a method in the Bean's remote interface, other than java.rmi.RemoteException. An application exception must not be defined as a subclass of the java.lang.RuntimeException, or of the java.rmi.RemoteException. These are reserved for system exceptions. The javax.ejb.CreateException, javax.ejb.RemoveException, javax.ejb.FinderException, and subclasses thereof, are considered to be application exceptions.

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

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

        if ((descriptor instanceof EjbSessionDescriptor) ||
                (descriptor instanceof EjbEntityDescriptor)) {

            if(descriptor.getRemoteClassName() != null)
                commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor);
            if(descriptor.getLocalClassName() != null)
                commonToBothInterfaces(descriptor.getLocalClassName(),descriptor);
            //EJB 3.0 business interface requirements
            Set<String> localAndRemoteInterfaces = descriptor.getLocalBusinessClassNames();
            localAndRemoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames());

            for (String localOrRemoteIntf : localAndRemoteInterfaces)
                commonToBothInterfaces(localOrRemoteIntf, descriptor);
        }
        if(result.getStatus() != Result.FAILED) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString
                    (getClass().getName() + ".passed",
                            "All the business methods are defined properly"));
        }
        return result;
    
private voidcommonToBothInterfaces(java.lang.String remote, com.sun.enterprise.deployment.EjbDescriptor 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
remote or remote for the Remote/Local interface of the Ejb. This parameter may be optional depending on the test

        try {
            Class c = Class.forName(remote, false, getVerifierContext().getClassLoader());
            Class [] methodExceptionTypes;
            for(Method methods : c.getDeclaredMethods()) {
                methodExceptionTypes = methods.getExceptionTypes();
                // methods must also throw java.rmi.RemoteException
                if (!(EjbUtils.isValidApplicationException(methodExceptionTypes))) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString
                            (getClass().getName() + ".failed",
                            "For the Interface [ {0} ] Method [ {1} ] does not throw " +
                            "valid application exceptions",
                                    new Object[] {remote, methods.getName()}));

                }
            } // for all the methods within the Remote interface class, loop

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