//
// Spec 10.6.2
//
if (!hasEntityBeanInterface(bean))
{
fireSpecViolationEvent(entity, new Section("10.6.2.a"));
status = false;
}
// The entity bean class MUST be defined as public and abstract.
//
// Spec 10.6.2
//
if (!isPublic(bean) || !isAbstract(bean))
{
fireSpecViolationEvent(entity, new Section("10.6.2.b"));
status = false;
}
// The entity bean class MUST define a public constructor that
// takes no arguments
//
// Spec 10.6.2
//
if (!hasDefaultConstructor(bean))
{
fireSpecViolationEvent(entity, new Section("10.6.2.c"));
status = false;
}
// The entity bean class MUST NOT define the finalize() method.
//
// Spec 10.6.2
//
if (hasFinalizer(bean))
{
fireSpecViolationEvent(entity, new Section("10.6.2.d"));
status = false;
}
// The ejbCreate(...) method signatures MUST follow these rules:
//
// - The method MUST be declared as public
// - The method MUST NOT be declared as final or static
// - The return type MUST be the entity bean's primary key type
// --- Only if method is on remote home ---
// - The method arguments MUST be legal types for RMI/IIOP
// - The method return value type MUST be legal type for RMI/IIOP
// --- End of only if method is on remote home ---
// - The method must define the javax.ejb.CreateException
//
// Spec 10.6.4
//
if (hasEJBCreateMethod(bean, false))
{
Iterator it = getEJBCreateMethods(bean);
while (it.hasNext())
{
Method ejbCreate = (Method)it.next();
if (!isPublic(ejbCreate))
{
fireSpecViolationEvent(entity, ejbCreate,
new Section("10.6.4.b"));
status = false;
}
if ((isFinal(ejbCreate)) || (isStatic(ejbCreate)))
{
fireSpecViolationEvent(entity, ejbCreate,
new Section("10.6.4.c"));
status = false;
}
if (!hasPrimaryKeyReturnType(entity, ejbCreate))
{
fireSpecViolationEvent(entity, ejbCreate,
new Section("10.6.4.d"));
status = false;
}
/* FIXME
* This is only true if the method is on the remote home
* interface
if (!hasLegalRMIIIOPArguments(ejbCreate)) {
fireSpecViolationEvent(entity, ejbCreate, new Section("10.6.4.d"));
status = false;
}
if (!hasLegalRMIIIOPReturnType(ejbCreate)) {
fireSpecViolationEvent(entity, ejbCreate, new Section("10.5.4.f"));
status = false;
}
*/
if (!throwsCreateException(ejbCreate))
{
fireSpecViolationEvent(entity, ejbCreate,
new Section("10.6.4.g"));
status = false;
}
}
}
// For each ejbCreate(...) method, the entity bean class MUST
// define a matching ejbPostCreate(...) method.
//
// The ejbPostCreate(...) method MUST follow these rules:
//
// - the method MUST be declared as public
// - the method MUST NOT be declared as final or static
// - the return type MUST be void
// - the method arguments MUST be the same as the matching
// ejbCreate(...) method
//
// Spec 10.6.5
//
if (hasEJBCreateMethod(bean, false))
{
Iterator it = getEJBCreateMethods(bean);
while (it.hasNext())
{
Method ejbCreate = (Method)it.next();
if (!hasMatchingEJBPostCreate(bean, ejbCreate))
{
fireSpecViolationEvent(entity, ejbCreate,
new Section("10.6.5.a"));
status = false;
}
if (hasMatchingEJBPostCreate(bean, ejbCreate))
{
Method ejbPostCreate = getMatchingEJBPostCreate(bean,
ejbCreate);
if (!isPublic(ejbPostCreate))
{
fireSpecViolationEvent(entity, ejbPostCreate,
new Section("10.6.5.b"));
status = false;
}
if (isStatic(ejbPostCreate))
{
fireSpecViolationEvent(entity, ejbPostCreate,
new Section("10.6.5.c"));
status = false;
}
if (isFinal(ejbPostCreate))
{
fireSpecViolationEvent(entity, ejbPostCreate,
new Section("10.6.5.d"));
status = false;
}
if (!hasVoidReturnType(ejbPostCreate))
{
fireSpecViolationEvent(entity, ejbPostCreate,
new Section("10.6.5.e"));
status = false;
}
}
}
}
// The ejbHome(...) method signatures MUST follow these rules:
//
// - The method name MUST have ejbHome as its prefix.
// - The method MUST be declared as public
// - The method MUST NOT be declared as static.
// - The method MUST NOT define the java.rmi.RemoteException
//
// Spec 10.6.6
//
Iterator it = getEjbHomeMethods(bean);
while (it.hasNext())
{
Method ejbHome = (Method)it.next();
if (!isPublic(ejbHome))
{
fireSpecViolationEvent(entity, ejbHome, new Section("10.6.6.a"));
status = false;
}
if (isStatic(ejbHome))
{
fireSpecViolationEvent(entity, ejbHome, new Section("10.6.6.b"));
status = false;
}
if (throwsRemoteException(ejbHome))
{
fireSpecViolationEvent(entity, ejbHome, new Section("10.6.6.c"));
status = false;
}
}
// The CMP entity bean MUST implement get and set accessor methods for
// each field within the abstract persistance schema.
//
// Spec 10.6.2
//
it = entity.getCMPFields();
while (it.hasNext())
{
String fieldName = (String)it.next();
String getName = "get" + fieldName.substring(0, 1).toUpperCase() +
fieldName.substring(1);
Class fieldType = null;
try
{
Method m = bean.getMethod(getName, new Class[0]);
fieldType = m.getReturnType();
// The getter must not return 'void' according to the JavaBeans
// Spec
if (fieldType == Void.TYPE)
{
fireSpecViolationEvent(entity,
new Section("jb.7.1.b", "Field: " + fieldName));
}
}
catch (NoSuchMethodException nsme)
{
fireSpecViolationEvent(entity,
new Section("10.6.2.g", "Field: " + fieldName));
status = false;
}
String setName = "set" + fieldName.substring(0, 1).toUpperCase() +
fieldName.substring(1);
Class[] args = new Class[1];
args[0] = fieldType;
try
{
Method m = bean.getMethod(setName, args);
fieldType = m.getReturnType();
// According to the JavaBeans Spec, a setter method must
// return 'void'
if (fieldType != Void.TYPE)
{
fireSpecViolationEvent(entity,
new Section("jb.7.1.a", "Field: " + fieldName));
}
}
catch (NoSuchMethodException nsme)
{
// Try with java.util.Collection
//
// FIXME: This should only be tried for CMR methods; a CMP
// setter cannot accept a Collection!
try
{
args[0] = classloader.loadClass("java.util.Collection");
Method m = bean.getMethod(setName, args);
}
catch (NoSuchMethodException nsme2)
{
fireSpecViolationEvent(entity,
new Section("10.6.2.h", "Field: " + fieldName));
status = false;
}
catch (ClassNotFoundException cnfe)
{
// Something is really broken
}
}
}
// The ejbSelect(...) method signatures MUST follow these rules:
//
// - The method name MUST have ejbSelect as its prefix.
// - The method MUST be declared as public
// - The method MUST be declared as abstract.
// - The method MUST define the javax.ejb.FinderException
//
// Spec 10.6.7
//
it = getEjbSelectMethods(bean);
while (it.hasNext())
{
Method ejbSelect = (Method)it.next();
if (!isPublic(ejbSelect))
{
fireSpecViolationEvent(entity, ejbSelect, new Section("10.6.7.a"));
status = false;
}
if (!isAbstract(ejbSelect))
{
fireSpecViolationEvent(entity, ejbSelect, new Section("10.6.7.b"));
status = false;
}
if (!throwsFinderException(ejbSelect))
{
fireSpecViolationEvent(entity, ejbSelect, new Section("10.6.7.c"));
status = false;
}
if (!hasMatchingQuery(ejbSelect, entity))
{
fireSpecViolationEvent(entity, ejbSelect, new Section("10.5.7"));
status = false;
}
}
// A CMP Entity Bean must not define Finder methods.
//
// Spec 10.6.2
//
if (hasFinderMethod(bean))
{
fireSpecViolationEvent(entity, new Section("10.6.2.i"));
status = false;
}
return status;
}