From 57b33acd23d2117c021d169548877aff9cdd06b4 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 7 Aug 2015 13:27:32 +0200 Subject: [PATCH] =?utf8?q?Some=20fixes=20Signed-off-by:Roland=20H=C3=A4der?= =?utf8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../mxchange/jcore/BaseFrameworkSystem.java | 32 +++++++++++++++---- .../mxchange/jcore/FrameworkInterface.java | 3 +- .../mxchange/jcore/contact/BaseContact.java | 13 ++++++-- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index 5f74161..33923f8 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -175,9 +175,10 @@ public class BaseFrameworkSystem implements FrameworkInterface { * * @param columnName Column name * @return Value from field + * @throws IllegalArgumentException Some implementations may throw this. */ @Override - public Object getValueFromColumn (final String columnName) { + public Object getValueFromColumn (final String columnName) throws IllegalArgumentException { throw new UnsupportedOperationException(MessageFormat.format("Not implemented. columnName={0}", columnName)); //NOI18N } @@ -554,7 +555,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { } /** - * Returns boolean field value from given method call + * Returns boolean field value from given method name by invoking it * * @param instance The instance to call * @param targetClass Target class to look in @@ -598,7 +599,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { } /** - * Returns any field value from given method call + * Returns any field value from given method name by invoking it * * @param instance The instance to call * @param targetClass Target class to look in @@ -753,8 +754,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { } /** - * Creates an iterator from given instance and class name. The class name - * is required in getValueFromColumn() to make a proper call. + * Creates an iterator from given instance and class name. * * @param instance Instance to run getter calls on * @param className Class name to iterate over @@ -765,18 +765,36 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.getLogger().trace(MessageFormat.format("instance={0},className={1} - CALLED!", instance, className)); // Get all attributes from given instance - Field[] fields = instance.getClass().getDeclaredFields(); + Field[] fields = this.getClassFromTarget(instance, className).getDeclaredFields(); + + // Debug message + this.getLogger().debug(MessageFormat.format("Found {0} fields.", fields.length)); // A list is fine List list = new ArrayList<>(fields.length); // Walk through all for (final Field field : fields) { + // Debug log + this.getLogger().debug(MessageFormat.format("field={0}", field.getName())); + + // Does the field start with "$"? + if (field.getName().startsWith("$")) { + // Skip it silently + continue; + } + // Get value from it Object value = this.getValueFromColumn(field.getName()); + // Debug message + this.getLogger().debug(MessageFormat.format("value={0}", value)); + // Add it to list - assert(list.add(value)) : MessageFormat.format("value {0} has not been added", value); + boolean added = list.add(value); + + // Debug log + this.getLogger().debug("added=" + added); } // Debug message diff --git a/src/org/mxchange/jcore/FrameworkInterface.java b/src/org/mxchange/jcore/FrameworkInterface.java index 71ddb00..57c6436 100644 --- a/src/org/mxchange/jcore/FrameworkInterface.java +++ b/src/org/mxchange/jcore/FrameworkInterface.java @@ -95,6 +95,7 @@ public interface FrameworkInterface { * * @param columnName Column name * @return Value from field + * @throws IllegalArgumentException Some implementations may throw this */ - public Object getValueFromColumn (final String columnName); + public Object getValueFromColumn (final String columnName) throws IllegalArgumentException; } diff --git a/src/org/mxchange/jcore/contact/BaseContact.java b/src/org/mxchange/jcore/contact/BaseContact.java index 9085faa..2465158 100644 --- a/src/org/mxchange/jcore/contact/BaseContact.java +++ b/src/org/mxchange/jcore/contact/BaseContact.java @@ -480,14 +480,23 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * @return Value from field */ @Override - public Object getValueFromColumn (final String columnName) { + public Object getValueFromColumn (final String columnName) throws IllegalArgumentException { // Trace message this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName)); + // A '$' means not our field + if (columnName.startsWith("$")) { + // Don't handle these + throw new IllegalArgumentException("columnsName contains $"); + } + // Determine if the given column is boolean if (this.isBooleanField(this, "BaseContact", columnName)) { + // Debug message + this.getLogger().debug("Column " + columnName + " represents a boolean field."); + // Yes, then call other method - return this.getBooleanField(this, "BaseContact", columnName); + return this.getBooleanField(this, "BaseContact", this.convertColumnNameToGetterMethod(columnName, true)); } // Convert column name to field name -- 2.39.5