开发者

Comments in Enums imported from XSD by wsimport

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"/开发者_Go百科>
        <!-- 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)?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜