<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
<document>
    <header>
        <title>JPMS / Jigsaw Support in XmlBeans 4.0</title>
    </header>
    <body>
        <section>
            <title>Repackaging the schema files</title>

            <p>The schema generation has been modified in XmlBeans 4.0. Before the default path for the schemas was
                in schemaorg_apache_xmlbeans and the SchemaTypeSystem was fixed on the subdirectory structure.
            </p>

            <p>With XmlBeans 4.0 this is now a bit more dynamic. The default generation will be in the package
                <code>org.apache.xmlbeans.metadata</code>, which should be adapted to the project package name.
            </p>

            <p>This can be achieved by using the repackage options. Take the below example which is from the
                <a href="https://svn.apache.org/viewvc/poi/trunk/build.xml?view=markup">Apache POI build</a>.
                The repackage option is changing the package structure from
                <code>org.apache.xmlbeans.metadata</code>
                to <code>org.apache.poi.schemas.ooxml</code>.
            </p>

            <source><![CDATA[
                <taskdef name="xmlbean"
                         classname="org.apache.xmlbeans.impl.tool.XMLBean"
                         classpath="${ooxml.xmlbeans.jar}"/>

                <xmlbean
                    schema="${xmlbean.xsds.dir}"
                    srcgendir="${xmlbean.sources.dir}"
                    classgendir="${xmlbean.classes.dir}"
                    destfile="${xmlbean.xsds.dir}.jar"
                    srconly="true"
                    failonerror="true"
                    fork="true"
                    memoryMaximumSize="${ooxml.memory}"
                    typesystemname="ooxml"
                    repackage="org.apache.xmlbeans.metadata:org.apache.poi.schemas.ooxml">
                    <classpath>
                        <path location="${ooxml.xmlbeans.jar}"/>
                    </classpath>
                </xmlbean>
            ]]></source>

            <p>The schema files are relatively addressed by the TypeSystemHolder instance under
                <code>&lt;repackage name>/system/&lt;typesystemname></code>
                (e.g. /org/apache/poi/schemas/ooxml/system/ooxml)
            </p>
        </section>

        <section>
            <title>Manual generation of module-info.java</title>
            <p>The generation of the module-info.java isn't yet supported, hence you need to provide a module-info.java.
                In the case of Apache POI the module-info is injected as part of a multi-release configuration.
            </p>

            <section>
                <title>Example module-info.java</title>
                <p>Depending on the used JDK version, specifically for Java 9 and 10 you might need to include
                    <a href="https://search.maven.org/artifact/xml-apis/xml-apis/1.4.01/jar">xml-apis</a>.
                    More recent Java version work with the following dependency set:
                </p>

                <source><![CDATA[
                    open module <your-package-name> {
                        // this still throws "requires transitive directive for an automatic module" in JDK 14
                        // see https://bugs.openjdk.java.net/browse/JDK-8240847
                        requires transitive org.apache.xmlbeans;
                        requires java.xml;
                        exports <your-xml-schema-packages...>;
                    }
                ]]></source>

                <p>Currently it's necessary to open the schema classes module because of the dynamically loaded *.xsb files.
                    This limitation might be obsolete in future versions of XmlBeans.
                </p>
            </section>

        </section>
    </body>
</document>