XJC binding file: override package based on namespace instead of schemaLocation

怎甘沉沦 提交于 2019-12-11 09:49:01

问题


I'd like to override package for my schema via binding .xjb file.

It is done with:

<schemaBindings>
    <package name="com.schema.common" />
</schemaBindings>

JXC compiler expects context for above code, defined via schemaLocation.

I store .xsd and .xjb files in separate directories and this looks ugly (like all Java EE):

<bindings schemaLocation="../../../../wsdl/common_v47_0/CommonReqRsp.xsd">
    <schemaBindings>
        <package name="com.schema.common" />
    </schemaBindings>
</bindings>

It is possible to define bindings context without relative path in schemaLocation?

I dread XML Catalogs, we are in WEB 2.0 (or may be 4.0?) world.

I've seen SCD ("schema component designator"). It looks promising but I can't find reference for this syntax...


回答1:


Here is the magic of SCD:

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version='2.1'
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:tns="http://example/schema/common_v47_0">
    <bindings scd="x-schema::tns">
        <schemaBindings>
            <package name="com.schema.common" />
        </schemaBindings>
    </bindings>
</bindings>

All parts are important. SCD was introduced in version='2.1'.

I found reference at https://github.com/highsource/maven-jaxb2-plugin/wiki/Configure-Target-Packages-in-Binding-Files

SCD is extension of JAXB standard and implementation can be investigated in JAXB RI source tree:

  • upstream (with stripped history): https://github.com/eclipse-ee4j/jaxb-ri/tree/master/jaxb-ri/xsom/src/main/java/com/sun/xml/xsom/impl/scd
  • old sources: https://github.com/javaee/jaxb-v2/tree/master/jaxb-ri/xsom/src/main/java/com/sun/xml/xsom/impl/scd


来源:https://stackoverflow.com/questions/54565167/xjc-binding-file-override-package-based-on-namespace-instead-of-schemalocation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!