java.lang.Object
org.codehaus.mojo.jaxb2.schemageneration.postprocessing.schemaenhancement.ChangeNamespacePrefixProcessor
All Implemented Interfaces:
NodeProcessor

public class ChangeNamespacePrefixProcessor extends Object implements NodeProcessor

NodeProcessor which alters the namespace prefix for all relevant Nodes within an XML document Node. It alters namespace prefixes in the following logical places:

Schema Namespace Definition
xmlns:oldPrefix="http://some/namespace" is altered to xmlns:newPrefix="http://some/namespace"
Elements Namespace Prefix
<oldPrefix:someElement ... > is altered to <newPrefix:someElement ... >
Element Reference
<xs:element ref="oldPrefix:aRequiredElementInTheOldPrefixNamespace"/> is altered to <xs:element ref="newPrefix:aRequiredElementInTheOldPrefixNamespace"/>
Type Attribute
<xs:element type="oldPrefix:something"/> is altered to <xs:element type="newPrefix:something"/>
Type Extension
<xs:extension base="oldPrefix:something"/> is altered to <xs:extension base="newPrefix:something"/>
Since:
1.4
  • Field Details

  • Constructor Details

    • ChangeNamespacePrefixProcessor

      public ChangeNamespacePrefixProcessor(String oldPrefix, String newPrefix)
      Creates a new ChangeNamespacePrefixProcessor providing the oldPrefix which should be replaced by the newPrefix.
      Parameters:
      oldPrefix - The old/current namespace prefix
      newPrefix - The new/substituted namespace prefix
  • Method Details

    • 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.
    • isNamespaceDefinition

      private boolean isNamespaceDefinition(Attr attribute)
      Discovers if the provided attribute is the oldPrefix namespace definition, i.e. if the given attribute is the xmlns:[oldPrefix] within the schema Element.
      Parameters:
      attribute - the attribute to test.
      Returns:
      true if the provided attribute is the oldPrefix namespace definition, i.e. if the given attribute is the xmlns:[oldPrefix] within the schema Element.
    • isElementReference

      private boolean isElementReference(Attr attribute)
      Discovers if the provided attribute is a namespace reference to the oldPrefix namespace, on the form <xs:element ref="oldPrefix:anElementInTheOldPrefixNamespace"/>
      Parameters:
      attribute - the attribute to test.
      Returns:
      true if the provided attribute is named "ref" and starts with [oldPrefix]:, in which case it is a reference to the oldPrefix namespace.
    • isTypeAttributeWithPrefix

      private boolean isTypeAttributeWithPrefix(Attr attribute)
      Discovers if the provided attribute is a type attribute using the oldPrefix namespace, on the form <xs:element type="oldPrefix:anElementInTheOldPrefixNamespace"/>
      Parameters:
      attribute - the attribute to test.
      Returns:
      true if the provided attribute is named "type" and starts with [oldPrefix]:, in which case it is a type in the oldPrefix namespace.
    • isExtension

      private boolean isExtension(Attr attribute)
      Discovers if the provided attribute is a namespace reference to the oldPrefix namespace, on the form

           <xs:extension base="[oldPrefix]:importItem">
       
      Parameters:
      attribute - the attribute to test.
      Returns:
      true if the provided attribute is named "extension" and starts with [oldPrefix]:, in which case it is a reference to the oldPrefix namespace.