Kompilowanie schematu XML do Java z ograniczeniami tożsamości klucza / klucza
Powiedzmy, że mam następujący schemat XML:
<xs:schema
xmlns="http://www.example.com/data"
xmlns:data="http://www.example.com/data"
targetNamespace="http://www.example.com/data"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="data">
<xs:complexType>
<xs:all>
<xs:element name="countries">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="country" type="country"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="types">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="type" type="type"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="products">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="product" type="product"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
<xs:key name="countryNameKey">
<xs:selector xpath=".//data:country"/>
<xs:field xpath="@name"/>
</xs:key>
<xs:key name="typeNameKey">
<xs:selector xpath=".//data:type"/>
<xs:field xpath="@name"/>
</xs:key>
<xs:keyref name="countryNameRef" refer="data:countryNameKey">
<xs:selector xpath=".//data:product"/>
<xs:field xpath="@country"/>
</xs:keyref>
<xs:keyref name="typeNameRef" refer="data:typeNameKey">
<xs:selector xpath=".//data:product"/>
<xs:field xpath="@type"/>
</xs:keyref>
<xs:unique name="uniqueProducts">
<xs:selector xpath=".//data:product"/>
<xs:field xpath="@country"/>
<xs:field xpath="@type"/>
</xs:unique>
</xs:element>
<xs:complexType name="country">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="type">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="product">
<xs:attribute name="country" type="xs:string" use="required"/>
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
Przepraszam za wymyślony przykład.
Jak widać, są to dane tabelaryczne. Definiuję niektóre kraje, a następnie definiuję niektóre typy produktów. Następnie definiuję poszczególne produkty jako typ z kraju, na przykład ser z Francji.
Ważną rzeczą do odnotowania jest to, że używamkey
ikeyref
odsyłacz do wszystkich produktów z powrotem do oryginalnego kraju / typu.
Moje pytanie brzmi:
Czy jest możliwe skompilowanie tego schematu do klas java, które można unmarshalled za pomocą Eclipse Moxy z nienaruszonymi odsyłaczami?
Wiem, że specyfikacja JAXB 2.0 to robinie obsługuje klucza / klucza. Też to wiemMoxy robi.1
Ponadto wiem, że Moxy nie ma wtyczki Maven, aw każdym razie używa klas generowanych przez XJC i po prostu dodajejaxb.properties
plik określający dostawcę JAXB.2
Podejrzewam więc, że odpowiedź na moje pytanie brzmi „nie, musisz sam tworzyć klasy”, ale pomyślałem, że sprawdzę, zanim porzucę nadzieję.
Aby wyjaśnić, Myproduct
element obecnie się kompiluje (za pomocąwtyczka maven-jaxb2) do
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "product")
public class Product implements Cloneable, CopyTo, Equals, HashCode, ToString {
@XmlAttribute(name = "country", required = true)
protected String country;
@XmlAttribute(name = "type", required = true)
protected String type;
//getters and setters
}
To odwołuje się doString
s, a nieCountry
iType
przedmioty.