if (_returnTypeClass.isAssignableFrom(val.getClass())) {
return val;
}
}
} catch (SQLException e) {
throw new ControlException(e.getMessage(), e);
}
}
if (_fields == null) {
try {
getFieldMappings();
} catch (SQLException e) {
throw new ControlException(e.getMessage(), e);
}
}
try {
resultObject = _returnTypeClass.newInstance();
} catch (InstantiationException e) {
throw new ControlException("InstantiationException when trying to create instance of : "
+ _returnTypeClass.getName(), e);
} catch (IllegalAccessException e) {
throw new ControlException("IllegalAccessException when trying to create instance of : "
+ _returnTypeClass.getName(), e);
}
for (int i = 1; i < _fields.length; i++) {
AccessibleObject f = _fields[i];
Object resultValue = null;
try {
resultValue = extractColumnValue(i, _fieldTypes[i]);
if (f instanceof Field) {
((Field) f).set(resultObject, resultValue);
} else {
_args[0] = resultValue;
((Method) f).invoke(resultObject, _args);
}
} catch (SQLException e) {
throw new ControlException(e.getMessage(), e);
} catch (IllegalArgumentException iae) {
try {
ResultSetMetaData md = _resultSet.getMetaData();
if (f instanceof Field) {
throw new ControlException("The declared Java type for field " + ((Field) f).getName()
+ ((Field) f).getType().toString()
+ " is incompatible with the SQL format of column " + md.getColumnName(i).toString()
+ md.getColumnTypeName(i).toString()
+ " which returns objects of type " + resultValue.getClass().getName());
} else {
throw new ControlException("The declared Java type for method " + ((Method) f).getName()
+ ((Method) f).getParameterTypes()[0].toString()
+ " is incompatible with the SQL format of column " + md.getColumnName(i).toString()
+ md.getColumnTypeName(i).toString()
+ " which returns objects of type " + resultValue.getClass().getName());
}
} catch (SQLException e) {
throw new ControlException(e.getMessage(), e);
}
} catch (IllegalAccessException e) {
if (f instanceof Field) {
throw new ControlException("IllegalAccessException when trying to access field " + ((Field) f).getName(), e);
} else {
throw new ControlException("IllegalAccessException when trying to access method " + ((Method) f).getName(), e);
}
} catch (InvocationTargetException e) {
if (f instanceof Field) {
throw new ControlException("InvocationTargetException when trying to access field " + ((Field) f).getName(), e);
} else {
throw new ControlException("InvocationTargetException when trying to access method " + ((Method) f).getName(), e);
}
}
}
return resultObject;
}