Binding JiBX代码生成错误:位于的format元素上的名称重复
我正在尝试使用JiBX代码生成工具为[OTA2003B]()提供的OTA模式生成代码(应用了自定义设置)。以下是我为实现相同目标而编写的代码 Maven pom.xml jibx Maven插件配置Binding JiBX代码生成错误:位于的format元素上的名称重复,binding,jibx,codegen,Binding,Jibx,Codegen,我正在尝试使用JiBX代码生成工具为[OTA2003B]()提供的OTA模式生成代码(应用了自定义设置)。以下是我为实现相同目标而编写的代码 Maven pom.xml jibx Maven插件配置 <!-- JiBX Maven Plugin --> <plugin> <groupId>org.jibx</groupId> <artifactId>jibx
<!-- JiBX Maven Plugin -->
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<customizations>
<customizations>src/test/resources/custom1.xml</customizations>
</customizations>
<schemaLocation>src/main/conf</schemaLocation>
<includeSchemas>
<includeSchema>FS_OTA_VehAvailRateRQ.xsd</includeSchema>
<includeSchema>FS_OTA_VehAvailRateRS.xsd</includeSchema>
</includeSchemas>
<schemaBindingDirectory>src/main/java</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>*binding.xml</includeSchemaBindings>
</includeSchemaBindings>
</configuration>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<goals>
<goal>schema-codegen</goal>
</goals>
</execution>
<execution>
<id>compile-the-binding-</id>
<goals>
<goal>bind</goal>
</goals>
</execution>
</executions>
</plugin>
<schema-set xmlns:xs="http://www.w3.org/2001/XMLSchema"
prefer-inline="true"
type-substitutions="xs:integer xs:int xs:decimal xs:float"
binding-per-schema="true">
<schema name="FS_OTA_VehAvailRateRQ.xsd"
includes="OTA_VehAvailRateRQ"
binding-file-name="otaVehAvailRateRQ_binding.xml"
package="com.poc.jibx.vehAvailRateRQ"/>
<schema name="FS_OTA_VehAvailRateRS.xsd"
includes="OTA_VehAvailRateRS"
binding-file-name="otaVehAvailRateRS_binding.xml"
package="com.poc.jibx.vehAvailRateRS"/>
</schema-set>
<!-- For applying custom_a.xml customization -->
<!--
<configuration>
<customizations>
<customization>src/test/resources/custom_a.xml</customization>
</customizations>
<schemaLocation>src/main/conf/OTA_Schemas</schemaLocation>
<includeSchemas>
<includeSchema>Common/*.xsd</includeSchema>
</includeSchemas>
<schemaBindingDirectory>src/main/java</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>*binding.xml</includeSchemaBindings>
</includeSchemaBindings>
<options>
<u>http://www.opentravel.org/OTA/2003/05</u>
</options>
</configuration>
-->
<!-- For applying custom_b.xml customization -->
<configuration>
<customizations>
<customization>src/test/resources/custom_b.xml</customization>
</customizations>
<schemaLocation>src/main/conf/OTA_Schemas</schemaLocation>
<includeSchemas>
<includeSchema>vehAvailRate/*.xsd</includeSchema>
</includeSchemas>
<schemaBindingDirectory>src/main/java</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>*binding.xml</includeSchemaBindings>
</includeSchemaBindings>
<options>
<i>src/main/java/base-binding.xml</i>
</options>
</configuration>
<schema-set prefer-inline="true" package="com.poc.jibx.ota.common"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
type-substitutions="xs:integer xs:int xs:decimal xs:float"
binding-file-name="base-binding.xml">
<schema name="OTA_CommonPrefs.xsd" />
<schema name="OTA_CommonTypes.xsd" />
<schema name="OTA_SimpleTypes.xsd" />
<schema name="OTA_VehicleCommonTypes.xsd">
<complexType name="VehicleProfileRentalPrefType">
<element path="**" name="VendorPref" ignore="true"/>
</complexType>
</schema>
</schema-set>
但是,当我将generate all=“false”附加到custom1.xml中的元素时,代码生成和绑定生成就完成了
成功。当我使用generate all=“false”
我可以看到,在上面显示的错误中提到的两个模式中,例如InventoryStatusType中的元素都是可用的。因此,问题出现了。但是我已经为在我的custom1.xml中生成的每个模式代码指定了preference inline=“true”和不同的包,这意味着对于这两个模式,InventoryStatusType的完全限定名(假设它将被创建为一个内部类)将不同,并且这不会产生像我遇到的那样的重复错误。1) 导致问题的原因是什么?generate all=“false”如何避免此问题?
2) 如何在不使用generate all=“false”的情况下解决重复名称错误?
<!-- JiBX Maven Plugin -->
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<customizations>
<customizations>src/test/resources/custom1.xml</customizations>
</customizations>
<schemaLocation>src/main/conf</schemaLocation>
<includeSchemas>
<includeSchema>FS_OTA_VehAvailRateRQ.xsd</includeSchema>
<includeSchema>FS_OTA_VehAvailRateRS.xsd</includeSchema>
</includeSchemas>
<schemaBindingDirectory>src/main/java</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>*binding.xml</includeSchemaBindings>
</includeSchemaBindings>
</configuration>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<goals>
<goal>schema-codegen</goal>
</goals>
</execution>
<execution>
<id>compile-the-binding-</id>
<goals>
<goal>bind</goal>
</goals>
</execution>
</executions>
</plugin>
<schema-set xmlns:xs="http://www.w3.org/2001/XMLSchema"
prefer-inline="true"
type-substitutions="xs:integer xs:int xs:decimal xs:float"
binding-per-schema="true">
<schema name="FS_OTA_VehAvailRateRQ.xsd"
includes="OTA_VehAvailRateRQ"
binding-file-name="otaVehAvailRateRQ_binding.xml"
package="com.poc.jibx.vehAvailRateRQ"/>
<schema name="FS_OTA_VehAvailRateRS.xsd"
includes="OTA_VehAvailRateRS"
binding-file-name="otaVehAvailRateRS_binding.xml"
package="com.poc.jibx.vehAvailRateRS"/>
</schema-set>
<!-- For applying custom_a.xml customization -->
<!--
<configuration>
<customizations>
<customization>src/test/resources/custom_a.xml</customization>
</customizations>
<schemaLocation>src/main/conf/OTA_Schemas</schemaLocation>
<includeSchemas>
<includeSchema>Common/*.xsd</includeSchema>
</includeSchemas>
<schemaBindingDirectory>src/main/java</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>*binding.xml</includeSchemaBindings>
</includeSchemaBindings>
<options>
<u>http://www.opentravel.org/OTA/2003/05</u>
</options>
</configuration>
-->
<!-- For applying custom_b.xml customization -->
<configuration>
<customizations>
<customization>src/test/resources/custom_b.xml</customization>
</customizations>
<schemaLocation>src/main/conf/OTA_Schemas</schemaLocation>
<includeSchemas>
<includeSchema>vehAvailRate/*.xsd</includeSchema>
</includeSchemas>
<schemaBindingDirectory>src/main/java</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>*binding.xml</includeSchemaBindings>
</includeSchemaBindings>
<options>
<i>src/main/java/base-binding.xml</i>
</options>
</configuration>
<schema-set prefer-inline="true" package="com.poc.jibx.ota.common"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
type-substitutions="xs:integer xs:int xs:decimal xs:float"
binding-file-name="base-binding.xml">
<schema name="OTA_CommonPrefs.xsd" />
<schema name="OTA_CommonTypes.xsd" />
<schema name="OTA_SimpleTypes.xsd" />
<schema name="OTA_VehicleCommonTypes.xsd">
<complexType name="VehicleProfileRentalPrefType">
<element path="**" name="VendorPref" ignore="true"/>
</complexType>
</schema>
</schema-set>
注意:使用generate all=“false”时,会生成绑定文件,但在编译绑定时,我会遇到以下错误:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jibx-sample 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- jibx-maven-plugin:1.2.3:schema-codegen (default-cli) @ jibx-sample ---
[INFO] Generating Java sources in src/main/java from schemas available in src/main/conf...
Loaded and validated 2 specified schema(s)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:InventoryStatusType; on format element at (source unknown)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:RatePeriodSimpleType; on format element at (source unknown)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:OffLocationServiceID_Type; on format element at (source unknown)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:VehicleTransmissionType; on format element at (source unknown)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.527s
[INFO] Finished at: Mon Sep 26 13:38:06 IST 2011
[INFO] Final Memory: 12M/84M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jibx:jibx-maven-plugin:1.2.3:schema-codegen (default-cli) on project jibx-sample: Terminating d
ue to errors in bindings -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:AddressType; on mapping element at (line 251, col 104, in otaVehAvai
lRateRS_binding.xml)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:CompanyNameType; on mapping element at (line 275, col 112, in otaVeh
AvailRateRS_binding.xml)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:LocationType; on mapping element at (line 324, col 106, in otaVehAva
ilRateRS_binding.xml)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:PersonNameType; on mapping element at (line 362, col 110, in otaVehA
vailRateRS_binding.xml)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:TPA_Extensions_Type; on mapping element at (line 383, col 118, in ot
aVehAvailRateRS_binding.xml)
Error: Duplicate mapping name not allowed for unmarshalling; on mapping element at (line 386, col 88, in otaVehAvailRateRS_binding
.xml)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:TelephoneType; on mapping element at (line 394, col 108, in otaVehAv
ailRateRS_binding.xml)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:EffectiveExpireOptionalDateGroup-AttributeGroup; on mapping element
at (line 418, col 161, in otaVehAvailRateRS_binding.xml)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:PrivacyGroup-AttributeGroup; on mapping element at (line 430, col 12
1, in otaVehAvailRateRS_binding.xml)
Error: Duplicate name {http://www.opentravel.org/OTA/2003/05}:VehicleCustomerType; on mapping element at (line 470, col 120, in ot
aVehAvailRateRS_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.CompanyNameType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.
CompanyNameType; on structure element at (line 13, col 166, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.CompanyNameType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.
CompanyNameType; on structure element at (line 28, col 144, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.LocationType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Loc
ationType; on structure element at (line 43, col 159, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.LocationType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Loc
ationType; on structure element at (line 44, col 159, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.CompanyNameType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.
CompanyNameType; on structure element at (line 51, col 118, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.TPAExtensionsType is incompatible with binding for class com.poc.jibx.vehAvailRateR
S.TPAExtensionsType; on structure element at (line 227, col 50, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.VehicleCustomerType is incompatible with binding for class com.poc.jibx.vehAvailRat
eRS.VehicleCustomerType; on structure element at (line 106, col 117, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.AddressType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Addr
essType; on structure element at (line 128, col 111, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.PersonNameType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.P
ersonNameType; on structure element at (line 130, col 140, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.TelephoneType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Te
lephoneType; on structure element at (line 131, col 136, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.LocationType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Loc
ationType; on structure element at (line 136, col 151, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.CompanyNameType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.
CompanyNameType; on structure element at (line 137, col 157, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.CompanyNameType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.
CompanyNameType; on structure element at (line 138, col 157, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.CompanyNameType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.
CompanyNameType; on structure element at (line 144, col 145, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.PrivacyGroup is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Pri
vacyGroup; on structure element at (line 187, col 133, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.PrivacyGroup is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Pri
vacyGroup; on structure element at (line 220, col 133, in otaVehAvailRateRQ_binding.xml)
Error: References to structure object must have compatible types: com.poc.jibx.vehAvailRateRQ.TPAExtensionsType cannot be used as
com.poc.jibx.vehAvailRateRS.TPAExtensionsType; on structure element at (line 227, col 50, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.PrivacyGroup is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Pri
vacyGroup; on structure element at (line 230, col 133, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.PersonNameType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.P
ersonNameType; on structure element at (line 253, col 134, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.TelephoneType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Te
lephoneType; on structure element at (line 256, col 125, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.PrivacyGroup is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Pri
vacyGroup; on structure element at (line 264, col 137, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.AddressType is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Addr
essType; on structure element at (line 271, col 119, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.PrivacyGroup is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Pri
vacyGroup; on structure element at (line 288, col 137, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.EffectiveExpireOptionalDateGroup is incompatible with binding for class com.poc.jib
x.vehAvailRateRS.EffectiveExpireOptionalDateGroup; on structure element at (line 295, col 197, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.PrivacyGroup is incompatible with binding for class com.poc.jibx.vehAvailRateRS.Pri
vacyGroup; on structure element at (line 300, col 137, in otaVehAvailRateRQ_binding.xml)
Error: Object type com.poc.jibx.vehAvailRateRQ.EffectiveExpireOptionalDateGroup is incompatible with binding for class com.poc.jib
x.vehAvailRateRS.EffectiveExpireOptionalDateGroup; on structure element at (line 307, col 197, in otaVehAvailRateRQ_binding.xml)
在收到Don的回复后更新此内容
发布该问题后,我在线查看了我试图从中生成代码的OTA模式(),发现上面链接中提供的和我拥有的不同。因此我认为模式的扁平化版本是不同的
我有可能是问题的根源,所以我下载了Schema的在线版本,它的结构合理,包括
通用模式,即
<xs:include schemaLocation="OTA_VehicleCommonTypes.xsd"/>
<xs:include schemaLocation="OTA_SimpleTypes.xsd"/>
<xs:include schemaLocation="OTA_CommonTypes.xsd"/>
<xs:include schemaLocation="OTA_CommonPrefs.xsd"/>
<xs:include schemaLocation="OTA_AirCommonTypes.xsd"/>
那么,现在我遗漏了什么或出错了,以及如何解决这个问题?
我编写的代码是否符合JiBX用户应该遵循的最佳实践,或者我可以做一些改进?
注:
生成的代码包和层次结构
src/main/java
com.poc.jibx.ota.common (Java Package)
com.poc.jibx.ota.vehAvailRateRQ (Java Package)
com.poc.jibx.ota.vehAvailRateRS (Java Package)
base-binding.xml
binding.xml
otaVehAvailRateRQ_binding.xml
otaVehAvailRateRS_binding.xml
src/main/java
com.poc.jibx.ota.common(Java包)
com.poc.jibx.ota.vehavalraterq(Java包)
com.poc.jibx.ota.vehavalraters(Java包)
base-binding.xml
binding.xml
otaVehAvailRateRQ_binding.xml
otaVehAvailRateRS_binding.xml
binding.xml内容:
<binding name="binding" package="com.poc.jibx.ota" trim-whitespace="true">
<include path="/myproject/jibx-sample/src/main/java/base-binding.xml" precompiled="true"/>
<include path="otaVehAvailRateRS_binding.xml"/>
<include path="otaVehAvailRateRQ_binding.xml"/>
</binding>
谢谢,吉格尼什吉格尼什 当您使用平面模式(模式前缀为FS_)时,最好不要一次编译多个模式,因为所有包含的模式都将在每个顶级模式中重复 由于您仍然需要不同的包名称,请将其拆分为两个项目,其中一个项目包括:
<includeSchemas>
<includeSchema>FS_OTA_VehAvailRateRQ.xsd</includeSchema>
</includeSchemas>
FS_OTA_VehAvailRateRQ.xsd
另一个包括:
<includeSchemas>
<includeSchema>FS_OTA_VehAvailRateRS.xsd</includeSchema>
</includeSchemas>
FS_OTA_VehAvailRateRS.xsd
这是在不使用generate all=“false”的情况下解决重复名称错误的最简单方法
Don谢谢你的回复。我明白你的意思。我尝试了一些替代方案,在发布我的问题后遇到了一些新的错误。我已经用代码和面临的错误更新了我的原始帖子。如果你能看一下并提供建议,那将非常有帮助。谢谢,Jignesh