]> git.mxchange.org Git - jcore.git/commitdiff
Long story, short purpose. Short story, long purpose ...
authorRoland Haeder <roland@mxchange.org>
Fri, 14 Aug 2015 21:05:09 +0000 (23:05 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 14 Aug 2015 21:05:09 +0000 (23:05 +0200)
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 <roland@mxchange.org>

src/org/mxchange/jcore/BaseFrameworkSystem.java

index c0cdc9c0b60effd4d05c13681b1c033be6d4906a..8aa56cca75a157dd1680eda7ca3538187bf10b85 100644 (file)
@@ -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!");