XJC を使用して XSD から Java POJO を生成するアプリケーションに取り組んでいます。数十のスキーマがあり、その数は増えるでしょう。また、アプリケーションは、同じスキーマの異なるバージョンを処理できる必要があります。つまり、共通の型を定義する複数のスキーマを持つことになります。特定のコア タイプが共通のインターフェイスを実装するようにバインディングをカスタマイズしようとしています。JAXB2 Basics の Inheritance プラグインは、私が必要としている機能を果たしているようですが、正しい構文を理解できていないようです。
私のスキーマの関連部分は次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://example.com/core"
targetNamespace="http://example.com/core"
xmlns:xml="http://www.w3.org/XML/1998/namespace">
...
<xs:complexType name="addressType">
<xs:sequence>
<xs:element name="Address" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="Province" type="xs:string"/>
<xs:element name="Country" type="xs:string"/>
<xs:element name="County" type="xs:string" minOccurs="0"/>
<xs:element name="PostalCode" type="xs:string"/>
</xs:sequence>
</xs:complexType>
...
</xs:schema>
...そして、これは私のカスタムバインディングファイルがどのように見えるかです:
<?xml version="1.0"?>
<jaxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
xmlns:my="http://example.com/core"
jaxb:extensionBindingPrefixes="inheritance"
version="2.1">
<jaxb:bindings scd="x-schema::my" xmlns:my="http://example.com/core">
<jaxb:globalBindings localScoping="toplevel">
<jaxb:serializable/>
<xjc:simple/>
</jaxb:globalBindings>
<jaxb:bindings scd="/type::my:addressType">
<inheritance:implements>com.mysite.validator.ValidatableAddress</inheritance:implements>
<!--<xjc:superInterface name="com.mysite.validator.ValidatableAddress"/>-->
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
継承プラグインの使用方法を示すすべての「従来の」バインディングの例では、schemaLocationが指定されているため、私はscdアプローチを使用しています。スキーマの数が多い (そして増加している) ため、schemaLocationを指定する必要は避けたいと考えています。新しいスキーマを追加するたびにバインディング ファイルを変更する必要はありません。したがって、scdはこの要件を満たしているようです。
ただし、上記のバインディングを使用してビルドを実行すると、次のようになります。
[xjc] [ERROR] cvc-elt.1: Cannot find the declaration of element 'inheritance:implements'. [xjc] line 18 of file:/dev/workspace/my_app/etc/schemas/bindings-common.xml [xjc] failure in the XJC task. Use the Ant -verbose switch for more details [xjc] classLoader = java.net.URLClassLoader@ebcdbb [xjc] SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@14562c5
inheritance:implements行をコメントアウトし、 xjc:superInterface行のコメントを外すと、エラーはなくなり、ビルドは正常に完了しますが、私のAddressTypeクラスは ValidatableAddress タイプを実装していません。
継承プラグインをscdで使用できますか? xjc:superInterface を特定の要素のみに制限できますか?
乾杯。