I have an externally supplied XSD which has many elements all which are identical and represent a price with optional currency attribute.
<xs:complexType name="someType">
<xs:sequence>
<xs:element name="rrp" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="currency" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="whs" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="currency" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
I'd like this to be transformed into a common class instead of lots of static classes, is this possible with an XJB mapping document?
I don't know a way to do this with the JAXB annotations, but that's not to say that's not possible. Maybe some one will give you a better answer there.
The ideal way to solve this is obviously to change the XSD so that you have a "PriceWithcurrency" xs:complexType definition, and each element is declared to be of that type. But you said you can't change it.
Once thing I would try though, is to create a variant of that XSD that does just that, keep the same namespace definition for it and generate the jaxb classes. It should work with the XML document instances produced using the original XSD's.