FileDocCategorySizeDatePackage
PrimaryKeyClassMethodHashCode.javaAPI DocGlassfish v2 API7249Fri May 04 22:33:50 BST 2007com.sun.enterprise.tools.verifier.tests.ejb.entity.primarykeyclass

PrimaryKeyClassMethodHashCode

public class PrimaryKeyClassMethodHashCode extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest implements com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck
Primary key class provide implementation of hashCode() methods test. Enterprise Bean's primary key class The class must provide suitable implementation of the hashCode() method to simplify the management of the primary keys by client code.

Fields Summary
Constructors Summary
Methods Summary
public Resultcheck(com.sun.enterprise.deployment.EjbDescriptor descriptor)
Primary key class provide implementation of hashCode() methods test. Enterprise Bean's primary key class The class must provide suitable implementation of the hashCode() method to simplify the management of the primary keys by client code.

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


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

	if (descriptor instanceof EjbEntityDescriptor) {
	    String transactionType = descriptor.getTransactionType();
	    if (EjbDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType))
		{

		    boolean hasDefinedHashCodeMethod = false;
		    boolean oneFailed = false;
		    int lc = 0;

		    // RULE: Primary key class must defined HashCode() method
		    try {
			Context context = getVerifierContext();
			ClassLoader jcl = context.getClassLoader();
			// retrieve the EJB primary key class 
			Class c = Class.forName(((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader());
			Method methods[] = c.getDeclaredMethods();
			for (int i=0; i< methods.length; i++)
			    {
				if (methods[i].getName().equals("hashCode")){
				    // this is the right primary key class method hashCode()
				    hasDefinedHashCodeMethod = true;
				    // used in output below
				    lc = i;
				    break;
				}
			    }

			if (hasDefinedHashCodeMethod) 
			    {
				result.addGoodDetails(smh.getLocalString
						  ("tests.componentNameConstructor",
						   "For [ {0} ]",
						   new Object[] {compName.toString()}));
				result.addGoodDetails(smh.getLocalString
						      (getClass().getName() + ".debug1",
						       "For EJB primary key class [ {0} ]",
						       new Object[] {((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName()}));
				result.addGoodDetails(smh.getLocalString
						      (getClass().getName() + ".passed",
						       "Primary key class method [ {0} ] was defined in the primary key class.",
						       new Object[] {methods[lc].getName()}));
			    } else if (!hasDefinedHashCodeMethod) {
				oneFailed = true;
				result.addErrorDetails(smh.getLocalString
						  ("tests.componentNameConstructor",
						   "For [ {0} ]",
						   new Object[] {compName.toString()}));
				result.addErrorDetails(smh.getLocalString
						      (getClass().getName() + ".debug1",
						       "For EJB primary key class [ {0} ]",
						       new Object[] {((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName()}));
				result.addErrorDetails(smh.getLocalString
						       (getClass().getName() + ".failed",
							"Error: Primary key class method hashCode() was not defined in the primary key class."));
			    } 
        
		    } catch (ClassNotFoundException e) {
			Verifier.debug(e);
			result.addErrorDetails(smh.getLocalString
					       ("tests.componentNameConstructor",
						"For [ {0} ]",
						new Object[] {compName.toString()}));
			result.failed(smh.getLocalString
				      (getClass().getName() + ".failedException",
				       "Error: Class [ {0} ] not found within bean [ {1} ]",
				       new Object[] {((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName(), descriptor.getName()})
				      );
		    }

		    if (oneFailed) 
			result.setStatus(result.FAILED);
		    else
			result.setStatus(result.PASSED);

		} else {
		    // not container managed, but is a entity bean
		    result.addNaDetails(smh.getLocalString
						  ("tests.componentNameConstructor",
						   "For [ {0} ]",
						   new Object[] {compName.toString()}));
		    result.notApplicable(smh.getLocalString
					 (getClass().getName() + ".notApplicable2",
					  "Bean [ {0} ] is not {1} managed, it is [ {2} ] managed.",
					  new Object[] {descriptor.getName(),EjbDescriptor.CONTAINER_TRANSACTION_TYPE,transactionType}));
		}

	    return result;

	} else {
	    result.addNaDetails(smh.getLocalString
						  ("tests.componentNameConstructor",
						   "For [ {0} ]",
						   new Object[] {compName.toString()}));
	    result.notApplicable(smh.getLocalString
				 (getClass().getName() + ".notApplicable",
				  "[ {0} ] expected {1} bean, but called with {2} bean.",
				  new Object[] {getClass(),"Entity","Session"}));
	    return result;
	}