aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-07-23 16:26:38 -0700
committerSven Gothel <[email protected]>2010-07-23 16:26:38 -0700
commitc0d853dbeea2f20988e0a2f909983b09042a6c52 (patch)
treef320d95807b7f4babdc32af52fbf822b98c6fd88 /src/java/com
parent1588ce5f3f6e899ad6528379e4947ecab588d49e (diff)
Split up method call for reusage
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/jogamp/common/util/ReflectionUtil.java47
1 files changed, 36 insertions, 11 deletions
diff --git a/src/java/com/jogamp/common/util/ReflectionUtil.java b/src/java/com/jogamp/common/util/ReflectionUtil.java
index cd4c062..a04ec73 100644
--- a/src/java/com/jogamp/common/util/ReflectionUtil.java
+++ b/src/java/com/jogamp/common/util/ReflectionUtil.java
@@ -212,25 +212,41 @@ public final class ReflectionUtil {
}
/**
- * @throws JogampRuntimeException if the instance can not be created.
+ * @throws JogampRuntimeException if the Method can not be found.
*/
- public static final Object callStaticMethod(String clazzName, String methodName, Class[] argTypes, Object[] args, ClassLoader cl)
+ public static final Method getMethod(Class clazz, String methodName, Class[] argTypes, ClassLoader cl)
throws JogampRuntimeException, RuntimeException
{
- Class clazz;
- try {
- clazz = getClassImpl(clazzName, true, cl);
- } catch (ClassNotFoundException ex) {
- throw new JogampRuntimeException(clazzName + " not available", ex);
- }
Method method;
try {
- method = clazz.getDeclaredMethod(methodName, argTypes);
+ return clazz.getDeclaredMethod(methodName, argTypes);
} catch (NoSuchMethodException ex) {
throw new JogampRuntimeException("Method: '" + clazz + "." + methodName + "(" + asString(argTypes) + ")' not found", ex);
}
+ }
+
+ /**
+ * @throws JogampRuntimeException if the Method can not be found.
+ */
+ public static final Method getMethod(String clazzName, String methodName, Class[] argTypes, ClassLoader cl)
+ throws JogampRuntimeException, RuntimeException
+ {
+ try {
+ return getMethod(getClassImpl(clazzName, true, cl), methodName, argTypes, cl);
+ } catch (ClassNotFoundException ex) {
+ throw new JogampRuntimeException(clazzName + " not available", ex);
+ }
+ }
+
+ /**
+ * @throws JogampRuntimeException if the call fails
+ * @throws RuntimeException if the call fails
+ */
+ public static final Object callMethod(Object instance, Method method, Object[] args)
+ throws JogampRuntimeException, RuntimeException
+ {
try {
- return method.invoke(null, args);
+ return method.invoke(instance, args);
} catch (Exception e) {
Throwable t = e;
if (t instanceof InvocationTargetException) {
@@ -242,8 +258,17 @@ public final class ReflectionUtil {
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
- throw new JogampRuntimeException("calling "+method+" of "+clazz+" failed", t);
+ throw new JogampRuntimeException("calling "+method+" failed", t);
}
}
+
+ /**
+ * @throws JogampRuntimeException if the instance can not be created.
+ */
+ public static final Object callStaticMethod(String clazzName, String methodName, Class[] argTypes, Object[] args, ClassLoader cl)
+ throws JogampRuntimeException, RuntimeException
+ {
+ return callMethod(null, getMethod(clazzName, methodName, argTypes, cl), args);
+ }
}