Hi, I'm using Axis to model a sample WebService. What I'm doing now is trying to understand which are the limitations of the automated wsdl and code generation.
Now for some server side code:
this is the skeleton of the sample web service:
public class TestWebService {
public AbstractAttribute[] testCall( AbstractAttribute someAttribute ) {
....
and my data classes: public abstract class AbstractAttribute { String name;
/*get/set for name*/
public abstract T getValue();
public abstract void setValue(T value);
}
public class IntAttribute extends AbstractAttribute<Integer> {
Integer value;
public Integer getValue(){ return value; }
public void setValue(Integer value){ this.value = value; }
}
public class StringAttribute extends AbstractAttribute<String> {
String value;
/* ok, you got the point, get/set for value field */
}
The eclipse tool for Axis2 is quite happy to generate a wsdl from these sources, including the schema for the attribute classes, which is:
<xs:complexType name="AbstractAttribute">
<xs:sequence>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="value" nillable="true" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="IntAttribute">
<xs:complexContent>
<xs:extension base="xsd:AbstractAttribute">
<xs:sequence>
<xs:element minOccurs="0" name="value" nillable="true" type="xs:int"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="StringAttribute">
<xs:complexContent>
<xs:extension base="xsd:AbstractAttribute">
<xs:sequence>
<xs:element minOccurs="0" name="value" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
now, if see something strange here, AbstractAttribute hasn't the ** abstract="true" ** attribute, and define an anyType value element, which get rewrite in IntAttribute and StirngAttribute. I don't even know if this is a legal schema (I don't think it's legal, by the way).
More, if I try to generate a client from this wsdl (always using the eclipse tools) the generated sources won't compile, because AbstractAttribute defines an
Object localValue;
field and Int/String Attribute defines
int localValue;
and
String localValue;
..I tried to "accomodate" the sources (without many hopes, obviously), and the results are that the server try to instantiate an AbstractAttribute instance (throwing an InstantiationException).
So my question is: there is a way to model something like the data model above, or web services and XML schemas' in general are not the best tools to use for this particular case?