I would like to create a web service call AddActor. The method implementing this service would look something like:
public AddActorResponse addActorOperation(AddActorRequest request) throws OperationException{
AddActorResponse response = new AddActorResponse();
ActorType actor = request.getActor();
addImpl(actor);//add to database or something
response.setActor(actor);
return response;
}
However, I would like the class ActorType to be a super class of all actors in the system. For example, I would like to have a class UserType which extends ActorType and another class AdminType which also extends ActorType. Say from the wsdl/xsd perspective these classes look like:
<xsd:complexType name="ActorType">
<xsd:sequence>
<xsd:element name="ActorId" type="xsd:string"/>
<xsd:element name="Password" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="UserType">
<xsd:complexContent>
<xsd:extension base="ns:ActorType">
<xsd:sequence>
<xsd:element name="Email" type="xsd:string"/>
<xsd:element name="FullName" type="ns:NameType"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="AdminType">
<xsd:complexContent>
<xsd:extension base="ns:ActorType">
<xsd:sequence>
<xsd:element name="EmployeeCode" type="xsd:string"/>
<xsd:element name="FullName" type="ns:NameType"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Now I want to be able to use the AddActor service to add all types of actors, however when I call this service thusly:
addActorRequest request = new AddActorRequest();
UserType actor = new UserType();
actor.setActorId("asdasd");
actor.setPassword("asdasdasdasdas");
NameType name = new NameType();
name.setFirstName("Lucas");
actor.setFullName(name);
request.setActor(actor);
AddActorResponse result = addActorPort.addActorOperation(request);
On the server side I run into trouble when I call:
AddActorResponse response = new AddActorResponse();
ActorType actor = request.getActor();
because 'actor' is an ActorType and not a UserType. I assume this has something to do with the fact that AddActorResponse is defined like this:
<xsd:complexType name="AddActorRequest">
<xsd:sequence>
<xsd:element name="Actor" type="types:ActorType"/>
</xsd:sequence>
</xsd:complexType>
What strategies can I try to make my services OO savvy? Is there something I can add to the complexTypes to make this possible? I am starting to think this is impossible since in XML a UserType with no Email or Password looks just like an ActorType, no way for the unmarshaller to know any different.
Thanks a ton,
Lucas
[Message sent by forum member 'lucasjordan' (lucasjordan)]
http://forums.java.net/jive/thread.jspa?messageID=231718