if (_returnTypeClass.isAssignableFrom(val.getClass())) {
return val;
}
}
} catch (SQLException e) {
throw new ControlException(e.getMessage(), e);
}
}
if (_setterMethods == null) {
try {
getResultSetMappings();
} catch (SQLException e) {
throw new ControlException(e.getMessage(), e);
}
}
resultObject = XmlObject.Factory.newInstance(new XmlOptions().setDocumentType(_schemaType));
for (int i = 1; i < _setterMethods.length; i++) {
Method setterMethod = _setterMethods[i].getSetter();
Object resultValue = null;
try {
resultValue = extractColumnValue(i, _setterMethods[i].getParameterType());
// if the setter is for an xmlbean enum type, convert the extracted resultset column
// value to the proper xmlbean enum type. All xmlbean enums are derived from the class
// StringEnumAbstractBase
if (_setterMethods[i].getParameterType() == TypeMappingsFactory.TYPE_XMLBEAN_ENUM) {
Class parameterClass = _setterMethods[i].getParameterClass();
Method m = parameterClass.getMethod("forString", new Class[]{String.class});
resultValue = m.invoke(null, new Object[]{resultValue});
}
_args[0] = resultValue;
setterMethod.invoke(resultObject, _args);
if (_setterMethods[i].getNilable() != null) {
if (_resultSet.wasNull()) {
_setterMethods[i].getNilable().invoke(resultObject, (Object[]) null);
}
}
} catch (SQLException se) {
throw new ControlException(se.getMessage(), se);
} catch (IllegalArgumentException iae) {
try {
ResultSetMetaData md = _resultSet.getMetaData();
throw new ControlException("The declared Java type for method " + setterMethod.getName()
+ setterMethod.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) {
throw new ControlException("IllegalAccessException when trying to access method " + setterMethod.getName(), e);
} catch (NoSuchMethodException e) {
throw new ControlException("NoSuchMethodException when trying to map schema enum value using Enum.forString().", e);
} catch (InvocationTargetException e) {
throw new ControlException("IllegalInvocationException when trying to access method " + setterMethod.getName(), e);
}
}
return resultObject;
}