Class TransformingNamespaces

java.lang.Object
org.apache.sis.xml.TransformingNamespaces
All Implemented Interfaces:
NamespaceContext
Direct Known Subclasses:
TransformingNamespaces.Inverse

class TransformingNamespaces extends Object implements NamespaceContext
In the associations between prefixes and namespaces, substitutes the namespaces used in JAXB annotations by the namespaces used in the XML document at marshalling time. This class is used internally by TransformingWriter and TransformedEvent only.
Since:
0.4
Version:
1.0
See Also:
  • Field Details

  • Constructor Details

    • TransformingNamespaces

      private TransformingNamespaces(NamespaceContext context, TransformVersion version)
      Creates a new namespaces transformer for the given target version.
  • Method Details

    • asXML

      static NamespaceContext asXML(NamespaceContext context, TransformVersion version)
      Given the context for namespaces used in our JAXB annotations, returns a context working with namespaces used in XML document. The returned context converts namespace arguments from XML to JAXB namespaces, and converts returned namespaces from JAXB to XML.
      Example: for a "http://www.isotc211.org/2005/gmd" namespace (legacy ISO 19139:2007) given in argument to getPrefixes(String), the context converts that namespace to all possible ISO 19115-3 namespaces (there is many) and returns the associated prefixes: "mdb", "cit", etc. Conversely given a "mdb", "cit", etc., prefix, getNamespaceURI(String) method returns the above-cited legacy GMD namespace.
    • asJAXB

      static NamespaceContext asJAXB(NamespaceContext context, TransformVersion version)
      Given a context for namespaces used in XML document, returns a context working with the namespaces used in our JAXB annotations. The returned context converts namespace arguments from JAXB to XML namespaces before to delegate to the wrapped context, and converts returned namespaces from XML to JAXB.

      This can be used when a XMLEventWriter has been created for writing a legacy XML document and we want to expose a TransformingWriter view to give to JAXB.

    • getNamespaceURI

      public String getNamespaceURI(String prefix)
      Returns the namespace for the given prefix. The same URI may be returned for many prefixes. For example, when exporting from ISO 19115-3:2016 to legacy ISO 19139:2007, the "mdb", "cit" and many other prefixes are all mapped to "http://www.isotc211.org/2005/gmd". This is legal according NamespaceContext javadoc.
      Specified by:
      getNamespaceURI in interface NamespaceContext
    • getPrefix

      public String getPrefix(String namespaceURI)
      Returns an arbitrary prefix for the given namespace. More than one prefix may be bounded to a namespace, in which case this method returns an arbitrary prefix (which may differ between different JVM executions).
      Specified by:
      getPrefix in interface NamespaceContext
    • getPrefixes

      public Iterator<String> getPrefixes(String namespaceURI)
      Returns all prefixes for the given namespace. For example, given the "http://www.isotc211.org/2005/gmd" namespace from legacy ISO 19139:2007, this method returns "mdb", "cit" and all other prefixes from the new ISO 19115-3:2016 specification which are used in replacement of the legacy "gmd" prefix.
      Specified by:
      getPrefixes in interface NamespaceContext