package org.jboss.verifier.strategy;
import org.jboss.logging.Logger;
import org.jboss.metadata.BeanMetaData;
import org.jboss.metadata.EntityMetaData;
import org.jboss.metadata.MessageDrivenMetaData;
import org.jboss.metadata.SessionMetaData;
import org.jboss.verifier.Section;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Iterator;
public class EJBVerifier20 extends AbstractEJB2xVerifier
{
private static Logger log = Logger.getLogger(EJBVerifier20.class);
public EJBVerifier20(VerificationContext context)
{
super(context);
cmp1XVerifier = new EJBVerifier11(context);
}
public String getMessageBundle()
{
return "EJB20Messages.properties";
}
public void checkSession(SessionMetaData session)
{
boolean localOrRemoteExists = false;
boolean verified = false;
if (!verifyBean(session))
return;
verified = verifySessionBean(session);
if (hasRemoteInterfaces(session))
{
localOrRemoteExists = true;
verified = verified && verifySessionRemote(session);
verified = verified && verifySessionHome(session);
}
if (hasLocalInterfaces(session))
{
localOrRemoteExists = true;
verified = verified && verifySessionLocal(session);
verified = verified && verifySessionLocalHome(session);
}
if (!localOrRemoteExists)
{
fireSpecViolationEvent(session, new Section("7.10.1"));
verified = false;
}
if (verified)
{
fireBeanVerifiedEvent(session);
}
}
public void checkEntity(EntityMetaData entity)
{
if (entity.isCMP1x())
{
cmp1XVerifier.checkEntity(entity);
}
else
{
checkBmpOrCmp2Entity(entity);
}
}
public void checkMessageBean(MessageDrivenMetaData mdb)
{
boolean beanVerified = false;
if (!verifyBean(mdb))
return;
beanVerified = verifyMessageDrivenBean(mdb);
if (beanVerified)
{
fireBeanVerifiedEvent(mdb);
}
}
private void checkBmpOrCmp2Entity(EntityMetaData entity)
{
boolean localOrRemoteExists = false;
boolean verified = false;
if (!verifyBean(entity))
return;
if (entity.isCMP())
{
verified = verifyCMPEntityBean(entity);
}
else if (entity.isBMP())
{
verified = verifyBMPEntityBean(entity);
}
if (hasRemoteInterfaces(entity))
{
localOrRemoteExists = true;
verified = verified && verifyEntityRemote(entity);
verified = verified && verifyEntityHome(entity);
}
if (hasLocalInterfaces(entity))
{
localOrRemoteExists = true;
verified = verified && verifyEntityLocal(entity);
verified = verified && verifyEntityLocalHome(entity);
}
verified = verified && verifyPrimaryKey(entity);
if (!localOrRemoteExists)
{
if (entity.isCMP())
{
fireSpecViolationEvent(entity, new Section("10.6.1"));
verified = false;
}
else
{
fireSpecViolationEvent(entity, new Section("12.2.1"));
verified = false;
}
}
if (verified)
{
fireBeanVerifiedEvent(entity);
}
}
protected boolean verifyBean(BeanMetaData theBean)
{
String beanName = theBean.getEjbClass();
if (beanName == null)
return false;
try
{
bean = classloader.loadClass(beanName);
return true;
}
catch (ClassNotFoundException cnfe)
{
fireSpecViolationEvent(theBean, new Section("22.2.b",
"Class not found on '" + beanName + "': " + cnfe.getMessage()));
return false;
}
}
protected boolean hasRemoteInterfaces(BeanMetaData bean)
{
boolean status = true;
String homeName = bean.getHome();
String remoteName = bean.getRemote();
if (homeName == null || remoteName == null)
return false;
try
{
home = classloader.loadClass(homeName);
}
catch (ClassNotFoundException cnfe)
{
fireSpecViolationEvent(bean, new Section("22.2.c",
"Class not found on '" + homeName + "': " + cnfe.getMessage()));
status = false;
}
try
{
remote = classloader.loadClass(remoteName);
}
catch (ClassNotFoundException cnfe)
{
fireSpecViolationEvent(bean, new Section("22.2.d",
"Class not found on '" + remoteName + "': " + cnfe.getMessage()));
status = false;
}
return status;
}
protected boolean hasLocalInterfaces(BeanMetaData bean)
{
boolean status = true;
String localHomeName = bean.getLocalHome();
String localName = bean.getLocal();
if (localHomeName == null || localName == null)
return false;
try
{
localHome = classloader.loadClass(localHomeName);
}
catch (ClassNotFoundException cnfe)
{
fireSpecViolationEvent(bean, new Section("22.2.e",
"Class not found on '" + localHomeName + "': " +
cnfe.getMessage()));
status = false;
}
try
{
local = classloader.loadClass(localName);
}
catch (ClassNotFoundException cnfe)
{
fireSpecViolationEvent(bean, new Section("22.2.f",
"Class not found on '" + localName + "': " + cnfe.getMessage()));
status = false;
}
return status;
}
protected boolean verifySessionHome(SessionMetaData session)
{
boolean status = true;
if (session.isStateless())
{
if (!hasDefaultCreateMethod(home))
{
fireSpecViolationEvent(session, new Section("7.10.6.d2"));
status = false;
}
else
{
Method create = getDefaultCreateMethod(home);
if (hasMoreThanOneCreateMethods(home))
{
fireSpecViolationEvent(session, new Section("7.10.6.d2"));
status = false;
}
}
}
if (!hasEJBHomeInterface(home))
{
fireSpecViolationEvent(session, new Section("7.10.6.a"));
status = false;
}
Iterator it = Arrays.asList(home.getMethods()).iterator();
while (it.hasNext())
{
Method method = (Method)it.next();
if (!hasLegalRMIIIOPArguments(method))
{
fireSpecViolationEvent(session, method, new Section("7.10.6.b1"));
status = false;
}
if (!hasLegalRMIIIOPReturnType(method))
{
fireSpecViolationEvent(session, method, new Section("7.10.6.b2"));
status = false;
}
if (!throwsRemoteException(method))
{
fireSpecViolationEvent(session, method, new Section("7.10.6.b3"));
status = false;
}
}
if (!hasCreateMethod(home))
{
fireSpecViolationEvent(session, new Section("7.10.6.d1"));
status = false;
}
Iterator createMethods = getCreateMethods(home);
while (createMethods.hasNext())
{
Method create = (Method)createMethods.next();
if (!hasMatchingEJBCreate(bean, create))
{
fireSpecViolationEvent(session, create, new Section("7.10.6.e"));
status = false;
}
if (!hasRemoteReturnType(session, create))
{
fireSpecViolationEvent(session, create, new Section("7.10.6.f"));
status = false;
}
if (hasMatchingEJBCreate(bean, create))
{
Method ejbCreate = getMatchingEJBCreate(bean, create);
if (!hasMatchingExceptions(ejbCreate, create))
{
fireSpecViolationEvent(session, create,
new Section("7.10.6.g"));
status = false;
}
}
if (!throwsCreateException(create))
{
fireSpecViolationEvent(session, create, new Section("7.10.6.h"));
status = false;
}
}
return status;
}
protected boolean verifySessionLocalHome(SessionMetaData session)
{
boolean status = true;
if (session.isStateless())
{
if (!hasDefaultCreateMethod(localHome))
{
fireSpecViolationEvent(session, new Section("7.10.8.d2"));
status = false;
}
else
{
Method create = getDefaultCreateMethod(localHome);
if (hasMoreThanOneCreateMethods(localHome))
{
fireSpecViolationEvent(session, new Section("7.10.8.d2"));
status = false;
}
}
}
if (!hasEJBLocalHomeInterface(localHome))
{
fireSpecViolationEvent(session, new Section("7.10.8.a"));
status = false;
}
Iterator it = Arrays.asList(localHome.getMethods()).iterator();
while (it.hasNext())
{
Method method = (Method)it.next();
if (throwsRemoteException(method))
{
fireSpecViolationEvent(session, method, new Section("7.10.8.b"));
status = false;
}
}
if (!hasCreateMethod(localHome))
{
fireSpecViolationEvent(session, new Section("7.10.8.d1"));
status = false;
}
Iterator createMethods = getCreateMethods(localHome);
while (createMethods.hasNext())
{
Method create = (Method)createMethods.next();
if (!hasMatchingEJBCreate(bean, create))
{
fireSpecViolationEvent(session, create,
new Section("7.10.8.e"));
status = false;
}
if (!hasLocalReturnType(session, create))
{
fireSpecViolationEvent(session, create,
new Section("7.10.8.f"));
status = false;
}
if (hasMatchingEJBCreate(bean, create))
{
Method ejbCreate = getMatchingEJBCreate(bean, create);
if (!hasMatchingExceptions(ejbCreate, create))
{
fireSpecViolationEvent(session, create,
new Section("7.10.8.g"));
}
}
if (!throwsCreateException(create))
{
fireSpecViolationEvent(session, create,
new Section("7.10.8.h"));
status = false;
}
}
return status;
}
protected boolean verifySessionRemote(SessionMetaData session)
{
boolean status = true;
if (!hasEJBObjectInterface(remote))
{
fireSpecViolationEvent(session, new Section("7.10.5.a"));
status = false;
}
Iterator it = Arrays.asList(remote.getMethods()).iterator();
while (it.hasNext())
{
Method method = (Method)it.next();
if (!hasLegalRMIIIOPArguments(method))
{
fireSpecViolationEvent(session, method, new Section("7.10.5.b1"));
status = false;
}
if (!hasLegalRMIIIOPReturnType(method))
{
fireSpecViolationEvent(session, method, new Section("7.10.5.b2"));
status = false;
}
if (!throwsRemoteException(method))
{
fireSpecViolationEvent(session, method, new Section("7.10.5.b3"));
status = false;
}
}
it = Arrays.asList(remote.getDeclaredMethods()).iterator();
while (it.hasNext())
{
Method remoteMethod = (Method)it.next();
if (!hasMatchingMethod(bean, remoteMethod))
{
fireSpecViolationEvent(session, remoteMethod,
new Section("7.10.5.d1"));
status = false;
}
if (hasMatchingMethod(bean, remoteMethod))
{
try
{
Method beanMethod = bean.getMethod(remoteMethod.getName(),
remoteMethod.getParameterTypes());
if (!hasMatchingReturnType(remoteMethod, beanMethod))
{
fireSpecViolationEvent(session, remoteMethod,
new Section("7.10.5.d2"));
status = false;
}
if (!hasMatchingExceptions(beanMethod, remoteMethod))
{
fireSpecViolationEvent(session, remoteMethod,
new Section("7.10.5.d3"));
status = false;
}
}
catch (NoSuchMethodException ignored)
{
}
}
}
return status;
}
protected boolean verifySessionLocal(SessionMetaData session)
{
boolean status = true;
if (!hasEJBLocalObjectInterface(local))
{
fireSpecViolationEvent(session, new Section("7.10.7.a"));
status = false;
}
Iterator it = Arrays.asList(local.getMethods()).iterator();
while (it.hasNext())
{
Method method = (Method)it.next();
if (throwsRemoteException(method))
{
fireSpecViolationEvent(session, method, new Section("7.10.7.b"));
status = false;
}
}
it = Arrays.asList(local.getDeclaredMethods()).iterator();
while (it.hasNext())
{
Method localMethod = (Method)it.next();
if (!hasMatchingMethod(bean, localMethod))
{
fireSpecViolationEvent(session, localMethod,
new Section("7.10.7.d1"));
status = false;
}
if (hasMatchingMethod(bean, localMethod))
{
try
{
Method beanMethod = bean.getMethod(localMethod.getName(),
localMethod.getParameterTypes());
if (!hasMatchingReturnType(localMethod, beanMethod))
{
fireSpecViolationEvent(session, localMethod,
new Section("7.10.7.d2"));
status = false;
}
if (!hasMatchingExceptions(beanMethod, localMethod))
{
fireSpecViolationEvent(session, localMethod,
new Section("7.10.7.d3"));
status = false;
}
}
catch (NoSuchMethodException ignored)
{
}
}
}
return status;
}
protected boolean verifySessionBean(SessionMetaData session)
{
boolean status = true;
if (!hasSessionBeanInterface(bean))
{
fireSpecViolationEvent(session, new Section("7.10.2.a"));
status = false;
}
if (hasSessionSynchronizationInterface(bean))
{
if (session.isStateless())
{
fireSpecViolationEvent(session, new Section("7.5.3.a"));
status = false;
}
if (session.isBeanManagedTx())
{
fireSpecViolationEvent(session, new Section("7.5.3.b"));
status = false;
}
}
if (!hasEJBCreateMethod(bean, true))
{
fireSpecViolationEvent(session, new Section("7.10.3"));
status = false;
}
if (hasSessionSynchronizationInterface(bean)
&& session.isBeanManagedTx())
{
fireSpecViolationEvent(session, new Section("7.6.1"));
status = false;
}
if (!isPublic(bean))
{
fireSpecViolationEvent(session, new Section("7.10.2.b1"));
status = false;
}
if (isFinal(bean))
{
fireSpecViolationEvent(session, new Section("7.10.2.b2"));
status = false;
}
if (isAbstract(bean))
{
fireSpecViolationEvent(session, new Section("7.10.2.b3"));
status = false;
}
if (!hasDefaultConstructor(bean))
{
fireSpecViolationEvent(session, new Section("7.10.2.c"));
status = false;
}
if (hasFinalizer(bean))
{
fireSpecViolationEvent(session, new Section("7.10.2.d"));
status = false;
}
if (hasEJBCreateMethod(bean, true))
{
Iterator it = getEJBCreateMethods(bean);
while (it.hasNext())
{
Method ejbCreate = (Method)it.next();
if (!isPublic(ejbCreate))
{
fireSpecViolationEvent(session, ejbCreate,
new Section("7.10.3.b"));
status = false;
}
if ((isFinal(ejbCreate)) || (isStatic(ejbCreate)))
{
fireSpecViolationEvent(session, ejbCreate,
new Section("7.10.3.c"));
status = false;
}
if (!hasVoidReturnType(ejbCreate))
{
fireSpecViolationEvent(session, ejbCreate,
new Section("7.10.3.d"));
status = false;
}
if (!hasLegalRMIIIOPArguments(ejbCreate))
{
fireSpecViolationEvent(session, ejbCreate,
new Section("7.10.3.e"));
status = false;
}
}
}
return status;
}
private boolean verifyEntityHome(EntityMetaData entity)
{
boolean status = true;
if (!hasEJBHomeInterface(home))
{
fireSpecViolationEvent(entity, new Section("12.2.9.a"));
status = false;
}
Iterator methods = Arrays.asList(home.getMethods()).iterator();
while (methods.hasNext())
{
Method method = (Method)methods.next();
if (!hasLegalRMIIIOPArguments(method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.9.b1"));
status = false;
}
if (!hasLegalRMIIIOPReturnType(method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.9.b2"));
status = false;
}
if (!throwsRemoteException(method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.9.b3"));
status = false;
}
}
methods = Arrays.asList(home.getMethods()).iterator();
while (methods.hasNext())
{
Method method = (Method)methods.next();
if (method.getDeclaringClass().getName().equals(EJB_HOME_INTERFACE))
continue;
if (isCreateMethod(method))
{
if (!hasMatchingEJBCreate(bean, method))
{
fireSpecViolationEvent(entity, method, new Section("12.2.9.d"));
status = false;
}
if (!hasRemoteReturnType(entity, method))
{
fireSpecViolationEvent(entity, method, new Section("12.2.9.e"));
status = false;
}
if (hasMatchingEJBCreate(bean, method)
&& hasMatchingEJBPostCreate(bean, method))
{
Method ejbCreate = getMatchingEJBCreate(bean, method);
Method ejbPostCreate = getMatchingEJBPostCreate(bean, method);
if (!(hasMatchingExceptions(ejbCreate, method)
&& hasMatchingExceptions(ejbPostCreate, method)))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.9.f"));
}
}
if (!throwsCreateException(method))
{
fireSpecViolationEvent(entity, method, new Section("12.2.9.g"));
status = false;
}
}
else if (isFinderMethod(method))
{
if (entity.isBMP())
{ if ((!hasMatchingEJBFind(bean, method)))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.9.h"));
status = false;
}
if (!(hasRemoteReturnType(entity, method)
|| isMultiObjectFinder(method)))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.9.j"));
status = false;
}
if ((hasMatchingEJBFind(bean, method)))
{
Method ejbFind = getMatchingEJBFind(bean, method);
if (!(hasMatchingExceptions(ejbFind, method)))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.9.k"));
status = false;
}
}
if (!throwsFinderException(method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.9.l"));
status = false;
}
}
if (entity.isCMP())
{
if (!(hasRemoteReturnType(entity, method)
|| isMultiObjectFinder(method)))
{
fireSpecViolationEvent(entity, method,
new Section("10.6.10.a"));
status = false;
}
if (!throwsFinderException(method))
{
fireSpecViolationEvent(entity, method,
new Section("10.6.10.b"));
status = false;
}
if (!method.getName().equals("findByPrimaryKey")
&& !method.getName().equals("findAll")
&& !hasMatchingQuery(method, entity))
{
fireSpecViolationEvent(entity, method,
new Section("10.5.6"));
status = false;
}
} }
else {
if (!hasMatchingEJBHome(bean, method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.9.m"));
status = false;
}
}
}
return status;
}
private boolean verifyEntityLocalHome(EntityMetaData entity)
{
boolean status = true;
if (!hasEJBLocalHomeInterface(localHome))
{
fireSpecViolationEvent(entity, new Section("12.2.11.a"));
status = false;
}
Iterator homeMethods = Arrays.asList(localHome.getMethods()).iterator();
while (homeMethods.hasNext())
{
Method method = (Method)homeMethods.next();
if (throwsRemoteException(method))
{
fireSpecViolationEvent(entity, method, new Section("12.2.11.b"));
status = false;
}
}
homeMethods = Arrays.asList(localHome.getMethods()).iterator();
while (homeMethods.hasNext())
{
Method method = (Method)homeMethods.next();
if (method.getDeclaringClass().getName().equals(EJB_LOCAL_HOME_INTERFACE))
continue;
if (isCreateMethod(method))
{
if (!hasMatchingEJBCreate(bean, method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.11.e"));
status = false;
}
if (!hasLocalReturnType(entity, method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.11.f"));
status = false;
}
if (hasMatchingEJBCreate(bean, method)
&& hasMatchingEJBPostCreate(bean, method))
{
Method ejbCreate = getMatchingEJBCreate(bean, method);
Method ejbPostCreate = getMatchingEJBPostCreate(bean, method);
if (!(hasMatchingExceptions(ejbCreate, method)
&& hasMatchingExceptions(ejbPostCreate, method)))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.11.g"));
}
}
if (!throwsCreateException(method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.11.h"));
status = false;
}
}
else if (isFinderMethod(method))
{
if (!(hasLocalReturnType(entity, method)
|| isMultiObjectFinder(method)))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.11.j"));
status = false;
}
if (!throwsFinderException(method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.11.k"));
status = false;
}
if (entity.isCMP())
{
if (hasMatchingEJBFind(bean, method))
{
fireSpecViolationEvent(entity, method,
new Section("10.6.2.j"));
status = false;
}
if (!method.getName().equals("findByPrimaryKey")
&& !method.getName().equals("findAll")
&& !hasMatchingQuery(method, entity))
{
fireSpecViolationEvent(entity, method,
new Section("10.5.6"));
status = false;
}
}
if (entity.isBMP())
{
if (!hasMatchingEJBFind(bean, method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.11.i"));
status = false;
}
else
{
Method ejbFind = getMatchingEJBFind(bean, method);
if (!(hasMatchingExceptions(ejbFind, method)))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.11.l"));
}
}
}
}
else
{
if (!hasMatchingEJBHome(bean, method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.11.m"));
status = false;
}
}
}
return status;
}
private boolean verifyEntityLocal(EntityMetaData entity)
{
boolean status = true;
if (!hasEJBLocalObjectInterface(local))
{
fireSpecViolationEvent(entity, new Section("12.2.10.a"));
status = false;
}
Iterator localMethods = Arrays.asList(local.getMethods()).iterator();
while (localMethods.hasNext())
{
Method method = (Method)localMethods.next();
if (throwsRemoteException(method))
{
fireSpecViolationEvent(entity, method, new Section("12.2.10.b"));
status = false;
}
}
localMethods = Arrays.asList(local.getMethods()).iterator();
while (localMethods.hasNext())
{
Method method = (Method)localMethods.next();
if (method.getDeclaringClass().getName().equals(EJB_LOCAL_OBJECT_INTERFACE))
continue;
if (!hasMatchingMethod(bean, method))
{
fireSpecViolationEvent(entity, method, new Section("12.2.10.c"));
status = false;
}
if (hasMatchingMethod(bean, method))
{
try
{
Method beanMethod = bean.getMethod(method.getName(),
method.getParameterTypes());
if (!hasMatchingReturnType(beanMethod, method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.10.d"));
status = false;
}
if (!hasMatchingExceptions(beanMethod, method))
{
fireSpecViolationEvent(entity, method,
new Section("12.2.10.e"));
status = false;
}
}
catch (NoSuchMethodException ignored)
{
}
}
}
return status;
}
private boolean verifyEntityRemote(EntityMetaData entity)
{
boolean status = true;
if (!hasEJBObjectInterface(remote))
{
fireSpecViolationEvent(entity, new Section("9.2.7.a"));
status = false;
}
Iterator it = Arrays.asList(remote.getMethods()).iterator();
while (it.hasNext())
{
Method method = (Method)it.next();
if (!hasLegalRMIIIOPArguments(method))
{
fireSpecViolationEvent(entity, method, new Section("9.2.7.b"));
status = false;
}
if (!hasLegalRMIIIOPReturnType(method))
{
fireSpecViolationEvent(entity, method, new Section("9.2.7.c"));
status = false;
}
if (!hasLegalRMIIIOPExceptionTypes(method))
{
fireSpecViolationEvent(entity, method, new Section("9.2.7.h"));
status = false;
}
if (!throwsRemoteException(method))
{
fireSpecViolationEvent(entity, method, new Section("9.2.7.d"));
status = false;
}
}
it = Arrays.asList(remote.getMethods()).iterator();
while (it.hasNext())
{
Method method = (Method)it.next();
if (method.getDeclaringClass().getName().equals(EJB_OBJECT_INTERFACE))
continue;
if (!hasMatchingMethod(bean, method))
{
fireSpecViolationEvent(entity, method, new Section("9.2.7.e"));
status = false;
}
if (hasMatchingMethod(bean, method))
{
try
{
Method beanMethod = bean.getMethod(method.getName(),
method.getParameterTypes());
if (!hasMatchingReturnType(beanMethod, method))
{
fireSpecViolationEvent(entity, method,
new Section("9.2.7.f"));
status = false;
}
if (!hasMatchingExceptions(beanMethod, method))
{
fireSpecViolationEvent(entity, method,
new Section("9.2.7.g"));
status = false;
}
}
catch (NoSuchMethodException ignored)
{
}
}
}
return status;
}
private boolean verifyCMPEntityBean(EntityMetaData entity)
{
boolean status = true;
if (!hasEntityBeanInterface(bean))
{
fireSpecViolationEvent(entity, new Section("10.6.2.a"));
status = false;
}
if (!isPublic(bean) || !isAbstract(bean))
{
fireSpecViolationEvent(entity, new Section("10.6.2.b"));
status = false;
}
if (!hasDefaultConstructor(bean))
{
fireSpecViolationEvent(entity, new Section("10.6.2.c"));
status = false;
}
if (hasFinalizer(bean))
{
fireSpecViolationEvent(entity, new Section("10.6.2.d"));
status = false;
}
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;
}
if (!throwsCreateException(ejbCreate))
{
fireSpecViolationEvent(entity, ejbCreate,
new Section("10.6.4.g"));
status = false;
}
}
}
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;
}
}
}
}
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;
}
}
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();
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();
if (fieldType != Void.TYPE)
{
fireSpecViolationEvent(entity,
new Section("jb.7.1.a", "Field: " + fieldName));
}
}
catch (NoSuchMethodException nsme)
{
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)
{
}
}
}
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;
}
}
if (hasFinderMethod(bean))
{
fireSpecViolationEvent(entity, new Section("10.6.2.i"));
status = false;
}
return status;
}
private boolean verifyBMPEntityBean(EntityMetaData entity)
{
boolean status = true;
if (!hasEntityBeanInterface(bean))
{
fireSpecViolationEvent(entity, new Section("12.2.2.a"));
status = false;
}
if (!isPublic(bean) || isAbstract(bean))
{
fireSpecViolationEvent(entity, new Section("12.2.2.b"));
status = false;
}
if (isFinal(bean))
{
fireSpecViolationEvent(entity, new Section("12.2.2.c"));
status = false;
}
if (!hasDefaultConstructor(bean))
{
fireSpecViolationEvent(entity, new Section("12.2.2.d"));
status = false;
}
if (hasFinalizer(bean))
{
fireSpecViolationEvent(entity, new Section("12.2.2.e"));
status = false;
}
if (hasEJBCreateMethod(bean, false))
{
Iterator it = getEJBCreateMethods(bean);
while (it.hasNext())
{
Method ejbCreate = (Method)it.next();
if (!isPublic(ejbCreate))
{
fireSpecViolationEvent(entity, ejbCreate,
new Section("12.2.3.a"));
status = false;
}
if ((isFinal(ejbCreate)) || (isStatic(ejbCreate)))
{
fireSpecViolationEvent(entity, ejbCreate,
new Section("12.2.3.b"));
status = false;
}
if (!hasPrimaryKeyReturnType(entity, ejbCreate))
{
fireSpecViolationEvent(entity, ejbCreate,
new Section("12.2.3.c"));
status = false;
}
}
}
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("12.2.4.a"));
status = false;
}
if (hasMatchingEJBPostCreate(bean, ejbCreate))
{
Method ejbPostCreate = getMatchingEJBPostCreate(bean,
ejbCreate);
if (!isPublic(ejbPostCreate))
{
fireSpecViolationEvent(entity, ejbPostCreate,
new Section("12.2.4.b"));
status = false;
}
if (isStatic(ejbPostCreate) || isFinal(ejbPostCreate))
{
fireSpecViolationEvent(entity, ejbPostCreate,
new Section("12.2.4.c"));
status = false;
}
if (!hasVoidReturnType(ejbPostCreate))
{
fireSpecViolationEvent(entity, ejbPostCreate,
new Section("12.2.4.d"));
status = false;
}
}
}
}
if (!hasEJBFindByPrimaryKey(bean))
{
fireSpecViolationEvent(entity, new Section("12.2.5.e"));
status = false;
}
if (hasEJBFindByPrimaryKey(bean))
{
Method ejbFindByPrimaryKey = getEJBFindByPrimaryKey(bean);
if (!hasPrimaryKeyReturnType(entity, ejbFindByPrimaryKey))
{
fireSpecViolationEvent(entity, ejbFindByPrimaryKey,
new Section("12.2.5.e1"));
status = false;
}
if (!isSingleObjectFinder(entity, ejbFindByPrimaryKey))
{
fireSpecViolationEvent(entity, ejbFindByPrimaryKey,
new Section("12.2.5.e2"));
status = false;
}
}
if (hasFinderMethod(bean))
{
Iterator it = getEJBFindMethods(bean);
while (it.hasNext())
{
Method finder = (Method)it.next();
if (!isPublic(finder))
{
fireSpecViolationEvent(entity, finder, new Section("12.2.5.a"));
status = false;
}
if (isFinal(finder) || isStatic(finder))
{
fireSpecViolationEvent(entity, finder, new Section("12.2.5.b"));
status = false;
}
if (!(isSingleObjectFinder(entity, finder)
|| isMultiObjectFinder(finder)))
{
fireSpecViolationEvent(entity, finder, new Section("12.2.5.d"));
status = false;
}
}
}
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;
}
}
return status;
}
private boolean verifyPrimaryKey(EntityMetaData entity)
{
boolean status = true;
boolean cmp = entity.isCMP();
if (entity.getPrimaryKeyClass() == null
|| entity.getPrimaryKeyClass().length() == 0)
{
if (cmp)
fireSpecViolationEvent(entity, new Section("10.6.1.a"));
else
fireSpecViolationEvent(entity, new Section("12.2.1.a"));
return false;
}
Class cls = null;
try
{
cls = classloader.loadClass(entity.getPrimaryKeyClass());
}
catch (ClassNotFoundException e)
{
if (cmp)
fireSpecViolationEvent(entity, new Section("10.6.13.a"));
else
fireSpecViolationEvent(entity, new Section("12.2.12.a"));
return false;
}
if (!isRMIIDLValueType(cls))
{
if (cmp)
fireSpecViolationEvent(entity, new Section("10.6.13.b"));
else
fireSpecViolationEvent(entity, new Section("12.2.12.b"));
status = false;
}
if (entity.getPrimKeyField() == null ||
entity.getPrimKeyField().length() == 0)
{
if (!cls.getName().equals("java.lang.Object"))
{
Object one, two;
try
{
one = cls.newInstance();
two = cls.newInstance();
try
{
if (!one.equals(two))
{
if (cmp)
{
log.warn("Default instances of primary key: " + cls
+ " do not equate, check your equals method");
}
else
{
log.warn("Default instances of primary key: " + cls
+ " do not equate, check your equals method");
}
status = true;
}
}
catch (NullPointerException e)
{
}
try
{
if (one.hashCode() != two.hashCode())
{
if (cmp)
{
log.warn("Default instances of primary key: " + cls
+ " do not have the same hash, check your hashCode method");
}
else
{
log.warn("Default instances of primary key: " + cls
+ " do not have the same hash, check your hashCode method");
}
status = true;
}
}
catch (NullPointerException e)
{
}
}
catch (IllegalAccessException e)
{
if (cmp)
{
fireSpecViolationEvent(entity, new Section("10.8.2.a"));
status = false;
}
}
catch (InstantiationException e)
{
}
}
}
else
{
if (entity.isBMP())
{
fireSpecViolationEvent(entity, new Section("dd.a"));
status = false;
}
boolean found = false;
Iterator it = entity.getCMPFields();
while (it.hasNext())
{
String fieldName = (String)it.next();
if (fieldName.equals(entity.getPrimKeyField()))
{
found = true;
break;
}
}
if (!found)
{
status = false;
fireSpecViolationEvent(entity, new Section("10.8.1.b"));
}
try
{
String pkField = entity.getPrimKeyField();
String methodName = "get" +
pkField.substring(0, 1).toUpperCase() + pkField.substring(1);
Method method = bean.getMethod(methodName, new Class[0]);
if (!entity.getPrimaryKeyClass().equals(method.getReturnType().getName())
)
{
status = false;
fireSpecViolationEvent(entity, new Section("10.8.1.a"));
}
}
catch (NoSuchMethodException e)
{
status = false;
fireSpecViolationEvent(entity, new Section("10.8.1.b"));
}
}
return status;
}
protected boolean verifyMessageDrivenBean(MessageDrivenMetaData mdBean)
{
boolean status = true;
if (!hasMessageDrivenBeanInterface(bean))
{
fireSpecViolationEvent(mdBean, new Section("15.7.2.a"));
status = false;
}
if (!hasMessageListenerInterface(bean))
{
fireSpecViolationEvent(mdBean, new Section("15.7.2.b"));
status = false;
}
if (!isPublic(bean))
{
fireSpecViolationEvent(mdBean, new Section("15.7.2.c1"));
status = false;
}
if (isFinal(bean))
{
fireSpecViolationEvent(mdBean, new Section("15.7.2.c2"));
status = false;
}
if (isAbstract(bean))
{
fireSpecViolationEvent(mdBean, new Section("15.7.2.c3"));
status = false;
}
if (!hasDefaultConstructor(bean))
{
fireSpecViolationEvent(mdBean, new Section("15.7.2.d"));
status = false;
}
if (hasFinalizer(bean))
{
fireSpecViolationEvent(mdBean, new Section("15.7.2.e"));
status = false;
}
if (hasEJBCreateMethod(bean, false))
{
Iterator it = getEJBCreateMethods(bean);
Method ejbCreate = (Method)it.next();
if (!isPublic(ejbCreate))
{
fireSpecViolationEvent(mdBean, ejbCreate, new Section("15.7.3.b"));
status = false;
}
if ((isFinal(ejbCreate)) || (isStatic(ejbCreate)))
{
fireSpecViolationEvent(mdBean, ejbCreate, new Section("15.7.3.c"));
status = false;
}
if (!hasVoidReturnType(ejbCreate))
{
fireSpecViolationEvent(mdBean, ejbCreate, new Section("15.7.3.d"));
status = false;
}
if (!hasNoArguments(ejbCreate))
{
fireSpecViolationEvent(mdBean, ejbCreate, new Section("15.7.3.e"));
status = false;
}
if (!throwsNoException(ejbCreate))
{
fireSpecViolationEvent(mdBean, ejbCreate, new Section("15.7.3.f"));
status = false;
}
if (it.hasNext())
{
fireSpecViolationEvent(mdBean, new Section("15.7.3.a"));
status = false;
}
}
else
{
fireSpecViolationEvent(mdBean, new Section("15.7.3.a"));
status = false;
}
if (hasOnMessageMethod(bean))
{
Iterator it = getOnMessageMethods(bean);
Method onMessage = (Method)it.next();
if (!isPublic(onMessage))
{
fireSpecViolationEvent(mdBean, onMessage, new Section("15.7.4.b"));
status = false;
}
if ((isFinal(onMessage)) || (isStatic(onMessage)))
{
fireSpecViolationEvent(mdBean, onMessage, new Section("15.7.4.c"));
status = false;
}
try
{
Class message = classloader.loadClass("javax.jms.Message");
if (!hasSingleArgument(onMessage, message))
{
fireSpecViolationEvent(mdBean, onMessage,
new Section("15.7.4.e"));
status = false;
}
if (!throwsNoException(onMessage))
{
fireSpecViolationEvent(mdBean, onMessage,
new Section("15.7.4.f"));
status = false;
}
if (it.hasNext())
{
fireSpecViolationEvent(mdBean, new Section("15.7.4.a"));
status = false;
}
}
catch (ClassNotFoundException cnfe)
{
}
}
else
{
fireSpecViolationEvent(mdBean, new Section("15.7.4.a"));
status = false;
}
if (hasEJBRemoveMethod(bean))
{
Iterator it = getEJBRemoveMethods(bean);
Method ejbRemove = (Method)it.next();
if (!isPublic(ejbRemove))
{
fireSpecViolationEvent(mdBean, ejbRemove, new Section("15.7.5.b"));
status = false;
}
if ((isFinal(ejbRemove)) || (isStatic(ejbRemove)))
{
fireSpecViolationEvent(mdBean, ejbRemove, new Section("15.7.5.c"));
status = false;
}
if (!hasVoidReturnType(ejbRemove))
{
fireSpecViolationEvent(mdBean, ejbRemove, new Section("15.7.5.d"));
status = false;
}
if (!hasNoArguments(ejbRemove))
{
fireSpecViolationEvent(mdBean, ejbRemove, new Section("15.7.5.e"));
status = false;
}
if (!throwsNoException(ejbRemove))
{
fireSpecViolationEvent(mdBean, ejbRemove, new Section("15.7.5.f"));
status = false;
}
if (it.hasNext())
{
fireSpecViolationEvent(mdBean, new Section("15.7.5.a"));
status = false;
}
}
else
{
fireSpecViolationEvent(mdBean, new Section("15.7.5.a"));
status = false;
}
return status;
}
}