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

CmpFieldsAccessorExposition

public class CmpFieldsAccessorExposition extends CMPTest
EJB 2.0 Spec 9.4.11 Set Accessor method for primary key fields should not be exposed in the remote/local interface
author
Jerome Dochez
version

Fields Summary
com.sun.enterprise.tools.verifier.Result
result
ComponentNameConstructor
compName
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(EjbCMPEntityDescriptor descriptor)

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


                            
        

	result = getInitializedResult();
        boolean oneFailed = false;
	compName = getVerifierContext().getComponentNameConstructor();
        
	if (descriptor.getRemoteClassName() != null && !((descriptor.getRemoteClassName()).equals(""))) 
	    oneFailed = commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor); 
	if(oneFailed == false) {
	    if (descriptor.getLocalClassName() != null && !((descriptor.getLocalClassName()).equals(""))) 
		oneFailed = commonToBothInterfaces(descriptor.getLocalClassName(),descriptor); 
	}
	if (oneFailed) 
            result.setStatus(Result.WARNING);
        else 
            result.setStatus(Result.PASSED);
        return result;
    
private booleancommonToBothInterfaces(java.lang.String remote, 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 for the Remote/Local interface of the Ejb.
return
boolean the results for this assertion i.e if a test has failed or not

	boolean oneFailed = false;
	try { 
	   Class c = Class.forName(remote, false, getVerifierContext().getClassLoader());   
	    boolean foundAtLeastOne = false;
            
	    try {
		// Check first that pk fields set methods are mot part of the remote interface                
		PersistentFieldInfo[] pkFieldInfos = ((EjbCMPEntityDescriptor)descriptor).getPersistenceDescriptor().getPkeyFieldInfo();
		for (int i=0;i<pkFieldInfos.length;i++) {
		    foundAtLeastOne = true;
		    PersistentFieldInfo info = pkFieldInfos[i];
		    // check that setXXX is not part of the remote interface
		    String setMethodName = "set" + Character.toUpperCase(info.name.charAt(0)) + info.name.substring(1);                
		    Class parms[] = { info.type };
		    Method setMethod = getMethod(c, setMethodName, parms );        
		    if (setMethod != null) {
			// oopss
			result.addWarningDetails(smh.getLocalString
						 ("tests.componentNameConstructor",
						  "For [ {0} ]",
						  new Object[] {compName.toString()}));
			result.addWarningDetails(smh.getLocalString
			    ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldsAccessorExposition.failed",
			     "Error : Primary key field set accessor method [ {0} ] is exposed through the component interface [ {1} ]",
			     new Object[] {info.name,remote}));  
			oneFailed = true;
		    } else {
			result.addGoodDetails(smh.getLocalString
					      ("tests.componentNameConstructor",
					       "For [ {0} ]",
					       new Object[] {compName.toString()}));
			result.addGoodDetails(smh.getLocalString
			    ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldsAccessorExposition.passed",
			     "Primary key field set accessor method [ {0} ] is not exposed through the component interface [ {1} ]",
			     new Object[] {info.name,remote}));                    
		    }
		}
		if (foundAtLeastOne == false) {
		    result.addGoodDetails(smh.getLocalString
					  ("tests.componentNameConstructor",
					   "For [ {0} ]",
					   new Object[] {compName.toString()}));
		    result.addGoodDetails(smh.getLocalString
		     ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldsAccessorExposition.notApplicable",
		      "No persistent fields found.",
		      new Object[] {})); 
		    return oneFailed;
		}
		
	    } catch (RuntimeException rt) {
		result.addErrorDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
		result.failed(smh.getLocalString
			      ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldsAccessorExposition.failedException1",
			   "Exception occured while trying to access Primary key info in PersistenceDescriptor.",
			   new Object[] {}));
	    }
	    return oneFailed;
	} catch (ClassNotFoundException e) {
	    Verifier.debug(e);
	    result.addErrorDetails(smh.getLocalString
				   ("tests.componentNameConstructor",
				    "For [ {0} ]",
				    new Object[] {compName.toString()}));
	    result.failed(smh.getLocalString
			  ("com.sun.enterprise.tools.verifier.tests.ejb.EjbTest.failedException",
			   "Error: [ {0} ] class not found.",
			   new Object[] {descriptor.getEjbClassName()}));
	    oneFailed = true;
	    return oneFailed;
	    
	}