JAXB绑定简单类型

时间:2012-04-18 16:24:22

标签: binding jaxb

我正在尝试从xsd生成类,但在尝试自定义简单类型时遇到以下异常:

    com.sun.istack.SAXParseException2: A type safe enum customization is specified to a simple type that cannot be mapped to a type safe enum.

抛出异常的简单类型的声明如下:

    <xs:simpleType name="BroadcastAlertsItem">
    <xs:annotation>
        <xs:appinfo>
        reserved (0)
        broadcastAlertsAccepted (1)
        broadcastAlertsNotAccepted (2)
     </xs:appinfo>
    </xs:annotation>
    <xs:union>
        <xs:simpleType>
            <xs:restriction base="xs:unsignedInt">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="2"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:enumeration value="reserved"/>
                <xs:enumeration value="broadcastAlertsAccepted"/>
                <xs:enumeration value="broadcastAlertsNotAccepted"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:union>
</xs:simpleType>

这是绑定自定义文件的绑定:

    <jaxb:bindings node="//xs:simpleType[@name='BroadcastAlertsItem']">
        <jaxb:typesafeEnumBase name="BroadcastAlertsItem">
            <jaxb:typesafeEnumMember name="reserved"/>
            <jaxb:typesafeEnumMember name="broadcastAlertsAccepted"/>
            <jaxb:typesafeEnumMember name="broadcastAlertsNotAccepted"/>
        </jaxb:typesafeEnumBase>
    </jaxb:bindings>

正如您所想,我已尝试了更多方法来实现这一目标:(

有人知道是否有办法在不修改xsd文件的情况下绑定该简单类型?

非常感谢。

0 个答案:

没有答案