0

I have a webservice-standard I have to follow, got a xsd and want to generate the Java classes. Some classes with enums are generated properly, but some are empty and don't have values.

For example this one

<xsd:simpleType name="ST_Month">
  <xsd:restriction base="xsd:string">
     <xsd:enumeration value="01">
        <xsd:annotation>
           <xsd:documentation xml:lang="de">January</xsd:documentation>
        </xsd:annotation>
     </xsd:enumeration>
     <xsd:enumeration value="02">
        <xsd:annotation>
           <xsd:documentation xml:lang="de">February</xsd:documentation>
        </xsd:annotation>
     </xsd:enumeration>
     ...
  </xsd:restriction>
</xsd:simpleType>

is generated correctly to

@XmlType(name = "ST_Month")
@XmlEnum
public enum STMonth {
   /**January */
   @XmlEnumValue("01")
   VALUE_1("01"),

   /** February */
   @XmlEnumValue("02")
   VALUE_2("02"),
    ...
 }

But some enums have abstract superclasses like this:

<xsd:complexType name="STE_Country" abstract="true">
   <xsd:simpleContent>
      <xsd:extension base="xsd:string"/>
   </xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="STE_CountryBasic" final="#all">
   <xsd:simpleContent>
      <xsd:restriction base="dt:STE_Country">
         <xsd:enumeration value="01">
            <xsd:annotation>
               <xsd:documentation>USA</xsd:documentation>
            </xsd:annotation>
         </xsd:enumeration>
         <xsd:enumeration value="02">
            <xsd:annotation>
               <xsd:documentation>GERMANY</xsd:documentation>
            </xsd:annotation>
         </xsd:enumeration>
      </xsd:restriction>
   </xsd:simpleContent>
</xsd:complexType>

The result of the generation is this:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "STE_CountryBasic")
public class STECountryBasic extends STECountry
{
}

I also added my own complexType for 'MyOwnCountry' with country values that are missing in STE_Country but needed in my application. But the generated class is the same empty result as STECountryBasic.

What do I have to do so the enum-values in STECountryBasic are generated?

Additionally, I'm generating via maven with the cxf-codegen-plugin

Marc B
  • 36
  • 1
  • Well STE_CountryBasic is a complex type with a superclass, enums can't have superclasses. how would you expect it to be generated? – daniu Aug 28 '18 at 09:13
  • It would be cool if a 'public enum STECountryBasic' would be generated, optionally with a comment 'relates to STECountry'. Is that possible without changing the xsd? Maybe with config in jaxb-bindings? – Marc B Aug 28 '18 at 09:25
  • You will need STE_Country to generate an interface rather than a class that STE_Country then implements rather than extends. Check out this question https://stackoverflow.com/questions/1271980/generating-a-jaxb-class-that-implements-an-interface which asked for the same thing IIUC. – daniu Aug 28 '18 at 09:37
  • Ok thanks, I'll try it – Marc B Aug 28 '18 at 11:06
  • Unfortunatly I didn't get the solution with the interface working. But I found a way to transform the xsd via XSL, so the STE_CountryBasic looks like the ST_Month in the xsd. A second generation-step creates another class STE_ContryBasicValues as an enum. @daniu Thanks anyway for your proposal. – Marc B Sep 10 '18 at 07:23

0 Answers0