bug fixed for reflect

This commit is contained in:
wenshao
2012-08-10 12:40:42 +08:00
parent 139b5c9751
commit 29e3b0158c
2 changed files with 22 additions and 3 deletions
@@ -3,12 +3,21 @@ package com.alibaba.druid.stat;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.druid.util.ReflectionUtils;
public class DruidDataSourceStatJNDIStatStrategy implements DruidDataSourceStatStrategy{
private final static Log LOG = LogFactory.getLog(DruidDataSourceStatJNDIStatStrategy.class);
private Object getStrategyB() {
return ReflectionUtils.getClassFromWebContainerOrCurrentClassLoader("com.alibaba.druid.stat.DruidDataSourceStatDefaultStrategy");
try {
Class<?> clazz = ReflectionUtils.getClassFromWebContainerOrCurrentClassLoader("com.alibaba.druid.stat.DruidDataSourceStatDefaultStrategy");
return clazz.newInstance();
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return null;
}
}
@SuppressWarnings("unchecked")
@@ -42,10 +42,20 @@ public class ReflectionUtils {
}
}
public static Object callObjectMethod(Object obj, String methodName, Object... methodParams) {
public static Object callObjectMethod(Object obj, String methodName) {
try {
Method m = obj.getClass().getMethod(methodName);
return m.invoke(obj, methodParams);
return m.invoke(obj);
} catch (Exception e) {
LOG.warn("callObjectMethod fail:class=" + obj.getClass().getName() + " method=" + methodName, e);
return null;
}
}
public static Object callObjectMethod(Object obj, String methodName, Integer id) {
try {
Method m = obj.getClass().getMethod(methodName, Integer.class);
return m.invoke(obj, id);
} catch (Exception e) {
LOG.warn("callObjectMethod fail:class=" + obj.getClass().getName() + " method=" + methodName, e);
return null;