I am indeed using the xs:string type.
My schema/code is not private - I'm just experimenting.
I have included the follow files:
settings.xsd
TrimmedString.java
DatabaseSettingsImpl.java (excerpt)
I don't know how to attach the files to the form, and in
order to reduce the size of the text I've omitted the
generated files - however, if you can't reproduce the
problem, I'll be happy to send whatever I've got.
Thanks
Marcus
=== settings.xsd ===
<xsd:schema xmlns:xsd="
http://www.w3.org/2001/XMLSchema"
xmlns:jxb="
http://java.sun.com/xml/ns/jaxb"
jxb:version="1.0">
<!-- the root element for the settings XML file -->
<xsd:element name="settings" type="SettingsType"/>
<xsd:annotation>
<xsd:appinfo>
<jxb:globalBindings>
<jxb:javaType name="com.aspective.common.jaxb.TrimmedString"
xmlType="xsd:string"
parse="parse"
print="print">
</jxb:javaType>
</jxb:globalBindings>
</xsd:appinfo>
</xsd:annotation>
<!-- this is the top-level container for settings -->
<xsd:complexType name="SettingsType">
<xsd:sequence>
<xsd:element name="database" type="DatabaseSettings"/>
</xsd:sequence>
</xsd:complexType>
<!-- database settings -->
<xsd:complexType name="DatabaseSettings">
<xsd:sequence>
<xsd:element name="username">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="16"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="password">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="16"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
=== TrimmedString.java ===
package com.aspective.common.jaxb;
public class TrimmedString {
private String value;
public TrimmedString(String in) {
value = trimString(in);
}
public String print() {
return trimString(value);
}
public String toString() {
return this.value;
}
public static TrimmedString parse(String in) {
return new TrimmedString(in);
}
private static String trimString(String test) {
return (test == null) ? null : test.trim();
}
}
=== DatabaseSettingsImpl.java ===
public void text(String value)
throws com.sun.xml.bind.unmarshaller.UnreportedException
{
try {
switch (state) {
case 1 :
_Username = com.aspective.common.jaxb.TrimmedString.parse(com.sun.xml.bind.WhiteSpaceProcessor.collapse(value));
state = 2;
return ;
case 4 :
_Password = com.aspective.common.jaxb.TrimmedString.parse(com.sun.xml.bind.WhiteSpaceProcessor.collapse(value));
state = 5;
return ;
case 6 :
revertToParentFromText(value);
return ;
}
} catch (RuntimeException e) {
handleUnexpectedTextException(value, e);
}
}