From: Roland Haeder Date: Fri, 14 Aug 2015 21:05:09 +0000 (+0200) Subject: Long story, short purpose. Short story, long purpose ... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=276df5c7f83afb2c1f186013b9cca7c6ac7a3a37;p=jcore.git Long story, short purpose. Short story, long purpose ... Well, String is stored in database, but some getter require Long or Float which cannot be casted. So a hard-code "casting" needs to be added ... Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index c0cdc9c..8aa56cc 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -33,6 +33,7 @@ import java.util.Map; import java.util.Properties; import java.util.ResourceBundle; import java.util.StringTokenizer; +import java.util.logging.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.mxchange.jcore.application.Application; @@ -649,11 +650,14 @@ public class BaseFrameworkSystem implements FrameworkInterface { */ protected Object getField (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace messahe - this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N + this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},methodName={2}", instance, targetClass, methodName)); //NOI18N // Get method to call Method method = this.getMethodFromName(instance, targetClass, methodName); + // Debug message + this.getLogger().debug("method=" + method + ",instance=" + instance); + // Get value from field Object value = method.invoke(instance); @@ -678,7 +682,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { */ protected void setField (final FrameworkInterface instance, final String targetClass, final String methodName, final String columnName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace messahe - this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1},value={2}", targetClass, methodName, value)); //NOI18N + this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},methodName={2},value={3}", instance, targetClass, methodName, value)); //NOI18N // Get field type Class type = this.getType(instance, targetClass, columnName); @@ -686,11 +690,39 @@ public class BaseFrameworkSystem implements FrameworkInterface { // Debug message this.getLogger().debug("type=" + type); + // Init object + Object object = value; + + // Hard-coded "cast" again ... :-( + // @TODO Can't we get rid of this??? + switch (type.getSimpleName()) { + case "Long": // Long object + object = Long.parseLong((String) value); + break; + + case "Float": // Float object + object = Float.parseFloat((String) value); + break; + + case "Object": // General object + case "String": // String object + break; + + default: // Unsupported type + throw new IllegalArgumentException("value " + value + " has unsupported type " + type.getSimpleName()); + } + + // Debug message + this.getLogger().debug("object[" + object.getClass().getSimpleName() + "]=" + object); + // Get method to call Method method = this.getMethodFromName(instance, targetClass, methodName, type); + // Debug message + this.getLogger().debug("method=" + method + ",instance=" + instance + ",value[" + value.getClass().getSimpleName() + "]=" + value); + // Get value from field - method.invoke(instance, value); + method.invoke(instance, object); // Trace messahe this.getLogger().trace("EXIT!");