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

时间:2015-11-10 18:02:38

标签: java xsd jaxb jdf

我有一个具有相同名称的多个级别的大型架构。 (我没有写它!)

这是:

<?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>

注意名称为&#34; Layout&#34;的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)

请告知。

1 个答案:

答案 0 :(得分:1)

我确实遇到了错误,但它不是在xjc编译期间(使用xjc 2.2.8-b130911.1802),但由于ResourcePool中的重复静态类名布局,生成的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 -->