2

[OTA2003B] ( http://www.opentravel.org/Specifications/SchemaIndex.aspx?FolderName=2003B )で利用可能な OTA スキーマのコード (カスタマイズが適用された) を生成しようとしています。私は同じことを達成するために書いています。

Maven pom.xml jibx-maven-plugin 構成

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

カスタマイズ XML: custom1.xml

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

構成されたスキーマからコードを生成しようとすると、バインド ファイルなしでコードが生成され、次のエラーが発生します。

[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

ただし、custom1.xml の <shema-set> 要素にgenerate-all="false"を追加すると、コード生成とバインディング生成が正常に行われます。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)
Generated 11 top-level classes (plus 40 inner classes) in package com.poc.jibx.vehAvailRateRQ
Generated 24 top-level classes (plus 69 inner classes) in package com.poc.jibx.vehAvailRateRS
Total top-level classes in model: 35
Total classes (including inner classes) in model: 144
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.574s
[INFO] Finished at: Mon Sep 26 14:08:11 IST 2011
[INFO] Final Memory: 12M/84M
[INFO] ------------------------------------------------------------------------

両方のスキーマで、上記のエラーで参照されている要素が指定されていることがわかります。たとえば、InventoryStatusTypeが利用可能です。これにより、問題が発生しています。 my custom1.xmlで生成される各スキーマコード。つまり、両方のスキーマでInventoryStatusTypeの完全修飾名(これが内部クラスとして作成されると仮定) は異なり、これにより次のような重複エラーが発生することはありません。遭遇しています。
1)問題の原因は何ですか?また、generate-all="false"でこの問題を回避するにはどうすればよいですか?
2) generate-all="false" を使用せずに重複した名前エラーを解決する方法は?

注: generate-all="false" バインディング ファイルを使用すると生成されますが、バインディングのコンパイル時に次のエラーに直面します。

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)

ドンの返信を受け取った後のこれに関する更新

問題を投稿した後、OTA スキーマをオンラインで表示しました ( http://www.opentravel.org/Specifications/SchemaIndex.aspx?FolderName=2003B ) コードを生成しようとしていたところ、上記のリンクで入手できるものを見つけました。私が持っていたものは異なっていたので、私が持っていたスキーマのフラット化されたバージョンが問題を引き起こしているのではないかと考えました.それで、共通のスキーマが含まれているという意味で適切に構造化されたスキーマのオンラインバージョンをダウンロードしました.

<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"/>

注: このスキーマ定義のスキーマ要素に関連するエラーが発生していたため、コードで OTA_AirCommonTypes.xsd を使用していません。

そこで、(http://jibx.sourceforge.net/fromschema/example-modular.html) について言及されているモジュラー生成手法が役立つと考えました。私は同じことを進め、以下は私が書いたコードです:

jibx-maven-plugin 構成

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

マイ カスタマイズ XML

custom_a.xml

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

custom_b.xml

<schema-set prefer-inline="true" 
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        type-substitutions="xs:integer xs:int xs:decimal xs:float" >

   <name-converter strip-prefixes="OTA_"
      strip-suffixes="Type AttributeGroup Group Attributes"/>

    <schema name="OTA_VehAvailRateRQ.xsd" 
        includes="OTA_VehAvailRateRQ" binding-file-name="otaVehAvailRateRQ_binding.xml"
        package="com.poc.jibx.ota.vehAvailRateRQ" />

    <schema name="OTA_VehAvailRateRS.xsd" 
        includes="OTA_VehAvailRateRS" binding-file-name="otaVehAvailRateRS_binding.xml"
        package="com.poc.jibx.ota.vehAvailRateRS" />             
</schema-set>

まず、コードを生成するcustom_a.xmlを適用し、バインディング (base-binding.xml) を正常にコンパイルする jibx:bind ゴールを実行しました。次に、custom_a.xml を適用するための構成セクションをコメントし、 custom_b.xmlを適用するための構成セクションを有効にすると 、コードは正常に生成されましたが、バインディング コンパイラを実行すると次のエラーが発生しました。

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building jibx-sample 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- jibx-maven-plugin:1.2.3:bind (default-cli) @ jibx-sample ---
[INFO] Running JiBX binding compiler (single-module mode) on 4 binding file(s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.693s
[INFO] Finished at: Mon Sep 26 20:57:56 IST 2011
[INFO] Final Memory: 12M/69M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jibx:jibx-maven-plugin:1.2.3:bind (default-cli) on project jibx-sample: Internal error - cannot
 modify class com.poc.jibx.ota.common.ActionType loaded from /media/data/Practice/SpringRoo/jibx-sample/target/classes -> [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

それで、私が欠けている、または間違っているのは何ですか、これを修正する方法は何ですか? また、私が書いたコードは、JiBX ユーザーが従うべきベスト プラクティスに沿っていますか、それとも私ができる改善点はありますか?

ノート:

生成されたコード パッケージと階層

ソース/メイン/Java
    com.poc.jibx.ota.common (Java パッケージ)
    com.poc.jibx.ota.vehAvailRateRQ (Java パッケージ)
    com.poc.jibx.ota.vehAvailRateRS (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>

ありがとう、
ジグネッシュ

4

1 に答える 1

1

ジグネシュ、

フラット スキーマ (FS_ で始まるスキーマ) を使用している場合は、含まれているすべてのスキーマが各最上位スキーマで複製されるため、一度に複数のスキーマをコンパイルしないことをお勧めします。

とにかく異なるパッケージ名が必要なので、これを 2 つのプロジェクトに分割します。

<includeSchemas>
    <includeSchema>FS_OTA_VehAvailRateRQ.xsd</includeSchema>
</includeSchemas>

これを含む別のもの:

<includeSchemas>
    <includeSchema>FS_OTA_VehAvailRateRS.xsd</includeSchema>
</includeSchemas>

これは、generate-all="false" を使用せずに重複名エラーを解決する最も簡単な方法です。

ドン

于 2011-09-26T13:31:40.337 に答える