From: Roland Haeder Date: Fri, 14 Aug 2015 19:41:40 +0000 (+0200) Subject: Introduced getMethodFromName() with value check X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=38a371a12489b9baf04da99ae89909b827817407;p=jcore.git Introduced getMethodFromName() with value check Signed-off-by:Roland Häder --- 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);