JAXB for OGC - Java Bindings for OGC Schemas

This page introduces the OGC Schemas and Tools project which is developed for Java programmers who would like to use JAXB to work with XML schemas defined by the Open Geospatial Consortium, Inc (OGC).

This open-source project aims to provide Java bindings for all of the OGC XML Schemas.
OGC defines a number of standards (WMS, WFS, SLD etc.) which are widely used in GIS community. Many of these standards provide XML schemas (and sometimes DTDs) which define formats for XML documents.
When implementing GIS software in Java, developers often need to process XML data complying to these schemas. One of the popular technologies for XML processing is JAXB (Java Architecture for XML Binding).
JAXB comes with a schema compiler called XJC which consumes an XML schema and generates classes specific to the originating schema (schema-derived classes). Unfortunately, compiling OGC schemas with XJC is not easy:

  • OGC schemas rarely compile "as is". You typically need to provide special "binding" file which customizes compilation (for instance, renames classes or properties and so on).
  • OGC schemas have a lot of dependencies.
  • Some of OGC schemas are not valid per se.
  • Some of OGC schemas are defined in several versions.

 

The OGC Schemas project is aims to compile all of the OGC XML Schemas with JAXB schema compiler in order to make them usable in Java GIS environments via JAXB.

Supported schemas

This project provides bindings for most of the OGC schemas. Please see this page for the list of supported schemas.

We are working to provide bindings for *all* of the OGC schemas. Please let us know if the schema you are interested in is not supported yer.

Links

Please visit the project homepage:

A number of direct links:

License

The project is distributed under a modified BSD License. It is a commercial-software-friendly license, which is also compatible with GPL.

Credits

The project is led by Aleksei Valikov, senior software engineer, team lead and software architect working for the disy Informationssysteme GmbH. disy is a leading provider for spatial and environmental IT-solutions in Germany.

The project also contains numerous contributions from many individuals and companies.

Usage

There are two main ways to use this project:

  • Use the generated classes in your code
  • Use the JAXB bindings (binding.xjb) from this project and compile OGC schemas on your own

Using generated classes in your code

Below is a small code example which demonstrates parsing of the WMS 1.3.0 GetCapabilties-response:

// Create JAXB context for WMS 1.3.0
JAXBContext context = JAXBContext
.newInstance("net.opengis.wms.v_1_3_0");
// Use the created JAXB context to construct an unmarshaller
Unmarshaller unmarshaller = context.createUnmarshaller();
// GetCapabilities URL of the Demis WorldMap WMS Server
String url = "http://www2.demis.nl/wms/wms.asp?";
String url += REQUEST=GetCapabilities&VERSION=1.3.0&wms=WorldMap";
// Unmarshal the given URL, retrieve WMSCapabilities element
JAXBElement wmsCapabilitiesElement = unmarshaller
.unmarshal(new StreamSource(url), WMSCapabilities.class);
// Retrieve WMSCapabilities instance
WMSCapabilities wmsCapabilities = wmsCapabilitiesElement.getValue();
// Iterate over layers, print out layer names
for (Layer layer : wmsCapabilities.getCapability().getLayer()
.getLayer()) {
System.out.println(layer.getName());
}

Project JARs are available from central Maven repository, so you can simply add them as dependencies to your Maven project:

<dependency>
<groupId>org.jvnet.ogc</groupId>;
<artifactId>wms-v_1_3_0-schema</artifactId>
<version><!-- Version --></version>
</dependency>

Alternatively you can download the JARs, source code, Javadocs directly from the central Maven repository. See WMS 1.3.0 artifacts for example.

Using the JAXB bindings

If you wish to compile schemas on your own, you may still save some effort by reusing JAXB bindings from this project. To do this, check out or browse online the source code of the project.
Look for binding.xjb files in src/main/resources directories of the schema projects. Example: binding.xjb for GML 3.1.1.