Red Hat Training
A Red Hat training course is available for Red Hat Fuse
第32章 基本的なデータバインディングの概念
概要
Apache CXF が型マッピングを処理する方法に適用される一般的なトピックがいくつかあります。
32.1. スキーマ定義の包含とインポート
概要
Apache CXF は、include および import スキーマタグを使用して、スキーマ定義の追加およびインポートをサポートします。これらのタグを使用すると、外部ファイルまたはリソースの定義をスキーマ要素のスコープに挿入できます。インクルードとインポートの本質的な違いは次のとおりです。
- インクルードは、囲んでいるスキーマ要素と同じターゲット名前空間に属する定義を取り込みます。
- インポートすると、囲んでいるスキーマ要素とは異なるターゲット名前空間に属する定義が取り込まれます。
xsd:include 構文
include ディレクティブの構文は次のとおりです。
<include schemaLocation="anyURI" />anyURI によって指定された参照スキーマは、囲んでいるスキーマと同じターゲット名前空間に属しているか、ターゲット名前空間にまったく属していない必要があります。参照されるスキーマがどのターゲット名前空間にも属していない場合は、含まれるときに、それを囲むスキーマの名前空間に自動的に採用されます。
例32.1「別のスキーマを含むスキーマの例」 は、別の XML スキーマドキュメントを含む XML スキーマドキュメントの例を示しています。
例32.1 別のスキーマを含むスキーマの例
<definitions targetNamespace="http://schemas.redhat.com/tests/schema_parser"
xmlns:tns="http://schemas.redhat.com/tests/schema_parser"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="http://schemas.redhat.com/tests/schema_parser"
xmlns="http://www.w3.org/2001/XMLSchema">
<include schemaLocation="included.xsd"/>
<complexType name="IncludingSequence">
<sequence>
<element name="includedSeq" type="tns:IncludedSequence"/>
</sequence>
</complexType>
</schema>
</types>
...
</definitions>例32.2「含まれるスキーマの例」 は、含まれているスキーマファイルの内容を示します。
例32.2 含まれるスキーマの例
<schema targetNamespace="http://schemas.redhat.com/tests/schema_parser"
xmlns="http://www.w3.org/2001/XMLSchema">
<!-- Included type definitions -->
<complexType name="IncludedSequence">
<sequence>
<element name="varInt" type="int"/>
<element name="varString" type="string"/>
</sequence>
</complexType>
</schema>xsd:import syntax
import ディレクティブの構文は次のとおりです。
<import namespace="namespaceAnyURI" schemaLocation="schemaAnyURI" />
インポートされた定義は、namespaceAnyURI ターゲット 名前空間に属している必要があります。namespaceAnyURI が空白であるか、指定されていない場合、インポートされたスキーマ定義は修飾されません。
例32.3「別のスキーマをインポートするスキーマの例」 は、別の XML スキーマをインポートする XML スキーマの例を示しています。
例32.3 別のスキーマをインポートするスキーマの例
<definitions targetNamespace="http://schemas.redhat.com/tests/schema_parser"
xmlns:tns="http://schemas.redhat.com/tests/schema_parser"
xmlns:imp="http://schemas.redhat.com/tests/imported_types"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="http://schemas.redhat.com/tests/schema_parser"
xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.redhat.com/tests/imported_types"
schemaLocation="included.xsd"/>
<complexType name="IncludingSequence">
<sequence>
<element name="includedSeq" type="imp:IncludedSequence"/>
</sequence>
</complexType>
</schema>
</types>
...
</definitions>例32.4「インポートされたスキーマの例」 インポートされたスキーマファイルの内容を示します。
例32.4 インポートされたスキーマの例
<schema targetNamespace="http://schemas.redhat.com/tests/imported_types"
xmlns="http://www.w3.org/2001/XMLSchema">
<!-- Included type definitions -->
<complexType name="IncludedSequence">
<sequence>
<element name="varInt" type="int"/>
<element name="varString" type="string"/>
</sequence>
</complexType>
</schema>参照されていないスキーマドキュメントの使用
サービスの WSDL ドキュメントで参照されていないスキーマドキュメントで定義されたタイプを使用することは、3 つのステップのプロセスです。
-
xsd2wsdlツールを使用して、スキーマドキュメントを WSDL ドキュメントに変換します。 生成された WSDL ドキュメントの
wsdl2javaツールを使用してタイプの Java を生成します。重要WSDL ドキュメントがサービスを定義していないことを示す警告が
wsdl2javaツールから表示されます。この警告は無視してかまいません。- 生成されたクラスをクラスパスに追加します。