Reputation: 189
I want to generate a webservice in a bottom up approach but it does not work properly with generics.
I have a few classes which looks like these and can hardly be modified (maybe some annotations) :
public class MySuperSet<K,V> {
private Map<K,V> map;
...
// getter and setter for map
}
public class PearSet extends MySuperSet<String, Pear> {
}
public class AppleSet extends MySuperSet<String, Apple> {
}
The generated xsd looks like this :
<xs:complexType name="mySuperSet">
<xs:sequence>
<xs:element name="map">
<xs:complexType>
<xs:sequence>
<xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="key" minOccurs="0" type="xs:anyType"/>
<xs:element name="value" minOccurs="0" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="pearSet">
<xs:complexContent>
<xs:extension base="tns:mySuperSet">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="appleSet">
<xs:complexContent>
<xs:extension base="tns:mySuperSet">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
And the definitions for apple and pear are not generated too!
I guess the xsd I'm expecting would be more like this :
<xs:complexType name="pearSet">
<xs:sequence>
<xs:element name="map">
<xs:complexType>
<xs:sequence>
<xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="key" minOccurs="0" type="xs:string"/>
<xs:element name="value" minOccurs="0" type="tns:pear"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="appleSet">
<xs:sequence>
<xs:element name="map">
<xs:complexType>
<xs:sequence>
<xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="key" minOccurs="0" type="xs:string"/>
<xs:element name="value" minOccurs="0" type="tns:apple"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
I thought it might work out if I modify it manually. Like I guess when it needs to set the map element of appleSet it will just call setMap() which exists. However, the service generated does not take into account my modifications of the xsd (it seems that it is regenerated from the code dynamically).
I'm using an IBM eclipse plugin to generate the webservice project and it looks like it is using sun's implementation of jax-ws to build the application.
I would also like to remove some unused attributes from the xsd later.
-
What approach would you recommand to solve this issue ?
Here are the possibilities I have thought of :
XmlAdapter (One per subclass of MySuperSet)
Manual binding (I don't know how it works)
A more flexible library that try to use a given xsd and a given code and make them match
Thanks :-)
Upvotes: 1
Views: 981