Class BijectiveNsMap


  • public final class BijectiveNsMap
    extends java.lang.Object
    Helper class that implements "bijective map" (Map that allows use of values as keys and vice versa, bidirectional access), and is specifically used for storing namespace binding information. One thing worth noting is that Strings stored are NOT assumed to have been unified (interned) -- if they were, different implementation would be more optimal.

    Currently only used by stream writers, but could be more generally useful too.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static int DEFAULT_ARRAY_SIZE
      Let's plan for having up to 14 explicit namespace declarations (2 defaults, for 'xml' and 'xmlns', are pre-populated)
      private static int MAX_LOOP_FOR_NEW_PREFIX
      As a simple protection against infinite loops, use an arbitrary but bound limit for iterators
      (package private) java.lang.String[] mNsStrings
      Array that contains { prefix, ns-uri } pairs, up to (but not including) index mScopeEnd.
      (package private) int mScopeEnd  
      (package private) int mScopeStart  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private BijectiveNsMap​(int scopeStart, java.lang.String[] strs)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String addGeneratedMapping​(java.lang.String prefixBase, javax.xml.namespace.NamespaceContext ctxt, java.lang.String uri, int[] seqArr)
      Method used to add a dynamic binding, and return the prefix used to bind the specified namespace URI.
      java.lang.String addMapping​(java.lang.String prefix, java.lang.String uri)
      Method to add a new prefix-to-URI mapping for the current scope.
      BijectiveNsMap createChild()  
      static BijectiveNsMap createEmpty()  
      java.lang.String findPrefixByUri​(java.lang.String uri)  
      java.lang.String findUriByPrefix​(java.lang.String prefix)  
      java.util.List<java.lang.String> getPrefixesBoundToUri​(java.lang.String uri, java.util.List<java.lang.String> l)  
      int localSize()  
      int size()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_ARRAY_SIZE

        static final int DEFAULT_ARRAY_SIZE
        Let's plan for having up to 14 explicit namespace declarations (2 defaults, for 'xml' and 'xmlns', are pre-populated)
        See Also:
        Constant Field Values
      • MAX_LOOP_FOR_NEW_PREFIX

        private static final int MAX_LOOP_FOR_NEW_PREFIX
        As a simple protection against infinite loops, use an arbitrary but bound limit for iterators
        See Also:
        Constant Field Values
      • mScopeStart

        final int mScopeStart
      • mNsStrings

        java.lang.String[] mNsStrings
        Array that contains { prefix, ns-uri } pairs, up to (but not including) index mScopeEnd.
      • mScopeEnd

        int mScopeEnd
    • Constructor Detail

      • BijectiveNsMap

        private BijectiveNsMap​(int scopeStart,
                               java.lang.String[] strs)
    • Method Detail

      • findUriByPrefix

        public java.lang.String findUriByPrefix​(java.lang.String prefix)
      • findPrefixByUri

        public java.lang.String findPrefixByUri​(java.lang.String uri)
      • getPrefixesBoundToUri

        public java.util.List<java.lang.String> getPrefixesBoundToUri​(java.lang.String uri,
                                                                      java.util.List<java.lang.String> l)
      • size

        public int size()
      • localSize

        public int localSize()
      • addMapping

        public java.lang.String addMapping​(java.lang.String prefix,
                                           java.lang.String uri)
        Method to add a new prefix-to-URI mapping for the current scope. Note that it should NOT be used for the default namespace declaration
        Parameters:
        prefix - Prefix to bind
        uri - URI to bind to the prefix
        Returns:
        If the prefix was already bound, the URI it was bound to: null if it's a new binding for the current scope.
      • addGeneratedMapping

        public java.lang.String addGeneratedMapping​(java.lang.String prefixBase,
                                                    javax.xml.namespace.NamespaceContext ctxt,
                                                    java.lang.String uri,
                                                    int[] seqArr)
        Method used to add a dynamic binding, and return the prefix used to bind the specified namespace URI.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object