FileDocCategorySizeDatePackage
WebReferencesInWEBINF.javaAPI DocGlassfish v2 API8927Fri May 04 22:34:14 BST 2007com.sun.enterprise.tools.verifier.tests.web.elements

WebReferencesInWEBINF

public class WebReferencesInWEBINF extends com.sun.enterprise.tools.verifier.tests.web.WebTest implements com.sun.enterprise.tools.verifier.tests.web.WebCheck
The Bean Provider must declare all enterprise bean's references to the homes of other enterprise beans as specified in section 14.3.2 of the Moscone spec. Check for one within the same jar file, can't check outside of jar file. Load/locate & check other bean's home/remote/bean, ensure they match with what the linking bean says they should be; check for pair of referencing and referenced beans exist.

Fields Summary
Result
result
ComponentNameConstructor
compName
EjbReferenceDescriptor
ejbReference
Iterator
iterator
Constructors Summary
Methods Summary
public Resultcheck(WebBundleDescriptor descriptor)
The referenced Ejb bean/home/component interfaces should exist inside the WEB-INF/classes dir or the WEB-INF/lib/*.jar. These classes should be loadable by the war file's class loader.

param
descriptor the Web deployment descriptor
return
Result the results for this assertion

  
                                                 
        

        result = getInitializedResult();
	boolean oneFailed = false;
	compName = getVerifierContext().getComponentNameConstructor();

	if (descriptor instanceof WebBundleDescriptor) {

	    /*  
		The referenced Ejb home/component interfaces should exist inside the WEB-INF/classes dir 
		or the WEB-INF/lib/*.jar. These classes should be loadable by the war file's class loader.
	    */
   	   
	    String f = descriptor.getModuleDescriptor().getArchiveUri();
	    Set references = descriptor.getEjbReferenceDescriptors();
	    iterator = references.iterator();
	    result = loadWarFile(descriptor);

	    try {
		if (iterator.hasNext()) {
		    while (iterator.hasNext()) {
			ejbReference = (EjbReferenceDescriptor) iterator.next();
			if (ejbReference.isLinked()) { // instanceof EjbDescriptor) {
			    oneFailed = findEjbRef(f);
			} else {
			    // (e.g. external references)
			    result.addGoodDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
			    result.addGoodDetails(smh.getLocalString
						  (getClass().getName() + ".notApplicable2",
						   "Not Applicable: [ {0} ] must be external reference to bean outside of [ {1} ].",
						   new Object[] {ejbReference.getName(),f}));
			}
		    }
		}
		else {
		    result.addNaDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
		    result.notApplicable(smh.getLocalString
					 (getClass().getName() + ".notApplicable",
					  "Not Applicable: No EJB references found in [ {0} ]",
					  new Object[] {f}));
		    return result;
		}
	    } catch (Exception e) {
		result.addErrorDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
		result.failed(smh.getLocalString
			      (getClass().getName() + ".IOException", 
			       "I/O error trying to open {0}", new Object[] {f}));
	    } finally {
		try {
		} catch (Exception x) {}
	    }
	    if (oneFailed) {
		result.setStatus(Result.FAILED);
	    } else {
		result.setStatus(Result.PASSED);
	    }
	} else {
	    result.addNaDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
	    result.notApplicable(smh.getLocalString
				 (getClass().getName() + ".notApplicable1",
				  "There are no ejb references to other beans within this web archive [ {0} ]",
				  new Object[] {descriptor.getName()}));
	}
	
	return result;
    
private booleancommon(java.lang.String intf, java.lang.String f)

	Class cl = loadClass(result, intf);
	if (cl != null) {
	    result.addGoodDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));	
	    result.passed(smh.getLocalString
			  (getClass().getName() + ".passed",
			   "The referenced beans home/component [ {0} ] interface exists and is loadable within [ {1} ].",
			   new Object[] {intf,f}));
	    return false;
	} 
	else return true;
    
private booleanfindEjbRef(java.lang.String f)

	
	boolean oneFailed = false;
	
	try {
	  if(ejbReference.getEjbHomeInterface() != null && 
	       !"".equals(ejbReference.getEjbHomeInterface()) &&
	       ejbReference.getEjbInterface() != null && 
	       !"".equals(ejbReference.getEjbInterface())) {
		oneFailed = common(ejbReference.getEjbHomeInterface(),f);
		    if (oneFailed == true) {
			result.addErrorDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
			result.failed(smh.getLocalString
				      (getClass().getName() + ".failed",
				       "Error: The [ {0} ] interface of the referenced EJB [ {1} ] is not packaged inside the WEB-INF directory of the war file.",
				       new Object[] {ejbReference.getEjbHomeInterface(),ejbReference.getName()}));
			return true;
		    }
		    
		    oneFailed = common(ejbReference.getEjbInterface(),f);
		    if (oneFailed == true) {
			result.addErrorDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
			result.failed(smh.getLocalString
				      (getClass().getName() + ".failed",
				       "Error: The [ {0} ] interface of the referenced EJB [ {1} ] is not packaged inside the WEB-INF directory of the war file",
				       new Object[] {ejbReference.getEjbInterface(),ejbReference.getName()}));
			return true;
		    }
	    } 
	    return oneFailed;
	} catch (NoClassDefFoundError e) {
	    result.addErrorDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
	    result.failed(smh.getLocalString
			  (getClass().getName() + ".failed1",
			   "Error: Bean class [ {0} ] does not exist or is not loadable:NoClassDefFoundError.",
			   new Object[] {ejbReference.getName()}));
	    oneFailed = true;
	    return oneFailed;
	} catch (Exception e) {
	    Verifier.debug(e);
	    result.addErrorDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
	    result.failed(smh.getLocalString
			  (getClass().getName() + ".failed1",
			   "Error: Bean class [ {0} ] does not exist or is not loadable:ClassNotFoundException",
			   new Object[] {ejbReference.getName()}));
	    oneFailed = true;
	    return oneFailed;
	}