Class QualifyTargetNamespaceReferencesProcessor

  • All Implemented Interfaces:
    NodeProcessor

    public class QualifyTargetNamespaceReferencesProcessor
    extends Object
    implements NodeProcessor

    NodeProcessor which prepends the target namespace prefix to any unprefixed <xs:element ref="..."/> element references within a generated XML schema document.

    Schemagen may emit unprefixed ref attributes when referencing elements in the target namespace without declaring a default namespace (xmlns="...") on the root <xs:schema> element. According to W3C XML Schema rules, unprefixed QNames in attribute values resolve against the default namespace, so omitting both a prefix and a default namespace causes downstream validators (such as XJC) to report src-resolve.4.1: Error resolving component ... It was detected that ... has no namespace. This processor qualifies those references with the target namespace's prefix.

    Since:
    4.1.1
    Author:
    Lennart Jörelid
    • Constructor Detail

      • QualifyTargetNamespaceReferencesProcessor

        public QualifyTargetNamespaceReferencesProcessor​(String targetNamespacePrefix,
                                                         boolean hasDefaultNamespace)
        Creates a new QualifyTargetNamespaceReferencesProcessor.
        Parameters:
        targetNamespacePrefix - The prefix associated with the schema's targetNamespace.
        hasDefaultNamespace - true if the root <xs:schema> element declares a default namespace (i.e. xmlns="..."), in which case unprefixed QNames already legally resolve to it and must not be modified.
    • Method Detail

      • getModifiedCount

        public int getModifiedCount()
        Returns:
        The number of element reference nodes modified by this processor.
      • accept

        public boolean accept​(Node aNode)
        Defines if this visitor should process the provided node.
        Specified by:
        accept in interface NodeProcessor
        Parameters:
        aNode - The DOM node to process.
        Returns:
        true if the provided Node should be processed by this NodeProcessor.
      • process

        public void process​(Node aNode)
        Processes the provided DOM Node.
        Specified by:
        process in interface NodeProcessor
        Parameters:
        aNode - The DOM Node to process.