Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 0.9.4.2, 1.0, 1.0.1, 1.0.2, 1.0.3
-
Fix Version/s: 1.0.4
-
Component/s: XML code generator
-
Labels:None
-
Environment:Operating System: Windows 2000
Platform: PC
-
Bugzilla Id:1273
Description
As opposed to what the comment in XMLFieldHandler.resetValue says
//-- Do nothing, this method is overloaded by the
//-- source code generator
the Source Generator doesn't generate the resetValue method, at least not for
multi-valued fields (didn't check for single-valued). So the only way to access
multi-valued fields generically through the field handler is setValue - so there
is no way to remove values!
If there are any workarounds, please let me know...
This is what I added to DescriptorSourceFactory.createXMLFieldHandler to get a
working resetValue method for Java2 Collections - comments welcome!
//-- reset method
//--handle collections
if (member.isMultivalued()) {
CollectionInfo cInfo = (CollectionInfo) member;
FieldInfo content = cInfo.getContent();
jsc.add("public void resetValue( Object object ) throws
IllegalStateException, IllegalArgumentException {");
jsc.indent();
jsc.add("try {");
jsc.indent();
jsc.add(localClassName);
jsc.append(" target = (");
jsc.append(localClassName);
jsc.append(") object;");
String cName = JavaNaming.toJavaClassName(cInfo.getElementName());
if (cInfo instanceof CollectionInfoJ2) { jsc.add("target.clear" + cName + "();"); } else { jsc.add("target.removeAll" + cName + "()"); }
jsc.unindent();
jsc.add("} catch (java.lang.Exception ex) {"); jsc.indent(); jsc.add("throw new IllegalStateException(ex.toString());"); jsc.unindent(); jsc.add("}");
jsc.unindent();
jsc.add("}");
}
//-- end of reset method