You are here: Wiki>Documentation Web>XMLBeansBindings (09 Jul 2013, DanielNuest)Edit Attach

XMLBeansBindings

Many 52°North projects rely on XML processing functionality. We have created a wide set of XMLBeans-based precompiled XSD bindings. Those are available through our Maven repository and are created via a dedicated Maven project.

Available Bindings

tbd, see Maven repository in the mean time.

Source Code

Sources ar on GitHub: https://github.com/52North/common-xml

XMLBeans within OSGi Frameworks

Due to the heavy use of ClassLoaders within XMLBeans, using compiled XMLBeans within an OSGi environment (e.g. Eclipse Equinox, Apache Felix, ...) causes a lot of headaches. Using a simple XML schema most of the times works quite well with defining the correct Export-Package and Import-Package variations (see below). When it comes to complex schema hierarchies (e.g. OGC O&M 2.0 -depends on- OGC GML 3.2.1 -depends on- W3C XLink 1999, all provided as single OSGi modules) the OSGi ClassLoaders fail most of the time when accessing XML fragments in lower levels of that hierarchy (e.g. xlink:href attribute of an om:procedure).

Creating a Simple Bundle (no further schema dependencies)

OGC KML 2.2 has no external dependencies and thus can create a nice OSGi bundle. Simply add the Apache Felix maven-bundle-plugin to the project's build.

    <project>
                <groupId>my.osgi-enabled.kml</groupId>
                <artifactId>kml-xmlbeans</artifactId>
                <version>0.0.1-SNAPSHOT</version>
...
         <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <configuration>
               <instructions>
                  <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                  <Bundle-ContactAddress>info@52north.org</Bundle-ContactAddress>
                  <Bundle-Version>${project.version}</Bundle-Version>
                  <Export-Package>net.opengis.kml.x22.*</Export-Package>
                  <Import-Package>org.apache.xmlbeans.impl.schema;version="[2.5,3)",*</Import-Package>
               </instructions>
            </configuration>
            <executions>
               <execution>
                  <id>bundle-no-deps</id>
                  <phase>package</phase>
                  <goals>
                     <goal>bundle</goal>
                  </goals>
                  <inherited>false</inherited>
               </execution>
            </executions>
         </plugin>
...
    <dependencies>
            <dependency>
                        <groupId>org.apache.servicemix.bundles</groupId>
                        <artifactId>org.apache.servicemix.bundles.xmlbeans</artifactId>
                        <version>2.6.0_2</version>
            </dependency>
...
    <dependencies>
    </project>

We do not use the official xmlbeans release dependency but an OSGi-enabled repackage from Apache ServiceMix. The Module requiring access to the KML bindings must define these through the common Maven dependencies and within the maven-bundle-plugin configuration:

...
         <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.7</version>
            <extensions>true</extensions>
            <configuration>
               <instructions>
                  <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                  <Bundle-ContactAddress>info@52north.org</Bundle-ContactAddress>
                  <Bundle-Version>${project.version}</Bundle-Version>
                    <Import-Package>net.opengis.kml.x22.*,org.apache.xmlbeans.*,*</Import-Package>
               </instructions>
            </configuration>
            <executions>
               <execution>
                  <id>bundle-no-deps</id>
                  <phase>package</phase>
                  <goals>
                     <goal>bundle</goal>
                  </goals>
                  <inherited>false</inherited>
               </execution>
            </executions>
         </plugin>
...
    <dependencies>
            <dependency>
                        <groupId>my.osgi-enabled.kml</groupId>
                        <artifactId>kml-xmlbeans</artifactId>
                        <version>0.0.1-SNAPSHOT</version>
            </dependency>
...
    <dependencies>
...

Now we are ready to deploy the ServiceMix XMLBeans bundle, our KML bundle and the bundle which accesses KML to the OSGi framework.

Limitations

The most serious limitation is probably that the XmlObject.validate() will throw unexpected NullPointerExceptions. This is due to the fact that the validate() method is located in the xmlbeans-x.y.z.jar (= module). That module does not have any access to classes in the scope of our compiled schema bindings. This might work for leaf elements, but for a whole document will probably fail. [Solutions, workarounds much appreciated here!]

Workarounds

A dirty workaround for schema hierarchies would be to compile all schemas into one .jar (= module). Accessing XML fragments should work then, but still the previously stated limitations apply.

Topic revision: r2 - 09 Jul 2013, DanielNuest
Legal Notice | Privacy Statement


This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Wiki? Send feedback