Class NamespaceContextImpl

  • All Implemented Interfaces:
    NamespaceContext2, NamespaceContext

    public final class NamespaceContextImpl
    extends Object
    implements NamespaceContext2
    Keeps track of in-scope namespace bindings for the marshaller.

    This class is also used to keep track of tag names for each element for the marshaller (for the performance reason.)

    Author:
    Kohsuke Kawaguchi
    • Field Detail

      • collectionMode

        public boolean collectionMode
        True to allow new URIs to be declared. False otherwise.
    • Constructor Detail

      • NamespaceContextImpl

        public NamespaceContextImpl​(XMLSerializer owner)
    • Method Detail

      • reset

        public void reset()
      • declareNsUri

        public int declareNsUri​(String uri,
                                String preferedPrefix,
                                boolean requirePrefix)
        Returns the prefix index to the specified URI. This method allocates a new URI if necessary.
      • force

        public int force​(@NotNull
                         String uri,
                         @NotNull
                         String prefix)
        Description copied from interface: NamespaceContext2
        Forcibly make a namespace declaration in effect. If the (prefix,uri) binding is already in-scope, this method simply returns the assigned prefix index. Otherwise a new declaration will be put.
        Specified by:
        force in interface NamespaceContext2
      • getPrefixIndex

        public int getPrefixIndex​(String uri)
        Returns the prefix index of the specified URI. It is an error if the URI is not declared.
      • getPrefix

        public String getPrefix​(int prefixIndex)
        Gets the prefix from a prefix index. The behavior is undefined if the index is out of range.
      • getNamespaceURI

        public String getNamespaceURI​(int prefixIndex)
      • getNamespaceURI

        public String getNamespaceURI​(String prefix)
        Gets the namespace URI that is bound to the specified prefix.
        Specified by:
        getNamespaceURI in interface NamespaceContext
        Returns:
        null if the prefix is unbound.
      • declareNamespace

        public String declareNamespace​(String namespaceUri,
                                       String preferedPrefix,
                                       boolean requirePrefix)
        Description copied from interface: NamespaceContext2
        Declares a new namespace binding within the current context.

        The prefix is automatically assigned by MarshallingContext. If a given namespace URI is already declared, nothing happens.

        It is NOT an error to declare the same namespace URI more than once.

        For marshalling to work correctly, all namespace bindings for an element must be declared between its startElement method and its endAttributes event. Calling the same method with the same parameter between the endAttributes and the endElement returns the same prefix.

        Specified by:
        declareNamespace in interface NamespaceContext2
        preferedPrefix - If the caller has any particular preference to the prefix, pass that as a parameter. The callee will try to honor it. Set null if there's no particular preference.
        requirePrefix - If this parameter is true, this method must assign a prefix to this namespace, even if it's already bound to the default namespace. IOW, this method will never return null if this flag is true. This functionality is necessary to declare namespace URI used for attribute names.
        Returns:
        returns the assigned prefix. If the namespace is bound to the default namespace, null is returned.
      • count

        public int count()
        Number of total bindings declared.