从 xsd 生成 jaxb 对象时如何使用类自定义来解决冲突 [英] How to use a class customization to resolve conflict when generating jaxb object from xsd

查看:34
本文介绍了从 xsd 生成 jaxb 对象时如何使用类自定义来解决冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在以下 xsd 上运行 xjc -d src/-p com.test IFC2X3.xsd 命令时,它会产生冲突.

When I run the xjc -d src/ -p com.test IFC2X3.xsd command on following xsd it gives the conflict.

....
<xs:element name="IfcCondenserTypeEnum" nillable="true">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="ifc:IfcCondenserTypeEnum">
                    <xs:attributeGroup ref="ex:instanceAttributes">
                    </xs:attributeGroup>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>

    <xs:simpleType name="IfcCondenserTypeEnum">
        <xs:restriction base="xs:string">
            <xs:enumeration value="watercooledshelltube">
            </xs:enumeration>
            <xs:enumeration value="watercooledshellcoil">
            </xs:enumeration>
            <xs:enumeration value="watercooledtubeintube">
            </xs:enumeration>
            <xs:enumeration value="watercooledbrazedplate">
            </xs:enumeration>
            <xs:enumeration value="aircooled">
            </xs:enumeration>
            <xs:enumeration value="evaporativecooled">
            </xs:enumeration>
            <xs:enumeration value="userdefined">
            </xs:enumeration>
            <xs:enumeration value="notdefined">
            </xs:enumeration>
        </xs:restriction>
    </xs:simpleType>
   ....

错误:

parsing a schema...
compiling a schema...
[ERROR] A class/interface with the same name "com.test.IfcCondenserTypeEnum" is already in use. Use a class customization to resolve this conflict.
  line 14912 of file:/media/isuru/Projects/mitrai/bim_exchange/ifc_classes_v2x3/IFC2X3.xsd

[ERROR] (Relevant to above error) another "IfcCondenserTypeEnum" is generated from here.
  line 14902 of file:/media/isuru/Projects/mitrai/bim_exchange/ifc_classes_v2x3/IFC2X3.xsd

我发现了一些关于此的问题,但没有回答这个问题.我怎样才能按照建议的方式解决这个问题 使用类自定义

I found some questions regarding this but its not answering this. How can I resolve this as suggested Use a class customization

推荐答案

使用下面的绑定

<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:annox="http://annox.dev.java.net"
    xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix">
    <bindings schemaLocation="../schema.xsd">

        <bindings node="//xs:schema//xs:element[@name='IfcCondenserTypeEnum']">
            <class name="CondenserType" />
        </bindings>

    </bindings>
</bindings>

这篇关于从 xsd 生成 jaxb 对象时如何使用类自定义来解决冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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