Class<? extends FrameworkInterface> c = this.getClassFromTarget(instance, targetClass);
// Init field instance
- Method method = null;
-
- // Use reflection to get all attributes
- method = c.getDeclaredMethod(methodName, new Class<?>[0]);
+ Method method = c.getDeclaredMethod(methodName, new Class<?>[0]);
// Assert on field
assert (method instanceof Method) : "method is not a Method instance"; //NOI18N
* @param instance Actual instance to call
* @param targetClass Target class name
* @param methodName Method name
- * @param value Value to check type from
+ * @param type Type reflection 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 {
+ private Method getMethodFromName (final FrameworkInterface instance, final String targetClass, final String methodName, final Class<?> type) throws NoSuchMethodException {
// Trace messahe
- this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
+ this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1},type={2}", targetClass, methodName, type)); //NOI18N
// Get target class instance
Class<? extends FrameworkInterface> c = this.getClassFromTarget(instance, targetClass);
// Init field instance
- Method method = null;
-
- // Use reflection to get all attributes
- method = c.getDeclaredMethod(methodName, value.getClass());
+ Method method = c.getDeclaredMethod(methodName, type);
// Assert on field
assert (method instanceof Method) : "method is not a Method instance"; //NOI18N
Method method = this.getMethodFromName(instance, targetClass, methodName);
// Get value from field
- Boolean value = false;
-
- // Try to get the value by invoking the method
- value = (Boolean) method.invoke(instance);
+ Boolean value = (Boolean) method.invoke(instance);
// Trace message
this.getLogger().trace("value=" + value + " - EXIT!");
* @param instance The instance to call
* @param targetClass Target class to look in
* @param methodName Method name to look for
+ * @param columnName Column name
* @param value Boolean value from field
* @throws java.lang.NoSuchMethodException If the method was not found
* @throws java.lang.IllegalAccessException If the method cannot be accessed
* @throws java.lang.reflect.InvocationTargetException Some other problems?
*/
- protected void setBooleanField (final FrameworkInterface instance, final String targetClass, final String methodName, final Boolean value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ protected void setBooleanField (final FrameworkInterface instance, final String targetClass, final String methodName, final String columnName, final Boolean value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace messahe
this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
+ // Get field type
+ Class<?> type = this.getType(instance, targetClass, columnName);
+
// Get method instance
- Method method = this.getMethodFromName(instance, targetClass, methodName, value);
+ Method method = this.getMethodFromName(instance, targetClass, methodName, type);
// Try to get the value by invoking the method
method.invoke(instance, value);
* @param instance The instance to call
* @param targetClass Target class to look in
* @param methodName Method name to look for
+ * @param columnName Column name
* @param value Any value from field
* @throws java.lang.NoSuchMethodException If the method was not found
* @throws java.lang.IllegalAccessException If the method cannot be accessed
* @throws java.lang.reflect.InvocationTargetException Some other problems?
*/
- protected void setField (final FrameworkInterface instance, final String targetClass, final String methodName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ 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
+ // Get field type
+ Class<?> type = this.getType(instance, targetClass, columnName);
+
+ // Debug message
+ this.getLogger().debug("type=" + type);
+
// Get method to call
- Method method = this.getMethodFromName(instance, targetClass, methodName, value);
+ Method method = this.getMethodFromName(instance, targetClass, methodName, type);
// Get value from field
method.invoke(instance, value);
this.getLogger().debug("Column " + columnName + " represents a boolean field.");
// Yes, then call other method
- this.setBooleanField(instance, targetClass, this.convertColumnNameToSetterMethod(columnName), (Boolean) value);
+ this.setBooleanField(instance, targetClass, this.convertColumnNameToSetterMethod(columnName), columnName, (Boolean) value);
}
// Convert column name to field name
this.getLogger().debug(MessageFormat.format("methodName={0}", methodName));
// Get field
- this.setField(instance, targetClass, methodName, value);
+ this.setField(instance, targetClass, methodName, columnName, value);
// Trace message
this.getLogger().trace("EXIT!");
// Return value
return value;
}
+
+ /**
+ * Some getter for type reflection of given column name
+ *
+ * @param instance The instance to check
+ * @param targetClass Target class to check
+ * @param columnName Column name
+ * @return Type reflection of value
+ */
+ private Class<?> getType (final FrameworkInterface instance, final String targetClass, final String columnName) {
+ // Trace message
+ this.getLogger().trace("instance=" + instance + ",targetClass=" + targetClass + ",columnName=" + columnName + " - CALLED!");
+
+ // Init field tye
+ Class<?> type = null;
+
+ // Get all attributes from given instance
+ Field[] fields = this.getClassFromTarget(instance, targetClass).getDeclaredFields();
+
+ // Debug message
+ this.getLogger().debug("fields()=" + fields.length);
+
+ // Search for proper field instance
+ for (final Field field : fields) {
+ // Debug message
+ this.getLogger().debug("field=" + field);
+
+ // Does it match?
+ if (field.getName().equals(columnName)) {
+ // Found it
+ type = field.getType();
+ break;
+ }
+ }
+
+ // type should not be null
+ if (type == null) {
+ // No null allowed
+ throw new NullPointerException("type is null");
+ }
+
+ // Trace message
+ this.getLogger().debug("type=" + type + " - EXIT!");
+
+ // Return it
+ return type;
+ }
}