Package groovy.xml

Class NamespaceBuilderSupport

All Implemented Interfaces:
GroovyObject

public class NamespaceBuilderSupport extends BuilderSupport
A helper class for creating namespaced GroovyMarkup
  • Constructor Details

    • NamespaceBuilderSupport

      public NamespaceBuilderSupport(BuilderSupport builder)
      Creates a namespace-aware wrapper around the supplied builder.
      Parameters:
      builder - the builder to wrap
    • NamespaceBuilderSupport

      public NamespaceBuilderSupport(BuilderSupport builder, String uri)
      Creates a namespace-aware wrapper and binds the default prefix to the supplied namespace URI.
      Parameters:
      builder - the builder to wrap
      uri - the namespace URI to bind to the default prefix
    • NamespaceBuilderSupport

      public NamespaceBuilderSupport(BuilderSupport builder, String uri, String prefix)
      Creates a namespace-aware wrapper and binds the supplied prefix to the supplied namespace URI.
      Parameters:
      builder - the builder to wrap
      uri - the namespace URI to bind
      prefix - the prefix to associate with uri
    • NamespaceBuilderSupport

      public NamespaceBuilderSupport(BuilderSupport builder, String uri, String prefix, boolean autoPrefix)
      Creates a namespace-aware wrapper with optional automatic prefixing for unqualified method names.
      Parameters:
      builder - the builder to wrap
      uri - the namespace URI to bind
      prefix - the prefix to associate with uri
      autoPrefix - whether the configured prefix should be applied automatically
    • NamespaceBuilderSupport

      public NamespaceBuilderSupport(BuilderSupport builder, Map nsMap)
      Creates a namespace-aware wrapper using the supplied prefix-to-URI mappings.
      Parameters:
      builder - the builder to wrap
      nsMap - the namespace mappings to use
  • Method Details

    • namespace

      public NamespaceBuilderSupport namespace(String namespaceURI)
      Associates the default prefix with the supplied namespace URI.
      Parameters:
      namespaceURI - the namespace URI to bind
      Returns:
      this wrapper
    • namespace

      public NamespaceBuilderSupport namespace(String namespaceURI, String prefix)
      Associates the supplied prefix with the supplied namespace URI.
      Parameters:
      namespaceURI - the namespace URI to bind
      prefix - the prefix to associate with namespaceURI
      Returns:
      this wrapper
    • declareNamespace

      public NamespaceBuilderSupport declareNamespace(Map nsMap)
      Replaces the current namespace mappings used to resolve subsequent builder calls.
      Parameters:
      nsMap - the prefix-to-URI mappings to use
      Returns:
      this wrapper
    • getCurrent

      protected Object getCurrent()
      Builder lifecycle callback that exposes the wrapped builder's current node. Subclasses may override to customize how builder state is shared.
      Overrides:
      getCurrent in class BuilderSupport
      Returns:
      the wrapped builder's current node marker
    • setCurrent

      protected void setCurrent(Object current)
      Builder lifecycle callback that updates the wrapped builder's current node marker. Subclasses may override to customize how builder state is shared.
      Overrides:
      setCurrent in class BuilderSupport
      Parameters:
      current - the new current node marker
    • setParent

      protected void setParent(Object parent, Object child)
      Builder lifecycle callback invoked after a child node has been created. This implementation is a no-op because parent handling is delegated to the wrapped builder.
      Specified by:
      setParent in class BuilderSupport
      Parameters:
      parent - the parent node marker
      child - the child node marker
    • getName

      protected Object getName(String methodName)
      Resolves a builder method name into a namespace-aware node name. Subclasses may override to customize method-to-QName resolution.
      Overrides:
      getName in class BuilderSupport
      Parameters:
      methodName - the method name invoked on the wrapper
      Returns:
      a QName when a namespace mapping is available, otherwise the original method name
    • invokeMethod

      public Object invokeMethod(String methodName, Object args)
      Allow automatic detection of namespace declared in the attributes
      Specified by:
      invokeMethod in interface GroovyObject
      Overrides:
      invokeMethod in class BuilderSupport
      Parameters:
      methodName - the builder method being invoked
      args - the builder arguments, including any attribute map
      Returns:
      the result from the wrapped builder invocation
    • createNode

      protected Object createNode(Object name)
      Builder lifecycle callback that keeps the resolved node name for the wrapped builder.
      Specified by:
      createNode in class BuilderSupport
      Parameters:
      name - the resolved node name
      Returns:
      the same node name
    • createNode

      protected Object createNode(Object name, Object value)
      Builder lifecycle callback that keeps the resolved node name for the wrapped builder.
      Specified by:
      createNode in class BuilderSupport
      Parameters:
      name - the resolved node name
      value - the node value supplied by the builder call
      Returns:
      the same node name
    • createNode

      protected Object createNode(Object name, Map attributes)
      Builder lifecycle callback that keeps the resolved node name for the wrapped builder.
      Specified by:
      createNode in class BuilderSupport
      Parameters:
      name - the resolved node name
      attributes - the attributes supplied by the builder call
      Returns:
      the same node name
    • createNode

      protected Object createNode(Object name, Map attributes, Object value)
      Builder lifecycle callback that keeps the resolved node name for the wrapped builder.
      Specified by:
      createNode in class BuilderSupport
      Parameters:
      name - the resolved node name
      attributes - the attributes supplied by the builder call
      value - the node value supplied by the builder call
      Returns:
      the same node name