From 38a371a12489b9baf04da99ae89909b827817407 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 14 Aug 2015 21:41:40 +0200 Subject: [PATCH] =?utf8?q?Introduced=20getMethodFromName()=20with=20value?= =?utf8?q?=20check=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../mxchange/jcore/BaseFrameworkSystem.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index 6cc490e..f6a1cb5 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -234,6 +234,38 @@ public class BaseFrameworkSystem implements FrameworkInterface { return method; } + /** + * Some "getter" for a Method instance from given method name + * + * @param instance Actual instance to call + * @param targetClass Target class name + * @param methodName Method name + * @param value Value to check type from + * @return A Method instance + */ + private Method getMethodFromName (final FrameworkInterface instance, final String targetClass, final String methodName, final Object value) throws NoSuchMethodException { + // Trace messahe + this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N + + // Get target class instance + Class c = this.getClassFromTarget(instance, targetClass); + + // Init field instance + Method method = null; + + // Use reflection to get all attributes + method = c.getDeclaredMethod(methodName, value.getClass()); + + // Assert on field + assert (method instanceof Method) : "method is not a Method instance"; //NOI18N + + // Trace message + this.getLogger().trace(MessageFormat.format("method={0} - EXIT!", method)); //NOI18N + + // Return it + return method; + } + /** * Setter for self instance */ @@ -591,7 +623,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N // Get method instance - Method method = this.getMethodFromName(instance, targetClass, methodName); + Method method = this.getMethodFromName(instance, targetClass, methodName, value); // Try to get the value by invoking the method method.invoke(instance, value); @@ -653,7 +685,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1},value={2}", targetClass, methodName, value)); //NOI18N // Get method to call - Method method = this.getMethodFromName(instance, targetClass, methodName); + Method method = this.getMethodFromName(instance, targetClass, methodName, value); // Get value from field method.invoke(instance, value); -- 2.39.5