1
votes

General information:

  • I use Flex 4.5
  • I use FlashBuilder 4
  • I generate the WSDL using JAX-WS 2.2 (via a GlassFish 3.1 AS)

I want to have a web service that returns a list of clients. In the Java code, I have a base class for a Client, and 2 extending classes:

public class Client {
    public String getName() {
        return this.name;
    }
}

public class AdvisedClient extends Client {
    public String getFoo() {
        return this.foo;
    }
}

public class NotAdvisedClient extends Client {
    public String getBar() {
        return this.bar;
    }
}

These classes are POJOs.

The web service looks like this:

public class ClientsModel {
    public List<Client> getClients() {
        return this.clients;
    }
}

 @WebService
public class ClientService {
    @WebMethod
    public ClientsModel getClients(String bla) {
        ...
    }
}

I tried to use the following methods for representing the inheritance in the eventual WSDL:

http://bdoughan.blogspot.com/2010/11/jaxb-and-inheritance-using-substitution.html

(Here I annotated all 3 classes with @XmlRootElement, I also annotated ClientsModel with @XmlRootElement, annotated the ClientsModel.getClients() with @XmlElementRef, and also annotated ClientsModel with @XmlSeeAlso so that the JAXBContext would recognize the AdvisedClient and NotAdvisedClient classes).

http://bdoughan.blogspot.com/2010/11/jaxb-and-inheritance-using-xsitype.html

(Here I annotated only the Client class with @XmlRootElement, and left the extending classes as is, and also removed the @XmlElementRef annotation).

For the first approach (substitution), I got the following schema:

<xs:complexType name="ClientsModel">
  <xs:sequence>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="tns:AdvisedClient" /> 
      <xs:element ref="tns:NotAdvisedClient" /> 
    </xs:choice>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="Client">
  <xs:sequence>
    <xs:element name="name" type="xs:string" minOccurs="0" /> 
  </xs:sequence>
</xs:complexType>

<xs:complexType name="AdvisedClient">
  <xs:complexContent>
    <xs:extension base="tns:Client">
      <xs:sequence>
        <xs:element name="foo" type="xs:string" minOccurs="0" /> 
      </xs:sequence>  
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

<xs:complexType name="NotAdvisedClient">
  <xs:complexContent>
    <xs:extension base="tns:Client">
      <xs:sequence>
        <xs:element name="bar" type="xs:string" minOccurs="0" /> 
      </xs:sequence>  
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

And when I used FlashBuilder's 'Connect to Web Service' wizard, I got a ClientsModel class which contains a property for advisedClient and another for notAdvisedClient, but NOT as lists!

Then I tried the 2nd approach, and got the following schema:

<xs:complexType name="ClientsModel">
  <xs:sequence>
    <xs:element name="clients" type="tns:Client" nillable="true" minOccurs="0" maxOccurs="unbounded" />
   </xs:sequence>
</xs:complexType>

Whereas the complexType for Client, AdvisedClient and NotAdvisedClient remained the same.

After generating the classes in ActionScript using FlashBuilder, I this time got only Client class binded, with no AdvisedClient or NotAdvisedClient...

Is there another way to control the schema using JAXB, so that the inherit


Thanks for the answer, to start with.

Sorry for not being more specific about the AS generated classes. I didn't mean lists per-se. I meant the idea that generated ClientsModel class does not contain a List/array/ArrayCollection and so on. It contains a single property for an AdvisedClient and a single for NotAdvisedClient.

The generated class is quite complex, but I will try to simplify it:

public class _Super_ClientsModel extends flash.events.EventDispatcher implements com.adobe.fiber.valueobjects.IValueObject {
    private var _internal_client : com.company.product.clients.valueObjects.Client;
    private var _internal_advisedClient : com.company.product.clients.valueObjects.AdvisedClient;
    private var _internal_notAdvisedClient : com.company.product.clients.valueObjects.NotAdvisedClient;       
}

The get functions return them respectively.

So you see that the generated class is not as I would expect, and it's nothing I can work with. If you think that the whole class is relevant here, I could attach it too...

Thanks again, Daniel

1

1 Answers

0
votes
when I used FlashBuilder's 'Connect to Web Service' wizard, I got a ClientsModel class which contains a property for advisedClient and another for notAdvisedClient, but NOT as lists!

A List in Flex is a UI element, and it not usually used as a data type for passing information to and from a remote service. I would not expect anything model style objects that Flash Builder automatically generates to generate anything with a "List" data type. It would more likely use an Array or ArrayCollection.

But, you didn't show the generated AS3 objects; nor did you specify what they were being generated as; so I'm not sure where to direct you next.