Question

is there a way to get comments from XSD to Java code using wsimport? For example, I have an XSD file

<!-- Enumerace /model/user/UserLevel.java -->
<xs:simpleType name="userLevel">
    <xs:restriction base="xs:string">
        <!-- basic user -->
        <xs:enumeration value="BASE"/>
        <!-- team leader -->
        <xs:enumeration value="TL"/>
        <!-- section leader -->
        <xs:enumeration value="SL"/>
    </xs:restriction>
</xs:simpleType>

and I want my generated java enum class to look something like this:

@XmlType(name = "userLevel")
@XmlEnum
public enum UserLevel {
    /**
     * basic user
     */
    BASE,
    /**
     * team leader
     */
    TL,
    /**
     * section leader
     */
    SL;
}

Is this even possible in contract first (eg. java code generated from XSD)?

Was it helpful?

Solution

Ok, I found a solution, this in XSD:

<xs:simpleType name="MyEnum">
    <xs:restriction base="xs:string">
        <xs:enumeration value="STANDARD">
            <xs:annotation>
                <xs:documentation>
                    This is a comment.
                </xs:documentation>
            </xs:annotation>
        </xs:enumeration>
    </xs:restriction>
</xs:simpleType>

produces a Java enum such as:

@XmlType(name = "MyEnum")
@XmlEnum
public enum MyEnum {


    /**
     * 
     *                         This is a comment.
     *                     
     * 
     */
    STANDARD,

    public String value() {
        return name();
    }

    public static MyEnum fromValue(String v) {
        return valueOf(v);
    }

}

The only problem is that xs:documentation does not ignore whitespace so there is a lot of blank space in the comments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top