[jboss-cvs] JBossAS SVN: r106805 - projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 19 04:31:03 EDT 2010
Author: jaikiran
Date: 2010-07-19 04:31:03 -0400 (Mon, 19 Jul 2010)
New Revision: 106805
Modified:
projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/AutoTimerInitializer.java
Log:
EJBTHREE-2125 Fixed a bug in finding the right method
Modified: projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/AutoTimerInitializer.java
===================================================================
--- projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/AutoTimerInitializer.java 2010-07-19 08:17:14 UTC (rev 106804)
+++ projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/AutoTimerInitializer.java 2010-07-19 08:31:03 UTC (rev 106805)
@@ -30,6 +30,7 @@
import org.jboss.beans.metadata.api.annotations.Start;
import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.common.lang.ClassHelper;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBean31MetaData;
@@ -170,8 +171,8 @@
{
methodStringBuilder.append(Arrays.toString(timeoutMethodMetaData.getMethodParams().toArray()));
}
- throw new IllegalStateException("Timeout method: " + methodStringBuilder.toString() + " not found for bean class: "
- + enterpriseBeanMetaData.getEjbClass());
+ throw new IllegalStateException("Timeout method: " + methodStringBuilder.toString()
+ + " not found for bean class: " + enterpriseBeanMetaData.getEjbClass());
}
// finally create/get the auto timer
ejb31TimerService.getAutoTimer(autoTimerMetaData.getScheduleExpression(), timerConfig, timeoutMethod);
@@ -195,58 +196,67 @@
String timeoutMethodName = timeoutMethodMetaData.getMethodName();
MethodParametersMetaData timeoutMethodParams = timeoutMethodMetaData.getMethodParams();
+
+ List<Method> probableTimeoutMethods = ClassHelper.getAllMethodsByName(beanClass, timeoutMethodName);
+ if (probableTimeoutMethods == null || probableTimeoutMethods.isEmpty())
+ {
+ return null;
+ }
+ if (timeoutMethodParams == null)
+ {
+ if (probableTimeoutMethods.size() > 1)
+ {
+ throw new IllegalStateException("Found more than one timeout method with name: " + timeoutMethodName
+ + " on bean " + beanClass);
+ }
+ // match found
+ return probableTimeoutMethods.get(0);
+ }
+
// load the method param classes
- Class<?>[] timeoutMethodParamTypes = new Class<?>[]
- {};
- if (timeoutMethodParams != null)
+ Class<?>[] timeoutMethodParamTypes = new Class<?>[timeoutMethodParams.size()];
+ int i = 0;
+ for (String paramClassName : timeoutMethodParams)
{
- timeoutMethodParamTypes = new Class<?>[timeoutMethodParams.size()];
- int i = 0;
- for (String paramClassName : timeoutMethodParams)
+ Class<?> methodParamClass = null;
+ try
{
- Class<?> methodParamClass = null;
- try
- {
- methodParamClass = Class.forName(paramClassName, false, beanClass.getClassLoader());
- }
- catch (ClassNotFoundException cnfe)
- {
- throw new RuntimeException("Could not load method param class: " + paramClassName + " of timeout method");
- }
- timeoutMethodParamTypes[i++] = methodParamClass;
+ methodParamClass = Class.forName(paramClassName, false, beanClass.getClassLoader());
}
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new RuntimeException("Could not load method param class: " + paramClassName + " of timeout method");
+ }
+ timeoutMethodParamTypes[i++] = methodParamClass;
}
- // now start looking for the method
- Class<?> klass = beanClass;
- while (klass != null)
+ for (Method method : probableTimeoutMethods)
{
- Method[] methods = klass.getDeclaredMethods();
- for (Method method : methods)
+ Class<?>[] methodParamTypes = method.getParameterTypes();
+ if (equals(timeoutMethodParamTypes, methodParamTypes))
{
- if (method.getName().equals(timeoutMethodName))
- {
- Class<?>[] methodParamTypes = method.getParameterTypes();
- // param length doesn't match
- if (timeoutMethodParamTypes.length != methodParamTypes.length)
- {
- continue;
- }
- for (int i = 0; i < methodParamTypes.length; i++)
- {
- // param type doesn't match
- if (timeoutMethodParamTypes[i].equals(methodParamTypes[i]) == false)
- {
- continue;
- }
- }
- // match found
- return method;
- }
+ // match found
+ return method;
}
- klass = klass.getSuperclass();
}
// no match found
return null;
}
+ private boolean equals(Class<?>[] params, Class<?>[] otherParams)
+ {
+
+ if (params.length != otherParams.length)
+ {
+ return false;
+ }
+ for (int i = 0; i < params.length; i++)
+ {
+ // param type doesn't match
+ if (!params[i].equals(otherParams[i]))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
}
More information about the jboss-cvs-commits
mailing list