Проблема с представлением xsd complexType в SOAP WebService - PullRequest
0 голосов
/ 25 марта 2020

Я пытаюсь реализовать SOAP веб-сервис с java. У меня есть следующие определения .xsd complexType:

<xsd:complexType name="BasicURL">
   <xsd:annotation>
      <xsd:documentation>Generic representation of an URL with a possible user-friendly label</xsd:documentation>
   </xsd:annotation>
   <xsd:simpleContent>
      <xsd:extension base="xsd:string">
         <xsd:attribute name="label" type="xsd:string"/>
      </xsd:extension>
   </xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="URL">
   <xsd:annotation>
      <xsd:documentation>Extended representation of a URL with possible language and fee</xsd:documentation>
   </xsd:annotation>
   <xsd:complexContent>
      <xsd:extension base="BasicURL">
         <xsd:attribute name="lang" type="Language"/>
         <xsd:attribute name="fee" type="BasicAmount"/>
         <xsd:attribute name="currency" type="Currency"/>
      </xsd:extension>
   </xsd:complexContent>
</xsd:complexType>

Сгенерированные java классы выглядят так:

public class BasicURL {
   protected java.lang.String value;
   protected java.lang.String label;

   public BasicURL() {
   }

   ...

}

и

public class URL extends BasicURL  {
   private Language lang;
   private BasicAmount fee;
   private Currency currency;

   public URL() {
   }

   ...
}

У меня тогда есть метод, который возвращает ComplexValue, определенный как

<xsd:complexType name="ComplexValue">
   <xsd:annotation>
      <xsd:documentation>Represent a value taking the form of a basic type, a list of values or a table of values</xsd:documentation>
   </xsd:annotation>
   <xsd:choice>
      <xsd:element name="boolean" type="xsd:boolean"/>
      <xsd:element name="number" type="xsd:long"/>
      <xsd:element name="text" type="xsd:string"/>
      <xsd:element name="date" type="xsd:date"/>
      <xsd:element name="dateTime" type="xsd:dateTime"/>
      <xsd:element name="url" type="gen:URL"/>
   </xsd:choice>
</xsd:complexType>

со следующим java сгенерированным классом

public class ComplexValue  {
   private java.lang.Boolean _boolean;
   private java.lang.Long number;
   private java.lang.String text;
   private java.util.Date date;
   private java.util.Calendar dateTime;
   private URL url;

   public ComplexValue() {
   }

   ...

}

Если я затем инициализирую и возвращаю ComplexValue следующим образом:

...

URL url = new URL();
url.setLabel("Google");
url.setValue("http://google.com");
url.setLang(new Language("en"));
url.setFee(new BasicAmount("14.00"));
url.setCurrency(new Currency("USD"));

ComplexValue value = new ComplexValue();
value.setURL(url);

return value;

Я получаю следующее представление тега этого элемента:

<ns15:complexValue>
   <ns16:boolean />
   <ns17:number />
   <ns18:text />
   <ns20:date />
   <ns22:dateTime />
   <ns25:url lang="en" fee="14.00" currency="USD" />
</ns15:complexValue>

Обратите внимание, что он показывает только атрибуты, определенные в типе URL, и полностью пропускает атрибут (метку) и элемент (http://google.com) типа BasicURL? Почему это так, и как я могу выяснить проблему?

Редактировать: я должен добавить другие сложные complexTypes, например, Court

<xsd:complexType name="Court">
   <xsd:sequence>
      <xsd:element name="name" type="xsd:string"/>
      <xsd:element name="webSite" type="gen:BasicURL" minOccurs="0"/>
   </xsd:sequence>
   <xsd:attribute name="cdbId" type="xsd:token"/>
</xsd:complexType>

с java классом

public class Court  {
   private java.lang.String name;
   private BasicURL webSite;

   public Court() {
   }

   ...

}

выдает правильный тег

BasicURL url = new BasicURL();
url.setLabel("click here")
url.setValue("http://somesite.com");

Court court = new Court();
court.setName("somecourt");
court.setURL(url);

return court;

...

<ns12:court>
   <ns12:name>somecourt</ns12:name>
   <ns12:webSite label="click here">http://somesite.com</ns12:webSite>
</ns12:court>

...