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

发布于 2024-10-09 12:54:22 字数 9224 浏览 4 评论 0原文

当随后使用 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>

Java 代码中的差异负责不同的结果 XML,@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

与绑定.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 的稳定顺序?

When xjc version "2.2.3-hudson-jaxb-ri-2.2-70-" is used subsequently two times, it generates two different compile results. Issue is that XML marshalled by java files from xjc compile result 1 is different (and wrong) from XML file mashalled by java files from xjc compile result 2.

Difference in result XMLs is occurence/not occurence on namespace prefix ns2:

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

Difference in java code, responsible for different resulting XMLs, is different order in @XMLElements.
With the following order, namespace prefix occurs in the result 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),

With the following order, namespace prefix does NOT occur in the result 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),

I compile 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>

Is there a way to get stable order of @XMLElements in subsequent runs of XJC?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似狗非友 2024-10-16 12:54:22

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

http://java.net/jira/browse/JAXB-618
According to the link above this is fixed on the 2.2 branch, but I'm hitting the same issue with the 2.2.5 jax-ws download and even the nightly build.

深海不蓝 2024-10-16 12:54:22

我认为您可以通过指定自定义命名空间前缀映射器来解决此问题。不能解决核心问题,但可以帮助您确定命名空间。

I think you can address this issue by specifying a custom namespace prefix mapper. Does not solve the core issue, but may help you get the namespaces deterministic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文