2009-06-29 23:56:03 UTC
After scanning and tracing through the java code, I formulated a fix that allows this Type extension to work. The StructBean class can be changed to:
...
public StructBean(final Object obj) {
try {
PropertyDescriptor[] props =
PropertyUtils.getPropertyDescriptors(obj);
Arrays.sort(props, new PropertyComparator());
for (int i = 0; i < props.length; i++) {
if (!"SQLTypeName".equals(props[i].getName())
&& !"class".equals(props[i].getName())
&& !"baseType".equals(props[i].getName())
&& !"baseTypeName".equals(props[i].getName())
&& !"descriptor".equals(props[i].getName())) {
String fieldName = props[i].getName();
Method readMethod = props[i].getReadMethod();
if (readMethod != null) {
Object fieldValue = readMethod.invoke(obj, new Object[0]);
FieldBean fBean;
if ("array".equals(props[i].getName())) {
Class<?> type = fieldValue.getClass();
if (type.isArray()) {
int length = Array.getLength(fieldValue);
for (int j = 0; j < length; j++) {
fBean = new FieldBean(fieldName, Array.get(fieldValue, j));
fields.add(fBean);
}
}
} else if (typeMap.containsValue(props[i].getPropertyType())) {
// Field is a nested struct
fBean = new FieldBean(fieldName, fieldValue);
fields.add(fBean);
} else {
// Field is a simple type
fBean = new FieldBean(fieldName,
(fieldValue == null) ? "NULL"
: fieldValue.toString());
fields.add(fBean);
}
}
}
}
} catch (Exception ex) {
LOG.error("Could not read bean: " + obj.toString(), ex);
}
}
...
The result XML for comparison would then look like:
...
<outparam id="1" type="STRUCT">
<struct>
<field name="array">
<struct>
<field name="description">Red rubber ball</field>
<field name="size">30</field>
</struct>
</field>
</struct>
</outparam>
...
Note that the field name "array" is always called array.
Cheers,
Marc.