package org.jboss.verifier.strategy;
import org.jboss.metadata.EntityMetaData;
import org.jboss.metadata.QueryMetaData;
import org.jboss.util.Classes;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public abstract class AbstractEJB2xVerifier extends AbstractVerifier
{
protected EJBVerifier11 cmp1XVerifier;
protected Class bean;
protected Class home;
protected Class remote;
protected Class localHome;
protected Class local;
protected Class serviceEndpointInterface;
public AbstractEJB2xVerifier(VerificationContext context)
{
super(context);
}
public boolean isCreateMethod(Method m)
{
return m.getName().startsWith(CREATE_METHOD);
}
public boolean isEjbCreateMethod(Method m)
{
return m.getName().startsWith(EJB_CREATE_METHOD);
}
public boolean isEjbRemoveMethod(Method m)
{
return m.getName().startsWith(EJB_REMOVE_METHOD);
}
public boolean isEjbSelectMethod(Method m)
{
return m.getName().startsWith(EJB_SELECT_METHOD);
}
public boolean isEjbHomeMethod(Method m)
{
return m.getName().startsWith(EJB_HOME_METHOD);
}
public boolean hasRemoteInterface(Class c)
{
return isAssignableFrom("java.rmi.Remote", c);
}
public Iterator getEjbSelectMethods(Class c)
{
List selects = new LinkedList();
Method[] method = c.getMethods();
for (int i = 0; i < method.length; ++i)
{
if (isEjbSelectMethod(method[i]))
{
selects.add(method[i]);
}
}
return selects.iterator();
}
public boolean hasEJBRemoveMethod(Class c)
{
Method[] method = c.getMethods();
for (int i = 0; i < method.length; ++i)
{
if (isEjbRemoveMethod(method[i]))
return true;
}
return false;
}
public Iterator getEJBRemoveMethods(Class c)
{
List ejbRemoves = new LinkedList();
Method[] method = c.getMethods();
for (int i = 0; i < method.length; ++i)
{
if (isEjbRemoveMethod(method[i]))
ejbRemoves.add(method[i]);
}
return ejbRemoves.iterator();
}
public Iterator getHomeMethods(Class c)
{
List homes = new LinkedList();
Method[] method = c.getMethods();
for (int i = 0; i < method.length; ++i)
{
if (!isCreateMethod(method[i]) && !isFinderMethod(method[i]))
homes.add(method[i]);
}
return homes.iterator();
}
public Iterator getEjbHomeMethods(Class c)
{
List homes = new LinkedList();
Method[] method = c.getMethods();
for (int i = 0; i < method.length; ++i)
{
if (isEjbHomeMethod(method[i]))
homes.add(method[i]);
}
return homes.iterator();
}
protected boolean hasMatchingQuery(Method m, EntityMetaData e)
{
boolean result = false;
Iterator qIt = e.getQueries();
while (qIt.hasNext())
{
QueryMetaData qmd = (QueryMetaData)qIt.next();
if (!qmd.getMethodName().equals(m.getName()))
{
continue;
}
Class[] methodParameter = m.getParameterTypes();
Class[] queryParameter = null;
try
{
queryParameter = Classes.convertToJavaClasses(qmd.getMethodParams(), classloader);
}
catch (ClassNotFoundException cnfe)
{
continue;
}
if (methodParameter.length != queryParameter.length)
{
continue;
}
boolean parametersMatch = true;
for (int i = 0; i < methodParameter.length; i++)
{
if (!methodParameter[i].equals(queryParameter[i]))
{
parametersMatch = false;
break;
}
}
if (parametersMatch)
{
result = true;
break;
}
}
return result;
}
}