无法使用JAXB生成枚举类 [英] Cannot generated enumeration class using JAXB

查看:79
本文介绍了无法使用JAXB生成枚举类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JAXB从XSD(以无法控制的标准分发,我无法更改)生成一些POJO有很多困难。该问题似乎与该XSD中定义某些类型的方式有关。下面我粘贴了一个名为TransactionCodeType的XSD中定义的简单类型,它是一个标记的并集,它与一个枚举值列表相结合,也被定义为一个标记。

I've a lot of difficulties generating some POJOs from an XSD (distributed as a standard that I don't have control and I cannot changed) using JAXB. The problem seems to be related to the way certain types are defined in that XSD. Below I've pasted a simple type defined in this XSD named TransactionCodeType which is a union of a token combined with an enumeration list of values, also defined as a token.

<xs:element name="TransactionContentDetails">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="TransactionIdentifier" type="xs:string" minOccurs="0"/>
            <xs:element name="TransactionCode" type="TransactionCodeType"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:simpleType name="TransactionCodeType">
    <xs:union memberTypes="xs:token">
        <xs:simpleType>
            <xs:restriction base="xs:token">
                xs:enumeration value="Design E-Filing"/>
                <xs:enumeration value="Design B2B-Filing" />
                <xs:enumeration value="Design Information" />
                <xs:enumeration value="Design Identifier List" />
                <xs:enumeration value="Design List" />
                <xs:enumeration value="Design Opposition E-Filing" />
                <xs:enumeration value="Design Opposition Information" />
                <xs:enumeration value="Design Opposition Identifier List" />
                <xs:enumeration value="Representative Appointment" />
                <xs:enumeration value="Amendment Registered Design" />
                <xs:enumeration value="Amendment Application" />
                <xs:enumeration value="Convention Application" />
                <xs:enumeration value="Additional Application" />
                <xs:enumeration value="Subsequent Application" />
                <xs:enumeration value="Divisional Application" />
                <xs:enumeration value="Assignment Application" />
                <xs:enumeration value="Assignment Registered Design" />
                <xs:enumeration value="Request Certified Copies" />
                <xs:enumeration value="Request Extension Time" />
                <xs:enumeration value="Request Hearing" />
                <xs:enumeration value="Opposition First Extension" />
                <xs:enumeration value="Opposition Various Renewal/Extension of Registration Restoration" />
                <xs:enumeration value="Withdrawal" />
                <xs:enumeration value="Withdraw Application" />
                <xs:enumeration value="Withdraw Design" />
                <xs:enumeration value="Response Examination Report" />
                <xs:enumeration value="Statement Support" />
                <xs:enumeration value="Withdraw Service Request" />
                <xs:enumeration value="Request Publication" />
                <xs:enumeration value="Request Registration" />
                <xs:enumeration value="Offer Surrender" />
                <xs:enumeration value="Request Exclusion" />
                <xs:enumeration value="Request Conversion" />
                <xs:enumeration value="Duplicate Certificate" />
                <xs:enumeration value="Request Supply Documents" />
                <xs:enumeration value="Request Delayed Registration" />
                <xs:enumeration value="Request Accelerated Examination" />
                <xs:enumeration value="Expiry Notice" />
                <xs:enumeration value="Refusal Withdrawal Notification" />
                <xs:enumeration value="Division International Registration Notification" />
                <xs:enumeration value="Refusal Notification" />
                <xs:enumeration value="Providing Certificate To Holder" />
                <xs:enumeration value="Transmittal Application To IB" />
                <xs:enumeration value="Irregularities" />
                <xs:enumeration value="Invalidation Notification" />
                <xs:enumeration value="Cancellation Representative Appointment" />
                <xs:enumeration value="Application Receipt" />
                <xs:enumeration value="Notice Document By Design Formality Examination" />
                <xs:enumeration value="Notice Document By Design Substantial Examination" />
                <xs:enumeration value="Notice Document By Design Registration" />
                <xs:enumeration value="Notice Document By Trial Examination - Invitation" />
                <xs:enumeration value="Notice Document By Trial Examination" />
                <xs:enumeration value="Notice Document By Trial Examination - Decision" />
                <xs:enumeration value="Memo By Design Formality Examination" />
                <xs:enumeration value="Memo By Design Substantial Examination" />
                <xs:enumeration value="Memo By Trial Examination" />
                <xs:enumeration value="Memo By Trial Notice" />
                <xs:enumeration value="Memo By Trial Examination - Correction" />
                <xs:enumeration value="Accept Design Application Document" />
                <xs:enumeration value="Accept Design Applicant Document" />
                <xs:enumeration value="Accept Design Attorney Document" />
                <xs:enumeration value="Accept Design Withdrawal And Abandonment Document" />
                <xs:enumeration value="Accept Design Response Document" />
                <xs:enumeration value="Accept Design Submission Document" />
                <xs:enumeration value="Accept Design Amendment Document" />
                <xs:enumeration value="Accept Design Request For Inspection" />
                <xs:enumeration value="Accept Demand For A Trial" />
                <xs:enumeration value="Accept Trial Intermediate Document" />
                <xs:enumeration value="Inspection Accept Design Application Document" />
                <xs:enumeration value="Inspection Accept Design Applicant Document" />
                <xs:enumeration value="Inspection Accept Design Attorney Document" />
                <xs:enumeration value="Inspection Accept Design Withdrawal And Abandonment Document" />
                <xs:enumeration value="Inspection Accept Design Response Document" />
                <xs:enumeration value="Inspection Accept Design Submission Document" />
                <xs:enumeration value="Inspection Accept Design Amendment Document" />
                <xs:enumeration value="Inspection Accept Design Request For Inspection" />
                <xs:enumeration value="Inspection Accept Demand For A Trial" />
                <xs:enumeration value="Inspection Accept Trial Intermediate Document" />
                <xs:enumeration value="Inspection Notice Document By Design Formality Examination" />
                <xs:enumeration value="Inspection Notice Document By Design Substantial Examination" />
                <xs:enumeration value="Inspection Notice Document By Design Registration" />
                <xs:enumeration value="Inspection Notice Document By Trial Examination - Invitation" />
                <xs:enumeration value="Inspection Notice Document By Trial Examination" />
                <xs:enumeration value="Inspection Notice Document By Trial Examination - Decision" />
                <xs:enumeration value="Inspection Memo By Design Formality Examination" />
                <xs:enumeration value="Inspection Memo By Design Substantial Examination" />
                <xs:enumeration value="Inspection Memo By Trial Examination" />
                <xs:enumeration value="Inspection Memo By Trial Notice" />
                <xs:enumeration value="Certified Copy Notice Document By Design Formality Examination" />
                <xs:enumeration value="Certified Copy Notice Document By Design Substantial Examination" />
                <xs:enumeration value="Certified Copy Notice Document By Design Registration" />
                <xs:enumeration value="Certified Copy Notice Document By Trial Examination - Invitation" />
                <xs:enumeration value="Certified Copy Notice Document By Trial Examination" />
                <xs:enumeration value="Certified Copy Notice Document By Trial Examination - Decision" />
                <xs:enumeration value="Accept Document List" />
                <xs:enumeration value="Notice Document List" />
                <xs:enumeration value="Application Information" />
                <xs:enumeration value="Balance Sheet Reference" />
                <xs:enumeration value="Division Number List" />
                <xs:enumeration value="Record Licence" />
                <xs:enumeration value="Record Mortgagee" />
                <xs:enumeration value="Terminate Licence" />
                <xs:enumeration value="Discharge Mortgagee" />
                <xs:enumeration value="Change of Name" />
            </xs:restriction>
        </xs:simpleType>
    </xs:union>
</xs:simpleType>

使用JAXB,生成的输出(见下文)将转换为Java中的基本类型String。我正在使用org.jvnet.jaxb2.maven2的最新版本的maven-jaxb2-plugin。在某些时候,这是我的预期。因此,我希望能够从Java代码中访问XSD中定义的可能值列表。但是怎么样? JAXB不生成定义所有这些值的枚举类。我在网上搜索,包括在这个网站下找到解决方案;尝试一些建议的解决方案,包括绑定的使用,但没有任何成功。

Using JAXB, the output generated (see below) is translate as the basic type String in Java. I'm using the latest version of maven-jaxb2-plugin from org.jvnet.jaxb2.maven2. At some point, this is what I expected. Therefore, I would like to be able to access from the Java code the list of possible values that are defined within the XSD. But how ? JAXB doesn't generated a enumeration class that defined all these values. I've searched on the web including under this site to find solutions; try some of the proposed solutions including the usage of bindings without any success.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "transactionIdentifier",
    "transactionCode",
})
public static class TransactionContentDetails implements Serializable  {

    @XmlElement(name = "TransactionIdentifier")
    protected String transactionIdentifier;
    @XmlElement(name = "TransactionCode", required = true)
    protected String transactionCode;

    public String getTransactionIdentifier() {
        return transactionIdentifier;
    }

    public void setTransactionIdentifier(String value) {
        this.transactionIdentifier = value;
    }

    public String getTransactionCode() {
        return transactionCode;
    }

    public void setTransactionCode(String value) {
        this.transactionCode = value;
    }
}

所以,我想看看你有没有关于如何解决该问题的任何想法,即能够生成包含所有这些值的Java枚举类。作为解决方案的一部分,我不想在绑定文件中重新定义所有这些值。

So, I’m looking to see if you have any ideas on how I could resolve that problem, i.e., being able to generate a Java enumeration class containing all these values. As part of the solution, I don't want to have to redefined all these values within a binding file.

谢谢!

推荐答案

看起来工会得不到很好的支持 https://jaxb.java.net/tutorial/section_2_2_10-Defining-a-Type-Union.html

It looks like unions are not well supported https://jaxb.java.net/tutorial/section_2_2_10-Defining-a-Type-Union.html

如果你可以修改模式,你可以将枚举的匿名简单类型提取到命名类型,然后在你的代码中使用为这个新类型生成的Java枚举....

If you could modify the schema you could extract the enumerated anonymous simple type to a named type and then use in your code the Java enum generated for this new type....

这篇关于无法使用JAXB生成枚举类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆