FileDocCategorySizeDatePackage
EntityBeanExtendsSerializableClass.javaAPI DocGlassfish v2 API7627Fri May 04 22:33:36 BST 2007com.sun.enterprise.tools.verifier.tests.ejb.entity

EntityBeanExtendsSerializableClass

public class EntityBeanExtendsSerializableClass extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest implements EjbCheck
The interfaces/classes that the entity bean implements must be serializable directly or indirectly.
author
Sheetal Vartak

Fields Summary
Constructors Summary
Methods Summary
public Resultcheck(com.sun.enterprise.deployment.EjbDescriptor descriptor)
The interfaces/classes that the entity bean implements must be serializable directly or indirectly. Ejb 2.1 says that "The bean class that uses the timer service must implement the javax.ejb.TimedObject interface."

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) {
	    try {
		Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());

		boolean validBean = true;
		Class superClass = c.getSuperclass();
		if (validBean == true) {
		    // walk up the class tree 
		  if(!(superClass.getName()).equals("java.lang.Object")) {
			if (!isValidSerializableType(superClass) &&
					!isTimedObject(superClass)) {
			    validBean = false;
			    result.addWarningDetails(smh.getLocalString
						     ("tests.componentNameConstructor",
						      "For [ {0} ]",
						      new Object[] {compName.toString()}));
			    result.addWarningDetails(smh.getLocalString
						     (getClass().getName() + ".failed1",
						      "[ {0} ] extends class [ {1} ] which is not serializable. ",
						      new Object[] {descriptor.getEjbClassName(),superClass.getName()}));
			    result.setStatus(Result.WARNING);
			    return result;
			} else {
			    result.addGoodDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
			    result.addGoodDetails(smh.getLocalString
						  (getClass().getName() + ".passed1",
						   "Bean [ {0} ] extends class [ {1} ] which is serializable. ",
						   new Object[] {descriptor.getEjbClassName(), superClass.getName()}));
			    do {
				Class[] interfaces = c.getInterfaces();
				
				for (int i = 0; i < interfaces.length; i++) {
				    
                    logger.log(Level.FINE, getClass().getName() + ".debug1",
                            new Object[] {interfaces[i].getName()});

				    if (!isValidSerializableType(interfaces[i])
					 && !isTimedObject(interfaces[i])) {
					validBean = false;
					result.addWarningDetails(smh.getLocalString
								 ("tests.componentNameConstructor",
								  "For [ {0} ]",
								  new Object[] {compName.toString()}));
					result.addWarningDetails(smh.getLocalString
						   (getClass().getName() + ".failed",
						   "[ {0} ] implements interface [ {1} ] which is not serializable. ",
						   new Object[] {descriptor.getEjbClassName(),interfaces[i].getName()}));
					result.setStatus(Result.WARNING);
					break;
				    }
				}
			    } while ((((c=c.getSuperclass()) != null) && (validBean != false)));
			}
		    }
		    if (validBean == true){
			result.addGoodDetails(smh.getLocalString
					      ("tests.componentNameConstructor",
					       "For [ {0} ]",
					       new Object[] {compName.toString()}));
			result.passed(smh.getLocalString
				      (getClass().getName() + ".passed",
				       "Bean [ {0} ] implements interfaces which are all serializable. ",
				       new Object[] {descriptor.getEjbClassName()}));
			result.setStatus(Result.PASSED);
		    }
		}


	    } 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: [ {0} ] class not found.",
			       new Object[] {descriptor.getEjbClassName()}));
	    }  

	    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;
	}
    
public static booleanisTimedObject(java.lang.Class serClass)

        if (javax.ejb.TimedObject.class.isAssignableFrom(serClass))
            return true;
        else
            return false;
    
public static booleanisValidSerializableType(java.lang.Class serClass)
Class checked for implementing java.io.Serializable interface test. Verify the following: The class must implement the java.io.Serializable interface, either directly or indirectly.

param
serClass the class to be checked for Rmi-IIOP value type compliance
return
boolean true if class implements java.io.Serializable, false otherwise


        if (java.io.Serializable.class.isAssignableFrom(serClass))
            return true;
        else
            return false;