XJC编译结果是随机的,导致不同的编组XML

时间:2010-12-29 07:46:23

标签: jaxb xjc

当随后使用xjc版本“2.2.3-hudson-jaxb-ri-2.2-70-”两次时,它会生成两个不同的编译结果。问题是来自xjc编译结果1的java文件编组的XML与来自xjc编译结果2的java文件编写的XML文件不同(和错误)。

结果XML的差异在名称空间前缀ns2上出现/未出现:

<Activity Id="Id task1" Name="Task 1">
    <Implementation>
        <ns2:Task/>
    </Implementation>
</Activity>

负责产生不同XML的java代码的差异在@XMLElements中是不同的顺序 使用以下顺序,名称空间前缀出现在结果XML中:

@XmlElements({
@XmlElement(name = "BlockActivity", namespace = "http://www.wfmc.org/2002/XPDL1.0", type = org.wfmc._2002.xpdl1.BlockActivity.class),
@XmlElement(name = "BlockActivity", type = org.wfmc._2008.xpdl2.BlockActivity.class),

使用以下顺序,结果XML中不会出现名称空间前缀:

@XmlElements({
@XmlElement(name = "BlockActivity", type = org.wfmc._2008.xpdl2.BlockActivity.class),
@XmlElement(name = "BlockActivity", namespace = "http://www.wfmc.org/2002/XPDL1.0", type = org.wfmc._2002.xpdl1.BlockActivity.class),

我编译bpmnxpdl_31.xsd

xjc.bat -verbose -no-header c:\TEMP\bpmnxpdl_31.xsd -b c:\TEMP\binding.xjb

with binding.xjb:

<jxb:bindings node="xsd:element[@name='Activity']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Status']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Status"/>
  </jxb:bindings>
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='StartMode']/xsd:simpleType">
      <jxb:typesafeEnumClass name="StartMode"/>
  </jxb:bindings>
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='FinishMode']/xsd:simpleType">
      <jxb:typesafeEnumClass name="FinishMode"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='ActivitySet']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='AdHocOrdering']/xsd:simpleType">
      <jxb:typesafeEnumClass name="AdHocOrdering"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='Artifact']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='ArtifactType']/xsd:simpleType">
      <jxb:typesafeEnumClass name="ArtifactType"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='Assignment']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='AssignTime']/xsd:simpleType">
      <jxb:typesafeEnumClass name="AssignTime"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='Association']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='AssociationDirection']/xsd:simpleType">
      <jxb:typesafeEnumClass name="AssociationDirection"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='BasicType']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Type']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Type"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='BlockActivity']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='View']/xsd:simpleType">
      <jxb:typesafeEnumClass name="View"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='Condition']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Type']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Type"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='ConformanceClass']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='GraphConformance']/xsd:simpleType">
      <jxb:typesafeEnumClass name="GraphConformance"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='ConformanceClass']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='BPMNModelPortabilityConformance']/xsd:simpleType">
      <jxb:typesafeEnumClass name="BPMNModelPortabilityConformance"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='DataMapping']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Direction']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Direction"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='Deadline']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Execution']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Execution"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='EndEvent']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Result']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Result"/>
  </jxb:bindings>
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Implementation']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Implementation"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='EndPoint']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='EndPointType']/xsd:simpleType">
      <jxb:typesafeEnumClass name="EndPointType"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='FormalParameter']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Mode']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Mode"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='Icon']">
  <jxb:bindings node="./xsd:complexType/xsd:simpleContent/xsd:extension/xsd:attribute[@name='SHAPE']/xsd:simpleType">
      <jxb:typesafeEnumClass name="SHAPE"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='IntermediateEvent']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Trigger']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Trigger"/>
  </jxb:bindings>
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Implementation']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Implementation"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='Join']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Type']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Type"/>
  </jxb:bindings>
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='ExclusiveType']/xsd:simpleType">
      <jxb:typesafeEnumClass name="ExclusiveType"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='Loop']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='LoopType']/xsd:simpleType">
      <jxb:typesafeEnumClass name="LoopType"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='LoopMultiInstance']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='MI_Ordering']/xsd:simpleType">
      <jxb:typesafeEnumClass name="MI_Ordering"/>
  </jxb:bindings>
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='MI_FlowCondition']/xsd:simpleType">
      <jxb:typesafeEnumClass name="MI_FlowCondition"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='LoopStandard']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='TestTime']/xsd:simpleType">
      <jxb:typesafeEnumClass name="TestTime"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='ParticipantType']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Type']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Type"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='Pool']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Orientation']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Orientation"/>
  </jxb:bindings>
</jxb:bindings>

<jxb:bindings node="xsd:element[@name='ProcessHeader']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='DurationUnit']/xsd:simpleType">
      <jxb:typesafeEnumClass name="DurationUnit">
        <jxb:typesafeEnumMember value="M" name="Month" />
        <jxb:typesafeEnumMember value="m" name="Minute" />
      </jxb:typesafeEnumClass>
  </jxb:bindings>
</jxb:bindings>


<jxb:bindings node="xsd:element[@name='StartEvent']">
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Trigger']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Trigger"/>
  </jxb:bindings>
  <jxb:bindings node="./xsd:complexType/xsd:attribute[@name='Implementation']/xsd:simpleType">
      <jxb:typesafeEnumClass name="Implementation"/>
  </jxb:bindings>
</jxb:bindings>

有没有办法在后续的XJC运行中获得@XMLElements的稳定顺序?

2 个答案:

答案 0 :(得分:1)

http://java.net/jira/browse/JAXB-618 根据上面的链接,这是在2.2分支上修复的,但我在2.2.5 jax-ws下载甚至每晚构建时都遇到了同样的问题。

答案 1 :(得分:1)

我认为您可以通过指定custom namespace prefix mapper来解决此问题。不解决核心问题,但可以帮助您确定名称空间。