XPDL - 生成JAXB类时出错

时间:2012-09-16 15:18:08

标签: jaxb marshalling bpmn unmarshalling

在我公司的项目中,我正在构建一个非常简单的业务流程引擎。要做到这一点,我从BPMN的结构开始,现在我正在深入XPDL。 我从http://www.xpdl.org/下载了XPDL xsd,我尝试使用xjc及其包装eclipse插件从这个xsd生成类。 它失败,因为冲突错误如下

parsing a schema...
[ERROR] Property "TimeDate" is already defined. Use <jaxb:property> to resolve this conflict.
  line 3558 of file:/home/alberto/Job/WSP/orch/orch.model/src/main/resources/bpmnxpdl_40a.xsd

Honestely我不知道 1)为什么像这样的官方和标准xsd有这种问题 2)如何解决?

1 个答案:

答案 0 :(得分:0)

问题

如果您查看TriggerTime元素,您会看到有一个名为TimeDate的元素和属性。这在XML中不是问题,但默认情况下,JAXB实现将尝试将这两个项映射到导致冲突的同一Java属性。

<xsd:element name="TriggerTimer">
    <xsd:annotation>
        <xsd:documentation>BPMN: If the Trigger Type is Timer then this must be present</xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
        <xsd:sequence>
            <xsd:choice>
                <xsd:element name="TimeDate" type="xpdl:ExpressionType"/>
                <xsd:element name="TimeCycle" type="xpdl:ExpressionType"/>
            </xsd:choice>
            <xsd:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="TimeDate" type="xsd:string" use="optional">
            <xsd:annotation>
                <xsd:documentation>Deprecated</xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
        <xsd:attribute name="TimeCycle" type="xsd:string" use="optional">
            <xsd:annotation>
                <xsd:documentation>Deprecated</xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
        <xsd:anyAttribute namespace="##other" processContents="lax"/>
    </xsd:complexType>
</xsd:element>

解决方案(binding.xml)

外部绑定文件可用于自定义JAXB实现如何从XML模式生成Java modeld。下面是一个重命名生成的属性之一的示例:

<jxb:bindings
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">

    <jxb:bindings schemaLocation="bpmnxpdl_40a.xsd">
        <jxb:bindings node="//xsd:element[@name='TriggerTimer']/xsd:complexType/xsd:attribute[@name='TimeDate']">
            <jxb:property name="timeDateAttr"/>
        </jxb:bindings>
    </jxb:bindings>

</jxb:bindings>

XJC致电

-b选项用于在使用XJC实用程序时指定绑定文件。

xjc -b binding.xml bpmnxpdl_40a.xsd