繁体   English   中英

用于更改类名的 Jaxb 绑定不起作用

[英]Jaxb bindings to change class name aren't working

我有一个具有多个同名级别的大架构。 (不是我写的!)

这里是:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.CIP4.org/JDFSchema_1_1" xmlns:efi="http://www.efi.com/efijdf"
    xmlns:ssi="http://www.creo.com/SSI/JDFExtensions.xsd" xmlns:jdf="http://www.CIP4.org/JDFSchema_1_1">

    <xs:import namespace="http://www.efi.com/efijdf" schemaLocation="EFI-JDF.xsd" />
    <xs:import namespace="http://www.creo.com/SSI/JDFExtensions.xsd" schemaLocation="SSiJDFExtensions.xsd" />

    <xs:element name="JDF">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Comment">
                    <xs:complexType>
                        <xs:simpleContent>
                            <xs:extension base="xs:string">
                                <xs:attribute type="xs:string" name="AgentName" />
                                <xs:attribute type="xs:string" name="AgentVersion" />
                                <xs:attribute type="xs:dateTime" name="TimeStamp" />
                            </xs:extension>
                        </xs:simpleContent>
                    </xs:complexType>
                </xs:element>
                <xs:element name="AuditPool">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Created">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute type="xs:string" name="AgentName" />
                                            <xs:attribute type="xs:string" name="AgentVersion" />
                                            <xs:attribute type="xs:string" name="ID" />
                                            <xs:attribute type="xs:dateTime" name="TimeStamp" />
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="ResourcePool">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Layout">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="Layout" maxOccurs="unbounded" minOccurs="0">
                                            <xs:complexType>
                                                <xs:sequence>
                                                    <xs:element name="Layout">
                                                        <xs:complexType>
                                                            <xs:sequence>
                                                                <xs:element name="Media" type="jdf:MediaType" />
                                                                <xs:element name="TransferCurvePool">
                                                                    <xs:complexType>
                                                                        <xs:sequence>
                                                                            <xs:element name="TransferCurveSet">
                                                                                <xs:complexType>
                                                                                    <xs:simpleContent>
                                                                                        <xs:extension base="xs:string">
                                                                                            <xs:attribute type="xs:string" name="CTM" use="optional" />
                                                                                            <xs:attribute type="xs:string" name="Name" use="optional" />
                                                                                        </xs:extension>
                                                                                    </xs:simpleContent>
                                                                                </xs:complexType>
                                                                            </xs:element>
                                                                        </xs:sequence>
                                                                        <xs:attribute type="xs:string" name="Class" use="optional" />
                                                                    </xs:complexType>
                                                                </xs:element>
                                                                <xs:element name="MediaRef">
                                                                    <xs:complexType>
                                                                        <xs:simpleContent>
                                                                            <xs:extension base="xs:string">
                                                                                <xs:attribute type="xs:string" name="rRef" use="optional" />
                                                                            </xs:extension>
                                                                        </xs:simpleContent>
                                                                    </xs:complexType>
                                                                </xs:element>
                                                                <xs:element name="Layout4" maxOccurs="unbounded" minOccurs="0">
                                                                    <xs:complexType>
                                                                        <xs:choice maxOccurs="unbounded" minOccurs="0">
                                                                            <xs:element name="MarkObject">
                                                                                <xs:complexType>
                                                                                    <xs:simpleContent>
                                                                                        <xs:extension base="xs:string">
                                                                                            <xs:attribute type="xs:string" name="CTM" use="optional" />
                                                                                            <xs:attribute type="xs:string" name="ClipBox" use="optional" />
                                                                                            <xs:attribute type="xs:byte" name="Ord" use="optional" />
                                                                                        </xs:extension>
                                                                                    </xs:simpleContent>
                                                                                </xs:complexType>
                                                                            </xs:element>
                                                                            <xs:element name="ContentObject">
                                                                                <xs:complexType>
                                                                                    <xs:simpleContent>
                                                                                        <xs:extension base="xs:string">
                                                                                            <xs:attribute type="xs:string" name="CTM" use="optional" />
                                                                                            <xs:attribute type="xs:string" name="ClipBox" use="optional" />
                                                                                            <xs:attribute type="xs:byte" name="Ord" use="optional" />
                                                                                            <xs:attribute ref="ssi:Comp" />
                                                                                            <xs:attribute ref="ssi:TrimBox1" />
                                                                                            <xs:attribute type="xs:string" name="TrimCTM" use="optional" />
                                                                                            <xs:attribute type="xs:string" name="TrimSize" use="optional" />
                                                                                        </xs:extension>
                                                                                    </xs:simpleContent>
                                                                                </xs:complexType>
                                                                            </xs:element>
                                                                        </xs:choice>
                                                                        <xs:attribute ref="ssi:Dimension" />
                                                                        <xs:attribute ref="ssi:MediaOrigin" />
                                                                        <xs:attribute type="xs:string" name="Side" use="optional" />
                                                                        <xs:attribute type="xs:string" name="Status" use="optional" />
                                                                        <xs:attribute type="xs:string" name="SurfaceContentsBox" use="optional" />
                                                                    </xs:complexType>
                                                                </xs:element>
                                                            </xs:sequence>
                                                            <xs:attribute ref="ssi:WorkStyle" />
                                                            <xs:attribute type="xs:string" name="SheetName" use="optional" />
                                                            <xs:attribute type="xs:string" name="SurfaceContentsBox" use="optional" />
                                                            <xs:attribute type="xs:string" name="WorkStyle" use="optional" />
                                                        </xs:complexType>
                                                    </xs:element>
                                                </xs:sequence>
                                                <xs:attribute type="xs:string" name="SignatureName" use="optional" />
                                                <xs:attribute type="xs:string" name="Status" use="optional" />
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                    <xs:attribute type="xs:string" name="Class" />
                                    <xs:attribute type="xs:string" name="DescriptiveName" />
                                    <xs:attribute type="xs:string" name="ID" />
                                    <xs:attribute type="xs:string" name="PartIDKeys" />
                                    <xs:attribute type="xs:string" name="Status" />
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="Media" type="jdf:MediaType" />
                            <xs:element name="RunList" maxOccurs="unbounded" minOccurs="0">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="RunList2" maxOccurs="unbounded" minOccurs="0">
                                            <xs:complexType>
                                                <xs:sequence>
                                                    <xs:element name="LayoutElement" type="jdf:LayoutElementType" />
                                                </xs:sequence>
                                                <xs:attribute type="xs:byte" name="NPage" use="optional" />
                                                <xs:attribute type="xs:string" name="Pages" use="optional" />
                                                <xs:attribute type="xs:byte" name="Run" use="optional" />
                                                <xs:attribute type="xs:string" name="Status" use="optional" />
                                            </xs:complexType>
                                        </xs:element>
                                        <xs:element name="PageList" minOccurs="0">
                                            <xs:complexType>
                                                <xs:sequence>
                                                    <xs:element name="PageData" maxOccurs="unbounded" minOccurs="0">
                                                        <xs:complexType>
                                                            <xs:simpleContent>
                                                                <xs:extension base="xs:string">
                                                                    <xs:attribute type="xs:string" name="DescriptiveName" use="optional" />
                                                                    <xs:attribute type="xs:string" name="PageIndex" use="optional" />
                                                                </xs:extension>
                                                            </xs:simpleContent>
                                                        </xs:complexType>
                                                    </xs:element>
                                                </xs:sequence>
                                                <xs:attribute type="xs:string" name="Class" />
                                            </xs:complexType>
                                        </xs:element>
                                        <xs:element name="LayoutElement" type="jdf:LayoutElementType" />
                                    </xs:sequence>
                                    <xs:attribute type="xs:string" name="Class" use="optional" />
                                    <xs:attribute type="xs:string" name="ID" use="optional" />
                                    <xs:attribute type="xs:byte" name="NPage" use="optional" />
                                    <xs:attribute type="xs:string" name="PartIDKeys" use="optional" />
                                    <xs:attribute type="xs:string" name="Status" use="optional" />
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="ResourceLinkPool">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="LayoutLink">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute type="xs:string" name="Usage" />
                                            <xs:attribute type="xs:string" name="rRef" />
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="RunListLink" maxOccurs="unbounded" minOccurs="0">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute type="xs:string" name="ProcessUsage" use="optional" />
                                            <xs:attribute type="xs:string" name="Usage" use="optional" />
                                            <xs:attribute type="xs:string" name="rRef" use="optional" />
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="MediaLink">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute type="xs:string" name="Usage" />
                                            <xs:attribute type="xs:string" name="rRef" />
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute type="xs:string" name="Activation" />
            <xs:attribute type="xs:string" name="CommentURL" />
            <xs:attribute type="xs:string" name="DescriptiveName" />
            <xs:attribute type="xs:string" name="ICSVersions" />
            <xs:attribute type="xs:string" name="ID" />
            <xs:attribute type="xs:string" name="JobID" />
            <xs:attribute type="xs:string" name="JobPartID" />
            <xs:attribute type="xs:float" name="MaxVersion" />
            <xs:attribute type="xs:string" name="Status" />
            <xs:attribute type="xs:string" name="Type" />
            <xs:attribute type="xs:float" name="Version" />
        </xs:complexType>
    </xs:element>

    <xs:complexType name="FileSpecType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute ref="efi:validatecontent" use="optional" />
                <xs:attribute type="xs:string" name="MimeType" use="optional" />
                <xs:attribute type="xs:string" name="URL" use="optional" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="MediaType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute type="xs:string" name="Brand" use="optional" />
                <xs:attribute type="xs:string" name="Class" use="optional" />
                <xs:attribute type="xs:string" name="DescriptiveName" use="optional" />
                <xs:attribute type="xs:string" name="Dimension" use="optional" />
                <xs:attribute type="xs:byte" name="Grade" use="optional" />
                <xs:attribute type="xs:string" name="GrainDirection" use="optional" />
                <xs:attribute type="xs:string" name="Manufacturer" use="optional" />
                <xs:attribute type="xs:string" name="MediaType" use="optional" />
                <xs:attribute type="xs:string" name="MediaUnit" use="optional" />
                <xs:attribute type="xs:float" name="Thickness" use="optional" />
                <xs:attribute type="xs:byte" name="Weight" use="optional" />
                <xs:attribute type="xs:string" name="BackCoatings" use="optional" />
                <xs:attribute type="xs:byte" name="Brightness" use="optional" />
                <xs:attribute ref="efi:EFPaperCatalogID" use="optional" />
                <xs:attribute type="xs:string" name="FrontCoatings" use="optional" />
                <xs:attribute type="xs:string" name="HoleType" use="optional" />
                <xs:attribute type="xs:string" name="ID" use="optional" />
                <xs:attribute type="xs:string" name="MediaColorName" use="optional" />
                <xs:attribute type="xs:byte" name="MediaSetCount" use="optional" />
                <xs:attribute type="xs:string" name="MediaTypeDetails" use="optional" />
                <xs:attribute type="xs:string" name="Opacity" use="optional" />
                <xs:attribute type="xs:float" name="OpacityLevel" use="optional" />
                <xs:attribute type="xs:string" name="PrePrinted" use="optional" />
                <xs:attribute type="xs:string" name="ProductID" use="optional" />
                <xs:attribute type="xs:byte" name="RecycledPercentage" use="optional" />
                <xs:attribute type="xs:string" name="StockType" use="optional" />
                <xs:attribute type="xs:string" name="Texture" use="optional" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="LayoutElementType">
        <xs:sequence>
            <xs:element name="FileSpec" type="jdf:FileSpecType" />
        </xs:sequence>
    </xs:complexType>

</xs:schema>

EFI-JDF.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.efi.com/efijdf">
    <xs:attribute type="xs:string" name="EFPaperCatalogID" />
    <xs:attribute type="xs:string" name="validatecontent" />
</xs:schema>

SSiJDFExtensions.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.creo.com/SSI/JDFExtensions.xsd">
    <xs:attribute type="xs:string" name="Comp" />
    <xs:attribute type="xs:string" name="TrimBox1" />
    <xs:attribute type="xs:string" name="Dimension" />
    <xs:attribute type="xs:string" name="MediaOrigin" />
    <xs:attribute type="xs:string" name="WorkStyle" />
</xs:schema>

请注意名称为“布局”的 3 个元素。 我尝试使用 xjb 文件更改每个文件的类名,如下所示:

<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1">
    <bindings schemaLocation="MetrixJDF.xsd" version="1.0">
        <globalBindings localScoping="toplevel" />

        <schemaBindings xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
            <package name="com.metrixsoftware.vdp.jdf">
            </package>
        </schemaBindings>

        <bindings node="//xs:element[@name='JDF']">
            <bindings node="//xs:attribute[@ref='ssi:WorkStyle']">
                <property name="ssiWorkStyle" />
            </bindings>
        </bindings>

        <bindings
            node="//xs:element[@name='ResourcePool']/xs:complexType/xs:sequence/xs:element[@name='Layout']/xs:complexType/xs:sequence/xs:element[@name='Layout']/xs:complexType/xs:sequence/xs:element[@name='Layout']">
            <class name="Layout3" />
        </bindings>
        <bindings node="//xs:element[@name='ResourcePool']/xs:complexType/xs:sequence/xs:element[@name='Layout']/xs:complexType/xs:sequence/xs:element[@name='Layout']">
            <class name="Layout2" />
        </bindings>
        <bindings node="//xs:element[@name='ResourcePool']/xs:complexType/xs:sequence/xs:element[@name='Layout']">
            <class name="Layout1" />
        </bindings>
    </bindings>
</bindings>

那似乎行不通。 我没有收到关于 xjb 文件的任何错误,但是当我运行xjc时我仍然收到这些错误:

parsing a schema...
compiling a schema...
[ERROR] A class/interface with the same name "com.metrixsoftware.vdp.jdf.Layout" is already in use. Use a class customization to resolve this conflict.
    line 44 of file:/C:/Repo/Metrix/WEB-INF/classes/com/metrixsoftware/vdp/schemas/MetrixJDF.xsd
[ERROR] (Relevant to above error) another "Layout" is generated from here.
    line 47 of file:/C:/Repo/Metrix/WEB-INF/classes/com/metrixsoftware/vdp/schemas/MetrixJDF.xsd
[ERROR] A class/interface with the same name "com.metrixsoftware.vdp.jdf.Layout" is already in use. Use a class customization to resolve this conflict.
    line 44 of file:/C:/Repo/Metrix/WEB-INF/classes/com/metrixsoftware/vdp/schemas/MetrixJDF.xsd
[ERROR] (Relevant to above error) another "Layout" is generated from here.
    line 50 of file:/C:/Repo/Metrix/WEB-INF/classes/com/metrixsoftware/vdp/schemas/MetrixJDF.xsd
[ERROR] Two declarations cause a collision in the ObjectFactory class.
    line 50 of file:/C:/Repo/Metrix/WEB-INF/classes/com/metrixsoftware/vdp/schemas/MetrixJDF.xsd
[ERROR] (Related to above error) This is the other declaration.   
    line 44 of file:/C:/Repo/Metrix/WEB-INF/classes/com/metrixsoftware/vdp/schemas/MetrixJDF.xsd
[ERROR] Two declarations cause a collision in the ObjectFactory class.
    line 44 of file:/C:/Repo/Metrix/WEB-INF/classes/com/metrixsoftware/vdp/schemas/MetrixJDF.xsd
[ERROR] (Related to above error) This is the other declaration.   
    line 47 of file:/C:/Repo/Metrix/WEB-INF/classes/com/metrixsoftware/vdp/schemas/MetrixJDF.xsd

Failed to produce code.

版本信息:

$ "C:\Java\jdk1.6.0_45.64\bin\xjc.exe" -version
xjc version "JAXB 2.1.10 in JDK 6"
JavaTM Architecture for XML Binding(JAXB) Reference Implementation, (build JAXB 2.1.10 in JDK 6)

请指教。

我确实遇到了错误,但不是在 xjc 编译期间(使用 xjc 2.2.8-b130911.1802)而是由于 ResourcePool 中的静态类名 Layout 重复,生成的 Java 代码是非法的。 我也无法使用外部绑定解决此问题。

XML Schema 的以下修改 ——不改变 XML 布局允许生成正确的 Java 代码:

<xs:element name="ResourcePool">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Layout" type="jdf:LayoutLev1"/>
      <!-- keep the remainder of the element as it is -->

新的复杂类型:

<xs:complexType name="LayoutLev1">
  <xs:sequence>
    <xs:element name="Layout" type="jdf:LayoutLev2" maxOccurs="unbounded" minOccurs="0"/>                  

  </xs:sequence>
  <xs:attribute type="xs:string" name="Class" />
  <xs:attribute type="xs:string" name="DescriptiveName" />
  <xs:attribute type="xs:string" name="ID" />
  <xs:attribute type="xs:string" name="PartIDKeys" />
  <xs:attribute type="xs:string" name="Status" />
</xs:complexType>

<xs:complexType name="LayoutLev2">
  <xs:sequence>
    <xs:element name="Layout">
     <!-- keep the rest till the end of complexType -->

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM