I have attached updates to two files within the SourceGenerator and one validator which address the following bugs:
1) When an XML Schema type of NMTOKENS is used, the generated code uses a NameValidator instance configured to validate a single NMTOKEN. By extending the NameValidator to accept an NMTOKENS constant, the value to validate can first be broken into individual NMTOKEN instances and validated individually. 2) The FieldHandler interface has a resetValue method which should empty a collection of all elements. Currently the SourceGenerator does not define such a method. I have added a resetValue method in cases where the memeber is multi-valued. It uses the value of a new method getDeleteMethodName within CollectionInfo in order to allow for differences in method naming between CollectionInfo and CollectionInfoJ2. -Steve
Index: DescriptorSourceFactory.java =================================================================== RCS file: /cvs/castor/castor/src/main/org/exolab/castor/builder/DescriptorSourceFactory.java,v retrieving revision 1.63 diff -r1.63 DescriptorSourceFactory.java 412a413,446 > //-- resetValue method > if (member.isMultivalued()) { > jsc.add("public void resetValue( Object object ) "); > jsc.indent(); > jsc.add("throws IllegalStateException, IllegalArgumentException"); > jsc.unindent(); > jsc.add("{"); > jsc.indent(); > > jsc.add("try {"); > jsc.indent(); > > jsc.add(localClassName); > jsc.append(" target = ("); > jsc.append(localClassName); > jsc.append(") object;"); > > jsc.add("target."); > jsc.append(member.getDeleteMethodName()); > jsc.append("();"); > > jsc.unindent(); > jsc.add("}"); > jsc.add("catch (Exception ex) {"); > jsc.indent(); > jsc.add("throw new IllegalStateException(ex.toString());"); > jsc.unindent(); > jsc.add("}"); > jsc.unindent(); > jsc.add("}"); > } > //-- end of resetValue method > > 1037c1071,1074 < jsc.append("NameValidator.NMTOKEN));"); --- > if (member.isMultivalued()) > jsc.append("NameValidator.NMTOKENS));"); > else > jsc.append("NameValidator.NMTOKEN));");
Index: NameValidator.java =================================================================== RCS file: /cvs/castor/castor/src/main/org/exolab/castor/xml/validators/NameValidator.java,v retrieving revision 1.5 diff -r1.5 NameValidator.java 49a50 > import java.util.StringTokenizer; 62a64 > public static final short NMTOKENS = 3; 115a118,130 > case NMTOKENS: > StringTokenizer tokenizer = new StringTokenizer(value); > while (tokenizer.hasMoreTokens()) { > String token = tokenizer.nextToken(); > if (!ValidationUtils.isNMToken(token)) { > String err = "\""; > err += token +"\" within \"" + value + > "\" is not a valid NMTokens."; > throw new ValidationException(err); > } > } > break; > 142c157 < } //-- NameValidator \ No newline at end of file --- > } //-- NameValidator
Index: CollectionInfoJ2.java =================================================================== RCS file: /cvs/castor/castor/src/main/org/exolab/castor/builder/CollectionInfoJ2.java,v retrieving revision 1.17 diff -r1.17 CollectionInfoJ2.java 88a89,92 > public String getDeleteMethodName() { > return "clear" + JavaNaming.toJavaClassName(getElementName()); > } //-- getDeleteMethodName >
Index: CollectionInfo.java =================================================================== RCS file: /cvs/castor/castor/src/main/org/exolab/castor/builder/CollectionInfo.java,v retrieving revision 1.15 diff -r1.15 CollectionInfo.java 114a115,119 > public String getDeleteMethodName() { > return "removeAll" + JavaNaming.toJavaClassName(getElementName()); > } //-- getDeleteMethodName > >