FileDocCategorySizeDatePackage
MethodsExist.javaAPI DocGlassfish v2 API10139Fri May 04 22:33:36 BST 2007com.sun.enterprise.tools.verifier.tests.ejb.elements

MethodsExist

public abstract class MethodsExist extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest
Base class for all the MethodsExist tests. ContainerTransactionMethodExists, ExcludeListMethodsExist, MethodPermissionMethodExists and UncheckedMethodsExist.
author
Vikas Awasthi

Fields Summary
protected com.sun.enterprise.tools.verifier.Result
result
protected com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor
compName
private List
methods
Constructors Summary
Methods Summary
protected voidcheckMethodStyles(com.sun.enterprise.deployment.MethodDescriptor methodDescriptor, com.sun.enterprise.deployment.EjbDescriptor descriptor)
test for method styles 1, 2 or 3

    
              
        
                                       

        if (methodDescriptor.getName().equals(MethodDescriptor.ALL_EJB_METHODS)) 
            return; //style 1
        
        if (methodDescriptor.getParameterClassNames() == null) //style 2
            checkStyle(methodDescriptor, descriptor, true);
        else  // style 3
            checkStyle(methodDescriptor, descriptor, false);
    
private voidcheckStyle(com.sun.enterprise.deployment.MethodDescriptor methodDescriptor, com.sun.enterprise.deployment.EjbDescriptor descriptor, boolean isCheckStyle2)

        
        String methodName = methodDescriptor.getName();
            
        if (methodDescriptor.getEjbClassSymbol() != null) { // method intf present

            if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) {
                // if method-intf is Remote then add EJB3.0 remote business interfaces 
                Set<String> interfaces= new HashSet<String>(descriptor.getRemoteBusinessClassNames());
                if(descriptor.getRemoteClassName()!=null)
                    interfaces.add(descriptor.getRemoteClassName());
                
                if(!contains(methodDescriptor, getAllMethods(interfaces), isCheckStyle2)) 
                    logFailure(methodName, "remote");
                
            } else if(methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) {
                // if method-intf is Local then add EJB3.0 local business interfaces 
                Set<String> interfaces= new HashSet<String>(descriptor.getLocalBusinessClassNames());
                if(descriptor.getLocalClassName()!=null)
                    interfaces.add(descriptor.getLocalClassName());
                
                if(!contains(methodDescriptor, getAllMethods(interfaces), isCheckStyle2)) 
                    logFailure(methodName, "local");
                
            } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) {
                
                if(!contains(methodDescriptor, getAllMethods(descriptor.getHomeClassName()), isCheckStyle2)) 
                    logFailure(methodName, "home");
                
            } else if(methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) {
                
                if(!contains(methodDescriptor, getAllMethods(descriptor.getLocalHomeClassName()), isCheckStyle2)) 
                    logFailure(methodName, "localhome");
                
            } else if(methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_WEB_SERVICE)) {

                String endpointIntfName = descriptor.getWebServiceEndpointInterfaceName();
                if(!contains(methodDescriptor, getAllMethods(endpointIntfName), isCheckStyle2)) 
                    logFailure(methodName, "localhome");
                
            }
            // for ejbTimeout method of TimedObject the methodDescriptor.getEjbClassSymbol()
            // is always EJB_BEAN. So no need to check that as this test is not 
            // applicable for this method.
        } else { // method intf not present
            if(!contains(methodDescriptor, getAllMethods(descriptor), true)) 
                logFailure(methodDescriptor.getName(), "any of component or home");
        }
    
private booleancontains(com.sun.enterprise.deployment.MethodDescriptor method1, java.util.List methods, boolean isStyle2)
checks if method1 is present in the given list of methods. For style 2 methods only method names are compared and for style 3 method parameters are also compared.

        for (Method method : methods) {
            if(isStyle2) {// for style 2 do only name comparison
                if(method.getName().equals(method1.getName()))
                    return true;
            } else if (method.getName().equals(method1.getName()) &&
                    Arrays.equals(new MethodDescriptor().getParameterClassNamesFor(method),
                            method1.getParameterClassNames()))
                return true;
        }
        return false;
    
private java.util.ListgetAllMethods(com.sun.enterprise.deployment.EjbDescriptor descriptor)
It returns a list of all the methods in component and home interfaces of this ejbDescriptor.

        if(methods!=null)
            return methods;
        
        methods = new ArrayList<Method>();
        Set<String> interfaces = descriptor.getLocalBusinessClassNames();
        
        interfaces.addAll(descriptor.getRemoteBusinessClassNames());
        if(descriptor.getRemoteClassName()!=null)
            interfaces.add(descriptor.getRemoteClassName());
        if(descriptor.getLocalClassName()!=null)
            interfaces.add(descriptor.getLocalClassName());
        if(descriptor.getHomeClassName()!=null)
            interfaces.add(descriptor.getHomeClassName());
        if(descriptor.getLocalHomeClassName()!=null)
            interfaces.add(descriptor.getLocalHomeClassName());
        if(descriptor.getWebServiceEndpointInterfaceName()!=null)
            interfaces.add(descriptor.getWebServiceEndpointInterfaceName());
        
        for (String intf : interfaces) {
            Class intfClass = loadClass(intf);
            if(intfClass==null)//ignore if null. Error message is already logged
                continue;
            methods.addAll(Arrays.asList(intfClass.getMethods()));
        }
        return methods;
    
private java.util.ListgetAllMethods(java.lang.String intf)
It returns a list of all the methods in the given interface intf

        Class intfClass = loadClass(intf);
        return (intfClass==null)? new ArrayList<Method>():Arrays.asList(intfClass.getMethods());
    
private java.util.ListgetAllMethods(java.util.Set interfaces)
It returns a list of all the methods in the given interfaces

        List<Method> methods = new ArrayList<Method>();
        for (String intf : interfaces) {
            Class intfClass = loadClass(intf);
            if(intfClass==null) 
                continue;
            methods.addAll(Arrays.asList(intfClass.getMethods()));
        }
        return methods;
    
private java.lang.ClassloadClass(java.lang.String className)

        Class intfClass = null;
        try {
            intfClass = Class.forName(className, 
                                      false, 
                                      getVerifierContext().getClassLoader());
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString
                    (getClass().getName() + ".failedException",
                    "Error: Interface class not found. [ {0} ]",
                    new Object[] {className}));
        }
        return intfClass;
    
private voidlogFailure(java.lang.String msg1, java.lang.String msg2)

        addErrorDetails(result, compName);
        result.failed(smh.getLocalString
                (getClass().getName() + ".failed",
                "Error: Method name [ {0} ] not defined in {1} interface.",
                new Object[] {msg1, msg2}));