FileDocCategorySizeDatePackage
EjbUtils.javaAPI DocGlassfish v2 API11963Fri May 04 22:33:32 BST 2007com.sun.enterprise.tools.verifier.tests.ejb

EjbUtils

public class EjbUtils extends Object
Exceptions checked for CreateException, FinderException, RemoteException compliance test.

Fields Summary
Constructors Summary
Methods Summary
public static booleanisFieldSubsetOfCMP(java.lang.reflect.Field field, java.util.Set CMPFields)
The names of the fields in the primary key class must be a subset of the names of the container-managed fields. Verify the following: The primary key class field must be a subset of the names of the container-managed fields.

param
field the field to be checked for containment within the names of the container-managed fields
param
CMPFields the Set of contianer managed fields
return
boolean true if field is subset of CMP fields, false otherwise

	if (CMPFields.contains(new FieldDescriptor(field))) {
	    return true;
	} else {
	    return false;
	}
    
public static booleanisPKFieldMatchingBeanFields(java.lang.reflect.Field field, java.util.Vector beanFields)
The names of the fields in the primary key class must correspond to the field names of the entity bean class that comprise the key. Verify the following: The primary key class field must correspond to the field names of the entity bean class that comprise the key.

param
field the field to be checked for matching bean field
param
beanFields the Set of contianer managed fields
return
boolean true if field is subset of bean class fields, false otherwise


      for (int i = 0; i < beanFields.size(); i++) {
          if (((FieldDescriptor)beanFields.elementAt(i)).getName().equals(field.getName())) {
	      return true;
	  } else {
              continue;
	  }
      }
      // if you made it here, then field[] didn't contain field
      return false;
    
public static booleanisValidApplicationException(java.lang.Class[] methodExceptions)
Method application exception checked for compliance test. Verify the following: An application exception is an exception defined in the throws clause of a method in the Bean's home interface, other than java.rmi.RemoteException. An application exception must not be defined as a subclass of the java.lang.RuntimeException, or of the java.rmi.RemoteException. These are reserved for system exceptions. The javax.ejb.CreateException, javax.ejb.RemoveException, javax.ejb.FinderException, and subclasses thereof, are considered to be application exceptions.

param
methodExceptions the exceptions to be checked for throws application exception
return
boolean true if exceptions are valid application exception, false otherwise

	for (int kk = 0; kk < methodExceptions.length; ++kk) {
	 Class ex=methodExceptions[kk];
	 //check 0: app exception set is all exceptions minus java.rmi.RemoteException.
         if (java.rmi.RemoteException.class != ex) {
	 	//check 1: app exception must subclass java.lang.Exception
	 	if (!java.lang.Exception.class.isAssignableFrom(ex)) return false;
	 	//check 2: app exception must not subclass java.lang.RuntimeException or java.rmi.RemoteException
            	if(java.rmi.RemoteException.class.isAssignableFrom(ex) || java.lang.RuntimeException.class.isAssignableFrom(ex)) {
                	return false;
            	}
         }
	}
	return true;
    
public static booleanisValidCreateException(java.lang.Class[] methodExceptions)
Method exception javax.ejb.CreateException checked for compliance test. Verify the following: The home/remote interface methods exception types must be legal types for CreateException. This means that their exception must throw javax.ejb.CreateException.

param
methodExceptions the exceptions to be checked for throws javax.ejb.CreateException
return
boolean true if exceptions throw javax.ejb.CreateException, false otherwise

	// methods must throw javax.ejb.CreateException
	boolean throwsCreateException = false;
	for (int kk = 0; kk < methodExceptions.length; ++kk) {
	    if ((methodExceptions[kk].getName().equals("javax.ejb.CreateException")) ||
		(methodExceptions[kk].getName().equals("CreateException"))) {
		throwsCreateException = true;
		break;
	    }
	}
	return throwsCreateException;

    
public static booleanisValidFinderException(java.lang.Class[] methodExceptions)
Method exception javax.ejb.FinderException checked for compliance test. Verify the following: The home/remote interface methods exception types must be legal types for FinderException This means that their exception must throw javax.ejb.FinderException

param
methodExceptions the exceptions to be checked for throws javax.ejb.FinderException
return
boolean true if exceptions throw javax.ejb.FinderException, false otherwise

	// methods must throw javax.ejb.FinderException
	boolean throwsFinderException = false;
	for (int kk = 0; kk < methodExceptions.length; ++kk) {
	    if ((methodExceptions[kk].getName().equals("javax.ejb.FinderException")) ||
		(methodExceptions[kk].getName().equals("FinderException"))) {
		throwsFinderException = true;
		break;
	    }
	}
	return throwsFinderException;

    
public static booleanisValidObjectNotFoundExceptionException(java.lang.Class[] methodExceptions)
Method exception javax.ejb.ObjectNotFoundException checked for compliance test. Verify the following: The ObjectNotFoundException is a subclass of FinderException. It is thrown by the ejbFind(...) methods to indicate that the requested entity object does not exist. Only single-object finders (see Subsection 9.1.8) may throw this exception. Multi-object finders must not throw this exception.

param
methodExceptions the exceptions to be checked for throws javax.ejb.ObjectNotFoundException
return
boolean true if exceptions throw javax.ejb.ObjectNotFoundException, false otherwise

	// methods must throw javax.ejb.ObjectNotFoundException
	boolean throwsObjectNotFoundException = false;
	for (int kk = 0; kk < methodExceptions.length; ++kk) {
	    if ((methodExceptions[kk].getName().equals("javax.ejb.ObjectNotFoundException")) ||
		(methodExceptions[kk].getName().equals("ObjectNotFoundException"))) {
		throwsObjectNotFoundException = true;
		break;
	    }
	}
	return throwsObjectNotFoundException;
    
public static booleanisValidRemoteException(java.lang.Class[] methodExceptions)
Method exception java.rmi.RemoteException checked for compliance test. Verify the following: The home/remote interface methods exception types must be legal types for RemoteException. This means that their exception must throw java.rmi.RemoteException

param
methodExceptions the exceptions to be checked for throws java.rmi.RemoteException
return
boolean true if exceptions throw java.rmi.RemoteException, false otherwise

	// methods must throw java.rmi.RemoteException
	boolean throwsRemoteException = false;
	for (int kk = 0; kk < methodExceptions.length; ++kk) {
	    if ((methodExceptions[kk].getName().equals("java.rmi.RemoteException")) ||
		(methodExceptions[kk].getName().equals("RemoteException"))) {
		throwsRemoteException = true;
		break;
	    }
	}
	return throwsRemoteException;

    
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;

        /**
        // This complex logic is replaced by the above simple logic
	Class c = serClass;
	boolean validInterface = false;
	boolean badOne = false;
	// The class must implement the java.io.Serializable interface, either
	// directly or indirectly, 
	// walk up the class tree

	if (c.getName().equals("java.io.Serializable")) {
	    validInterface = true;
	    return validInterface;
	}
	do {	    
	    Class[] interfaces = c.getInterfaces();
	    for (int i = 0; i < interfaces.length; i++) {
		if (interfaces[i].getName().equals("java.io.Serializable")) {
		    validInterface = true;
		    break;
		} else {
		    // walk up the class tree of the interface and see if it
		    // implements java.io.Serializable
		    Class superClass = interfaces[i];
		    do {
			if (superClass.getName().equals("java.io.Serializable")) {
			    validInterface = true;
			    break;
			}
		    } while ((((superClass=superClass.getSuperclass()) != null) && (!validInterface)));
		}
	    }
	} while ((((c=c.getSuperclass()) != null) && (!validInterface)));


	if (validInterface) {
	    return true;
	} else {
	    return false;
	}
       **/