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

EjbMethodIntfElement

public class EjbMethodIntfElement extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest implements com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck
The method-intf element must be one of the following "Remote" or "Home" or "LocalHome" or "Local".

Fields Summary
Constructors Summary
Methods Summary
public Resultcheck(EjbDescriptor descriptor)
The method-intf element must be one of the following "Remote" or "Home" or "LocalHome" or "Local".

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


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


        // method-intf don't make sense for messagedriven bean
        if (descriptor instanceof EjbMessageBeanDescriptor) {   
	    result.addNaDetails(smh.getLocalString
				  ("tests.componentNameConstructor",
				   "For [ {0} ]",
				   new Object[] {compName.toString()}));         
            result.notApplicable(smh.getLocalString
                (getClass().getName() + ".notApplicable",
                "There are no <method-intf> elements within this bean [ {0} ]",
                new Object[] {descriptor.getName()}));
            return result;
        }
        
	// hack try/catch block around test, to exit gracefully instead of
	// crashing verifier on getMethodDescriptors() call, XML mods cause
	// java.lang.ClassNotFoundException: verifier.ejb.hello.BogusEJB
	// Replacing <ejb-class>verifier.ejb.hello.HelloEJB with
	//  <ejb-class>verifier.ejb.hello.BogusEJB...
	try  {

	    boolean na = false;
	    boolean na1 = false;
	    boolean oneFailed = false;
            if (!descriptor.getMethodContainerTransactions().isEmpty()) {
                for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) {
  
		    MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                    String methodIntf = null;
                    try {
                        methodIntf = methodDescriptor.getEjbClassSymbol();
                    } catch ( Exception ex ) {}
                    if ( methodIntf == null ) { //|| methodIntf.equals("") 
                        continue;
                    }
                    // The method-intf element must be one of the following
                    // Home Remote LocalHome Local ServiceEndpoint
                    if (!( (methodIntf.equals(MethodDescriptor.EJB_REMOTE)) ||
                        (methodIntf.equals(MethodDescriptor.EJB_HOME)) ||
                        (methodIntf.equals(MethodDescriptor.EJB_LOCALHOME)) || 
                        (methodIntf.equals(MethodDescriptor.EJB_LOCAL)) ||
                        (methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) ||
                        (methodIntf.length()==0))) {
                    // The method-intf element must be one of the following "Remote" or "Home"
//		    if (!((methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE))  ||
//			  (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) ||
//			  (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) || 
//			  (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) ||
//                          (methodDescriptor.getEjbClassSymbol().length()==0))) {
			oneFailed =true;
			result.addErrorDetails(smh.getLocalString
					       ("tests.componentNameConstructor",
						"For [ {0} ]",
						new Object[] {compName.toString()}));
			result.addErrorDetails
			    (smh.getLocalString
			     (getClass().getName() + ".failed",
			      "Error: Container transaction method [ {0} ] method-intf element [ {1} ] must be one of the following: [ {2} ] or [ {3} ] or [ {4} ] or [ {5} ]  within bean [ {6} ]",
			      new Object[] {methodDescriptor.getName(),methodDescriptor.getEjbClassSymbol(),
						MethodDescriptor.EJB_REMOTE.toString(), MethodDescriptor.EJB_HOME,
						MethodDescriptor.EJB_LOCAL, MethodDescriptor.EJB_LOCALHOME,
						descriptor.getName()}));
		    } else {
			result.addGoodDetails(smh.getLocalString
					      ("tests.componentNameConstructor",
					       "For [ {0} ]",
					       new Object[] {compName.toString()}));
			result.addGoodDetails
			    (smh.getLocalString
			     (getClass().getName() + ".passed",
			      "Container Transaction method [ {0} ] method-intf element [ {1} ] is one of the following:  [ {2} ] or [ {3} ] or [ {4} ] or [ {5} ]  within bean [ {6} ]",
			      new Object[] {methodDescriptor.getName(),methodDescriptor.getEjbClassSymbol(),
						MethodDescriptor.EJB_REMOTE, MethodDescriptor.EJB_HOME,
						MethodDescriptor.EJB_LOCAL, MethodDescriptor.EJB_LOCALHOME,
						descriptor.getName()}));
		    } 
		} 
	    } else {
                na = true;
	    } 

            Map permissionedMethods = descriptor.getPermissionedMethodsByPermission();
            if (permissionedMethods.size() >0) {
		for (Iterator e = permissionedMethods.keySet().iterator(); e.hasNext();) {            
		    MethodPermission nextPermission = (MethodPermission) e.next();
		    Set permissionedMethodsForRole = (HashSet) permissionedMethods.get(nextPermission);

		    if (permissionedMethodsForRole != null) {
			Set convertedPermissionedMethods = new HashSet();
			for (Iterator itr = permissionedMethodsForRole.iterator(); itr.hasNext();) {
			    MethodDescriptor methodDescriptor = (MethodDescriptor) itr.next();

                            String methodIntf = null;
                            try {
                                methodIntf = methodDescriptor.getEjbClassSymbol();
                            } catch ( Exception ex ) {}
                            if ( methodIntf == null  ) { //|| methodIntf.equals("")
                                continue;
                            }
                            // The method-intf element must be one of the following
                            // Home Remote LocalHome Local ServiceEndpoint
                            if (!( (methodIntf.equals(MethodDescriptor.EJB_REMOTE)) ||
                                (methodIntf.equals(MethodDescriptor.EJB_HOME)) ||
                                (methodIntf.equals(MethodDescriptor.EJB_LOCALHOME)) || 
                                (methodIntf.equals(MethodDescriptor.EJB_LOCAL)) ||
                                (methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) ||
                                (methodIntf.length()==0))) {
  
			    // The method-intf element must be one of the following "Remote" or "Home"
//			    if (!((methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE))  ||
//				  (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) || 
//                                (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) || 
//				  (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) || 
//                                  (methodDescriptor.getEjbClassSymbol().length()==0))) {

				oneFailed =true;
				result.addErrorDetails(smh.getLocalString
						       ("tests.componentNameConstructor",
							"For [ {0} ]",
							new Object[] {compName.toString()}));
				result.addErrorDetails
				    (smh.getLocalString
				     (getClass().getName() + ".failed1",
				      "Error: Method permissions method [ {0} ] method-intf element [ {1} ] must be one of the interfaces of the bean [ {2} ]",
				      new Object[] {methodDescriptor.getName(),
							methodDescriptor.getEjbClassSymbol(), 
							descriptor.getName()}));
			    } else {
				result.addGoodDetails(smh.getLocalString
						      ("tests.componentNameConstructor",
						       "For [ {0} ]",
						       new Object[] {compName.toString()}));
				result.addGoodDetails
				    (smh.getLocalString
				     (getClass().getName() + ".passed1",
				      "Method permissions method [ {0} ] method-intf element [ {1} ] is one of the interfaces of the  bean [ {2} ]",
				      new Object[] {methodDescriptor.getName(),methodDescriptor.getEjbClassSymbol(), descriptor.getName()}));
			    } 
			} 
		    } 
		} 
	    } else {
                na1 = true;
	    } 


	    if (oneFailed) {
		result.setStatus(Result.FAILED);
	    } else if (na && na1) {
		result.addNaDetails(smh.getLocalString
				    ("tests.componentNameConstructor",
				     "For [ {0} ]",
				     new Object[] {compName.toString()}));
		result.notApplicable(smh.getLocalString
				     (getClass().getName() + ".notApplicable",
				      "There are no <method-intf> elements within this bean [ {0} ]",
				      new Object[] {descriptor.getName()}));
	    } else {
		result.setStatus(Result.PASSED);
	    }
	    return result;
	} catch (Throwable t) {
	    result.addErrorDetails(smh.getLocalString
				   ("tests.componentNameConstructor",
				    "For [ {0} ]",
				    new Object[] {compName.toString()}));
	    result.failed(smh.getLocalString
			  (getClass().getName() + ".failedException",
			   "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]",
			   new Object[] {descriptor.getName(), t.getMessage(), descriptor.getName()}));
	    return result;
	}