Custom implementations
But you don't have to implement directly the metadata interfaces! If the underlying
storage framework allows access to metadata from their class and attribute names (either
Java names or ISO/OGC names), then it is possible to implement a single engine accessing
any kind of metadata and let the Java Virtual Machine implements the GeoAPI interfaces
on-the-fly, using the
java.lang.reflect.Proxy
class. See the Proxy javadoc for details, keeping in mind that the ISO/OGC name
of a java.lang.Class or java.lang.reflect.Method object can be
obtained as below:
UML uml = method.getAnnotation(UML.class);
if (uml != null) {
String name = uml.identifier();
// Fetch the metadata here.
}
This is exactly the approach taken by the geotk-metadata-sql module for providing an implementation of all GeoAPI metadata interfaces reading their values directly from a SQL database.
JAXBException)
The classes given to the JAXB marshaller must contain JAXB annotations, otherwise the following exception is thrown:
javax.xml.bind.JAXBException: class MyCustomClass
nor any of its super class is known to this context.
The easiest workaround is to wrap the custom implementation into one of the implementations
provided in the org.geotoolkit.metadata.iso package. All those Geotk implementation
classes provide shallow copy constructor for making that easy. Note that you need to wrap
only the root class, not the attributes. The attribute values will be wrapped automatically
as needed by JAXB adapters.