Hi,
I have a case, when classes are generated with XJC.
part of XSD:
<xs:element name="LRN" minOccurs="0" type="LRNContentType">
<xs:annotation>
<xs:documentation>
<description value="LRN" />
<format value="an..22" />
<optionality value="D" />
</xs:documentation>
</xs:annotation>
</xs:element>
which turns out to java code:
@XmlElement(name = "LRN")
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "token")
protected String lrn;
public String getLRN() {
return lrn;
}
public void setLRN(String value) {
this.lrn = value;
}
and then another example:
<xs:element name="TIRHolderIdentificationNumber" minOccurs="0" type="TIRHolderIdentificationNumberContentType">
<xs:annotation>
<xs:documentation>
<description value="TIR holder identification number" />
<format value="an..17" />
<optionality value="D" />
</xs:documentation>
</xs:annotation>
</xs:element>
which turns out to be:
@XmlElement(name = "TIRHolderIdentificationNumber")
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "token")
protected String tirHolderIdentificationNumber;
public String getTIRHolderIdentificationNumber() {
return tirHolderIdentificationNumber;
}
public void setTIRHolderIdentificationNumber(String value) {
this.tirHolderIdentificationNumber = value;
}
By the naming convention this is correct so I made a workaround like this:
public class XjcCompatibleClassInfoStrategy extends AbstractClassInfoStrategy {
...
protected String extractFieldNameFromMethod(String methodName, Pattern pattern) {
String candidateField = pattern.matcher(methodName).replaceFirst("");
// we have all capitals like MRN or LRN, let's make them all small.
if (candidateField.toUpperCase().equals(candidateField)) {
return candidateField.toLowerCase();
}
/*
* Default XJC respect Java Bean convention: If the first two letters of a property
* name are uppercase, no capitalization or decapitalization is applied to the get
* and set methods.
*
* Podam on the other hand do not take this into account so it does not find such
* fields.
*/
// method name starts with 2 or more capitals
if (candidateField.substring(0, 2).toUpperCase().equals(candidateField.substring(0, 2))) {
// now let's lowercase all but last in the row of upper cases
char[] candidate = candidateField.toCharArray();
char[] newName = new char[candidate.length];
boolean noMoreCapitals = false;
for (int i = 0; i < candidate.length; i++) {
if (i >= candidate.length - 2 || noMoreCapitals) {
// just copy last character
newName[i] = candidate[i];
} else if (Character.isUpperCase(candidate[i]) && Character.isUpperCase(candidate[i + 1])) {
newName[i] = Character.toLowerCase(candidate[i]);
} else {
newName[i] = candidate[i];
noMoreCapitals = true;
}
}
return new String(newName);
}
return super.extractFieldNameFromMethod(methodName, pattern);
}
...
}
I think podam should take care of this by default?
Cheers, Matjaz