FileDocCategorySizeDatePackage
CmrFields.javaAPI DocGlassfish v2 API5766Fri May 04 22:33:40 BST 2007com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2

CmrFields

public class CmrFields extends CmrFieldTest
Container managed relationship type field must be : a reference to a local interface of a entity bean a collection interface for oneToMany or manyToMany relationships
author
Jerome Dochez
author
Sheetal Vartak
version

Fields Summary
Constructors Summary
Methods Summary
private booleanisValidInterface(java.lang.Class fieldType, java.util.Set entities)

        String component = "";
        if (entities==null)
            return false;
	// only local interface can be a valid interface
        Iterator iterator = entities.iterator();
        while (iterator.hasNext()) {
            EjbAbstractDescriptor entity = (EjbAbstractDescriptor) iterator.next();
	    if (fieldType.getName().equals(entity.getLocalClassName()))
		return true;
	}
        return false;
    
protected booleanrunIndividualCmrTest(Descriptor descriptor, RelationRoleDescriptor role, java.lang.Class c, com.sun.enterprise.tools.verifier.Result result)
run an individual verifier test of a declated cmr field of the class

param
entity the descriptor for the entity bean containing the cmp-field
param
info the descriptor for the declared cmr field
param
c the class owning the cmp field
parma
r the result object to use to put the test results in
return
true if the test passed

     
	boolean foundIt = false;
	CMRFieldInfo info = null;
	ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();

	try { 
	    info  = role.getCMRFieldInfo();
        }catch (Exception e) {
        addErrorDetails(result, compName);
	    result.addErrorDetails(smh.getLocalString
		   (getClass().getName() + ".failed1",
		    "Error: No Local interfaces defined for EJB [ {0} ]",
	            new Object[] {descriptor.getName()}));
	    return false;
	    
	}   
        if (role.getPartner().getIsMany()) {
            // must be one the collection interface 
            if (info.type.getName().equals("java.util.Collection") ||
                info.type.getName().equals("java.util.Set")) {
                foundIt = true;
            } 
        } else {
	    EjbBundleDescriptor bundle = ((EjbDescriptor) descriptor).getEjbBundleDescriptor();
	    if(((EjbDescriptor) descriptor).getLocalClassName() != null && 
	       !"".equals(((EjbDescriptor) descriptor).getLocalClassName())) {
		if (isValidInterface(info.type, bundle.getEjbs())) {
		    foundIt = true;
		}
	    }
	    else {
		if ((role.getRelationshipDescriptor()).getIsBidirectional()) {
		    result.addErrorDetails(smh.getLocalString
			   (getClass().getName() + ".failed",
			    "Error: Invalid type assigned for container managed relationship [ {0} ] in bean [ {1} ]",
			    new Object[] {info.name , descriptor.getName()}));
		    return false;
		}
		else foundIt = true;
	    }
        }
        if (foundIt) {
	     result.addGoodDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
            result.addGoodDetails(smh.getLocalString
	           (getClass().getName() + ".passed",
		    "Valid type assigned for container managed relationship [ {0} ] in bean [ {1} ]",
	                    new Object[] {info.name , descriptor.getName()}));
        } else {
            result.addErrorDetails(smh.getLocalString
		   (getClass().getName() + ".failed",
		    "Error: Invalid type assigned for container managed relationship [ {0} ] in bean [ {1} ]",
	            new Object[] {info.name , descriptor.getName()}));
        }
        return foundIt;