patrodyne / hisrc-higherjaxb

The most advanced JAXB Maven Plugin for XJC (XML Schema compilation).
BSD 3-Clause "New" or "Revised" License
8 stars 0 forks source link

Annox namespace no longer available at jvnet.org #4

Closed rconnacher closed 11 months ago

rconnacher commented 11 months ago

I've been using maven plugins to generate pojos from XMLSchema via xjc in the JAXB2 world, and migrating now to Jakarta and JAXB3. I'm trying to replace the use of org.jvnet.jaxb2_commons.jaxb2-namespace-prefix with hisrc-higherjaxb-annox to preserve XML namespaces.

Samples and documentation (and answers on Stack Overflow) specify the use of the following bindings attributes when using this package in my global.xjb:

<jaxb:bindings version="3.0" xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:annox="http://jvnet.org/basicjaxb/xjc/annox" jaxb:extensionBindingPrefixes="annox" >

However, the "annox" namespace as specified ("http://jvnet.org/basicjaxb/xjc/annox") is unreachable. Do you have a new URI for it, or can you otherwise suggest a workaround? Thanks very much!

patrodyne commented 11 months ago

Thank you for the question. No workaround is required and XJC does not try to reach the URI, http://jvnet.org/basicjaxb/xjc/annox when used as a xmlns:annox declaration. This standalone sample hisrc-hyperjaxb-annox-sample-annotate-2.1.0-mvn-src.zip can be unzipped and tested using mvn clean test. It uses the hisrc-hyperjaxb-annox plugin and the http://jvnet.org/basicjaxb/xjc/annox namespace to add annotations to your locally schema derived classes at ../target/generated-sources/xjc/org/jvnet/hyperjaxb_annox/basics/sample/annotate.

Here is an explanation of why the URI is not (in general) a URL.

When specifying XML namespace prefixes, the right hand side is a URI and it is often not intended to be a URL. As a URI, it is not necessarily intended as an address to get a resource. It is just an identifier. Two HiSrc projects hisrc-basicjaxb-annox and hisrc-hyperjaxb-annox use this URI http://jvnet.org/basicjaxb/xjc/annox only as an identifier. That URI originates in the Java code that comprise the libraries and plugins that the projects distribute. The URI is a signal, in the code, that its library is being requested, on the class path, by JAXBContext or by the xjc code generator. Because its predecessor (old http://annox.dev.java.net) was first defined for use by the libraries (15+ years ago), the original use case was separate from the use case of XML schema design for validation and/or code generation for that namespace. Thus, in general, there is no schema location (URL) for the associated XML Schema document.

Note: The URI declaration is at Constants and it is used in XAnnotationParser, AnnotatePlugin and RemoveAnnotationPlugin. As the code shows, it is a code first design for this URI. In other words, no schema URL.

However, there is a reference document for download from annox.xsd. This XSD is reverse engineered from the code and describes the format of the *.ann.xml files used by hisrc-basicjaxb-annox . However again, that XSD does not attempt to reverse engineer the definitions in AnnotatePlugin, RemoveAnnotationPlugin and AnnotationTarget from hisrc-hyperjaxb-annox. The latter use case refers to the namespace usage in the binding files or schema files used by the XJC plugin.

With the caveat that the annox.xsd is reverse engineered, the use case for the *.ann.xml files can configure the schemaLocation of the annox.xsd URL as follows:

<class
    xmlns="http://jvnet.org/basicjaxb/xjc/annox"
    xmlns:jaxb="http://jvnet.org/basicjaxb/xjc/annox/jakarta.xml.bind.annotation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://jvnet.org/basicjaxb/xjc/annox https://github.com/patrodyne/hisrc-basicjaxb-annox/releases/download/2.1.0/annox.xsd"
>
...
</class>

Note: In this last example, xsi:schemaLocation="URI URL is used to bind the URI (http://jvnet.org/basicjaxb/xjc/annox) to the reachable URL (https://github.com/patrodyne/hisrc-basicjaxb-annox/releases/download/2.1.0/annox.xsd).

rconnacher commented 11 months ago

Wow, thanks for a very helpful (and educational) answer!