Java Code Examples for com.sun.org.apache.xml.internal.utils.SuballocatedIntVector#size()

The following examples show how to use com.sun.org.apache.xml.internal.utils.SuballocatedIntVector#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiDOM.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void removeDOMAdapter(DOMAdapter adapter) {
    _documents.remove(adapter.getDocumentURI(0));
    DOM dom = adapter.getDOMImpl();

    if (dom instanceof DTMDefaultBase) {
        SuballocatedIntVector ids = ((DTMDefaultBase) dom).getDTMIDs();
        int idsSize = ids.size();
        for (int i = 0; i < idsSize; i++) {
            _adapters[ids.elementAt(i) >>> DTMManager.IDENT_DTM_NODE_BITS] = null;
        }
    } else {
        int id = dom.getDocument() >>> DTMManager.IDENT_DTM_NODE_BITS;
        if ((id > 0) && (id < _adapters.length) && isMatchingAdapterEntry(_adapters[id], adapter)) {
            _adapters[id] = null;
        } else {
            boolean found = false;
            for (int i = 0; i < _adapters.length; i++) {
                if (isMatchingAdapterEntry(_adapters[id], adapter)) {
                    _adapters[i] = null;
                    found = true;
                    break;
                }
            }
        }
    }
}
 
Example 2
Source File: MultiDOM.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void removeDOMAdapter(DOMAdapter adapter) {
    _documents.remove(adapter.getDocumentURI(0));
    DOM dom = adapter.getDOMImpl();

    if (dom instanceof DTMDefaultBase) {
        SuballocatedIntVector ids = ((DTMDefaultBase) dom).getDTMIDs();
        int idsSize = ids.size();
        for (int i = 0; i < idsSize; i++) {
            _adapters[ids.elementAt(i) >>> DTMManager.IDENT_DTM_NODE_BITS] = null;
        }
    } else {
        int id = dom.getDocument() >>> DTMManager.IDENT_DTM_NODE_BITS;
        if ((id > 0) && (id < _adapters.length) && isMatchingAdapterEntry(_adapters[id], adapter)) {
            _adapters[id] = null;
        } else {
            boolean found = false;
            for (int i = 0; i < _adapters.length; i++) {
                if (isMatchingAdapterEntry(_adapters[id], adapter)) {
                    _adapters[i] = null;
                    found = true;
                    break;
                }
            }
        }
    }
}
 
Example 3
Source File: DTMDefaultBase.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
   * Subroutine: Locate the specified node within
   * m_namespaceDeclSetElements, or the last element which
   * preceeds it in document order
   *
   * %REVIEW% Inlne this into findNamespaceContext? Create SortedSuballocatedIntVector type?
   *
   * @return If positive or zero, the index of the found item.
   * If negative, index of the point at which it would have appeared,
   * encoded as -1-index and hence reconvertable by subtracting
   * it from -1. (Encoding because I don't want to recompare the strings
   * but don't want to burn bytes on a datatype to hold a flagged value.)
   */
protected int findInSortedSuballocatedIntVector(SuballocatedIntVector vector, int lookfor)
{
  // Binary search
  int i = 0;
  if(vector != null) {
    int first = 0;
    int last  = vector.size() - 1;

    while (first <= last) {
      i = (first + last) / 2;
      int test = lookfor-vector.elementAt(i);
      if(test == 0) {
        return i; // Name found
      }
      else if (test < 0) {
        last = i - 1; // looked too late
      }
      else {
        first = i + 1; // looked ot early
      }
    }

    if (first > i) {
      i = first; // Clean up at loop end
    }
  }

  return -1 - i; // not-found has to be encoded.
}
 
Example 4
Source File: DTMDefaultBase.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
   * Subroutine: Locate the specified node within
   * m_namespaceDeclSetElements, or the last element which
   * preceeds it in document order
   *
   * %REVIEW% Inlne this into findNamespaceContext? Create SortedSuballocatedIntVector type?
   *
   * @return If positive or zero, the index of the found item.
   * If negative, index of the point at which it would have appeared,
   * encoded as -1-index and hence reconvertable by subtracting
   * it from -1. (Encoding because I don't want to recompare the strings
   * but don't want to burn bytes on a datatype to hold a flagged value.)
   */
protected int findInSortedSuballocatedIntVector(SuballocatedIntVector vector, int lookfor)
{
  // Binary search
  int i = 0;
  if(vector != null) {
    int first = 0;
    int last  = vector.size() - 1;

    while (first <= last) {
      i = (first + last) / 2;
      int test = lookfor-vector.elementAt(i);
      if(test == 0) {
        return i; // Name found
      }
      else if (test < 0) {
        last = i - 1; // looked too late
      }
      else {
        first = i + 1; // looked ot early
      }
    }

    if (first > i) {
      i = first; // Clean up at loop end
    }
  }

  return -1 - i; // not-found has to be encoded.
}
 
Example 5
Source File: DTMDefaultBase.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Given a namespace handle, advance to the next namespace.
 *
 * @param baseHandle handle to original node from where the first namespace
 * was relative to (needed to return nodes in document order).
 * @param nodeHandle A namespace handle for which we will find the next node.
 * @param inScope true if all namespaces that are in scope should be processed,
 * otherwise just process the nodes in the given element handle.
 * @return handle of next namespace, or DTM.NULL to indicate none exists.
 */
public int getNextNamespaceNode(int baseHandle, int nodeHandle,
                                boolean inScope)
{
      if(inScope)
        {
          //Since we've been given the base, try direct lookup
          //(could look from nodeHandle but this is at least one
          //comparison/get-parent faster)
          //SuballocatedIntVector nsContext=findNamespaceContext(nodeHandle & m_mask);

              SuballocatedIntVector nsContext=findNamespaceContext(makeNodeIdentity(baseHandle));

          if(nsContext==null)
            return NULL;
          int i=1 + nsContext.indexOf(nodeHandle);
          if(i<=0 || i==nsContext.size())
            return NULL;

          return nsContext.elementAt(i);
        }
      else
        {
          // Assume that attributes and namespace nodes immediately follow the element.
          int identity = makeNodeIdentity(nodeHandle);
          while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
            {
              int type = _type(identity);
              if (type == DTM.NAMESPACE_NODE)
                {
                  return makeNodeHandle(identity);
                }
              else if (type != DTM.ATTRIBUTE_NODE)
                {
                  break;
                }
            }
        }
   return DTM.NULL;
}
 
Example 6
Source File: DTMDefaultBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
   * Subroutine: Locate the specified node within
   * m_namespaceDeclSetElements, or the last element which
   * preceeds it in document order
   *
   * %REVIEW% Inlne this into findNamespaceContext? Create SortedSuballocatedIntVector type?
   *
   * @return If positive or zero, the index of the found item.
   * If negative, index of the point at which it would have appeared,
   * encoded as -1-index and hence reconvertable by subtracting
   * it from -1. (Encoding because I don't want to recompare the strings
   * but don't want to burn bytes on a datatype to hold a flagged value.)
   */
protected int findInSortedSuballocatedIntVector(SuballocatedIntVector vector, int lookfor)
{
  // Binary search
  int i = 0;
  if(vector != null) {
    int first = 0;
    int last  = vector.size() - 1;

    while (first <= last) {
      i = (first + last) / 2;
      int test = lookfor-vector.elementAt(i);
      if(test == 0) {
        return i; // Name found
      }
      else if (test < 0) {
        last = i - 1; // looked too late
      }
      else {
        first = i + 1; // looked ot early
      }
    }

    if (first > i) {
      i = first; // Clean up at loop end
    }
  }

  return -1 - i; // not-found has to be encoded.
}
 
Example 7
Source File: DTMDefaultBase.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
   * Subroutine: Locate the specified node within
   * m_namespaceDeclSetElements, or the last element which
   * preceeds it in document order
   *
   * %REVIEW% Inlne this into findNamespaceContext? Create SortedSuballocatedIntVector type?
   *
   * @return If positive or zero, the index of the found item.
   * If negative, index of the point at which it would have appeared,
   * encoded as -1-index and hence reconvertable by subtracting
   * it from -1. (Encoding because I don't want to recompare the strings
   * but don't want to burn bytes on a datatype to hold a flagged value.)
   */
protected int findInSortedSuballocatedIntVector(SuballocatedIntVector vector, int lookfor)
{
  // Binary search
  int i = 0;
  if(vector != null) {
    int first = 0;
    int last  = vector.size() - 1;

    while (first <= last) {
      i = (first + last) / 2;
      int test = lookfor-vector.elementAt(i);
      if(test == 0) {
        return i; // Name found
      }
      else if (test < 0) {
        last = i - 1; // looked too late
      }
      else {
        first = i + 1; // looked ot early
      }
    }

    if (first > i) {
      i = first; // Clean up at loop end
    }
  }

  return -1 - i; // not-found has to be encoded.
}
 
Example 8
Source File: DTMDefaultBase.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
   * Subroutine: Locate the specified node within
   * m_namespaceDeclSetElements, or the last element which
   * preceeds it in document order
   *
   * %REVIEW% Inlne this into findNamespaceContext? Create SortedSuballocatedIntVector type?
   *
   * @return If positive or zero, the index of the found item.
   * If negative, index of the point at which it would have appeared,
   * encoded as -1-index and hence reconvertable by subtracting
   * it from -1. (Encoding because I don't want to recompare the strings
   * but don't want to burn bytes on a datatype to hold a flagged value.)
   */
protected int findInSortedSuballocatedIntVector(SuballocatedIntVector vector, int lookfor)
{
  // Binary search
  int i = 0;
  if(vector != null) {
    int first = 0;
    int last  = vector.size() - 1;

    while (first <= last) {
      i = (first + last) / 2;
      int test = lookfor-vector.elementAt(i);
      if(test == 0) {
        return i; // Name found
      }
      else if (test < 0) {
        last = i - 1; // looked too late
      }
      else {
        first = i + 1; // looked ot early
      }
    }

    if (first > i) {
      i = first; // Clean up at loop end
    }
  }

  return -1 - i; // not-found has to be encoded.
}
 
Example 9
Source File: DTMDefaultBase.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Given a namespace handle, advance to the next namespace.
 *
 * @param baseHandle handle to original node from where the first namespace
 * was relative to (needed to return nodes in document order).
 * @param nodeHandle A namespace handle for which we will find the next node.
 * @param inScope true if all namespaces that are in scope should be processed,
 * otherwise just process the nodes in the given element handle.
 * @return handle of next namespace, or DTM.NULL to indicate none exists.
 */
public int getNextNamespaceNode(int baseHandle, int nodeHandle,
                                boolean inScope)
{
      if(inScope)
        {
          //Since we've been given the base, try direct lookup
          //(could look from nodeHandle but this is at least one
          //comparison/get-parent faster)
          //SuballocatedIntVector nsContext=findNamespaceContext(nodeHandle & m_mask);

              SuballocatedIntVector nsContext=findNamespaceContext(makeNodeIdentity(baseHandle));

          if(nsContext==null)
            return NULL;
          int i=1 + nsContext.indexOf(nodeHandle);
          if(i<=0 || i==nsContext.size())
            return NULL;

          return nsContext.elementAt(i);
        }
      else
        {
          // Assume that attributes and namespace nodes immediately follow the element.
          int identity = makeNodeIdentity(nodeHandle);
          while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
            {
              int type = _type(identity);
              if (type == DTM.NAMESPACE_NODE)
                {
                  return makeNodeHandle(identity);
                }
              else if (type != DTM.ATTRIBUTE_NODE)
                {
                  break;
                }
            }
        }
   return DTM.NULL;
}
 
Example 10
Source File: DTMDefaultBase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a namespace handle, advance to the next namespace.
 *
 * @param baseHandle handle to original node from where the first namespace
 * was relative to (needed to return nodes in document order).
 * @param nodeHandle A namespace handle for which we will find the next node.
 * @param inScope true if all namespaces that are in scope should be processed,
 * otherwise just process the nodes in the given element handle.
 * @return handle of next namespace, or DTM.NULL to indicate none exists.
 */
public int getNextNamespaceNode(int baseHandle, int nodeHandle,
                                boolean inScope)
{
      if(inScope)
        {
          //Since we've been given the base, try direct lookup
          //(could look from nodeHandle but this is at least one
          //comparison/get-parent faster)
          //SuballocatedIntVector nsContext=findNamespaceContext(nodeHandle & m_mask);

              SuballocatedIntVector nsContext=findNamespaceContext(makeNodeIdentity(baseHandle));

          if(nsContext==null)
            return NULL;
          int i=1 + nsContext.indexOf(nodeHandle);
          if(i<=0 || i==nsContext.size())
            return NULL;

          return nsContext.elementAt(i);
        }
      else
        {
          // Assume that attributes and namespace nodes immediately follow the element.
          int identity = makeNodeIdentity(nodeHandle);
          while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
            {
              int type = _type(identity);
              if (type == DTM.NAMESPACE_NODE)
                {
                  return makeNodeHandle(identity);
                }
              else if (type != DTM.ATTRIBUTE_NODE)
                {
                  break;
                }
            }
        }
   return DTM.NULL;
}
 
Example 11
Source File: MultiDOM.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private int addDOMAdapter(DOMAdapter adapter, boolean indexByURI) {
    // Add the DOM adapter to the array of DOMs
    DOM dom = adapter.getDOMImpl();

    int domNo = 1;
    int dtmSize = 1;
    SuballocatedIntVector dtmIds = null;
    if (dom instanceof DTMDefaultBase) {
        DTMDefaultBase dtmdb = (DTMDefaultBase)dom;
        dtmIds = dtmdb.getDTMIDs();
        dtmSize = dtmIds.size();
        domNo = dtmIds.elementAt(dtmSize-1) >>> DTMManager.IDENT_DTM_NODE_BITS;
    }
    else if (dom instanceof SimpleResultTreeImpl) {
        SimpleResultTreeImpl simpleRTF = (SimpleResultTreeImpl)dom;
        domNo = simpleRTF.getDocument() >>> DTMManager.IDENT_DTM_NODE_BITS;
    }

    if (domNo >= _size) {
        int oldSize = _size;
        do {
            _size *= 2;
        } while (_size <= domNo);

        final DOMAdapter[] newArray = new DOMAdapter[_size];
        System.arraycopy(_adapters, 0, newArray, 0, oldSize);
        _adapters = newArray;
    }

    _free = domNo + 1;

    if (dtmSize == 1) {
        _adapters[domNo] = adapter;
    }
    else if (dtmIds != null) {
        int domPos = 0;
        for (int i = dtmSize - 1; i >= 0; i--) {
            domPos = dtmIds.elementAt(i) >>> DTMManager.IDENT_DTM_NODE_BITS;
            _adapters[domPos] = adapter;
        }
        domNo = domPos;
    }

    // Store reference to document (URI) in the Map
    if (indexByURI) {
        String uri = adapter.getDocumentURI(0);
        _documents.put(uri, domNo);
    }

    // If the dom is an AdaptiveResultTreeImpl, we need to create a
    // DOMAdapter around its nested dom object (if it is non-null) and
    // add the DOMAdapter to the list.
    if (dom instanceof AdaptiveResultTreeImpl) {
        AdaptiveResultTreeImpl adaptiveRTF = (AdaptiveResultTreeImpl)dom;
        DOM nestedDom = adaptiveRTF.getNestedDOM();
        if (nestedDom != null) {
            DOMAdapter newAdapter = new DOMAdapter(nestedDom,
                                                   adapter.getNamesArray(),
                                                   adapter.getUrisArray(),
                                                   adapter.getTypesArray(),
                                                   adapter.getNamespaceArray());
            addDOMAdapter(newAdapter);
        }
    }

    return domNo;
}
 
Example 12
Source File: MultiDOM.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
private int addDOMAdapter(DOMAdapter adapter, boolean indexByURI) {
    // Add the DOM adapter to the array of DOMs
    DOM dom = adapter.getDOMImpl();

    int domNo = 1;
    int dtmSize = 1;
    SuballocatedIntVector dtmIds = null;
    if (dom instanceof DTMDefaultBase) {
        DTMDefaultBase dtmdb = (DTMDefaultBase)dom;
        dtmIds = dtmdb.getDTMIDs();
        dtmSize = dtmIds.size();
        domNo = dtmIds.elementAt(dtmSize-1) >>> DTMManager.IDENT_DTM_NODE_BITS;
    }
    else if (dom instanceof SimpleResultTreeImpl) {
        SimpleResultTreeImpl simpleRTF = (SimpleResultTreeImpl)dom;
        domNo = simpleRTF.getDocument() >>> DTMManager.IDENT_DTM_NODE_BITS;
    }

    if (domNo >= _size) {
        int oldSize = _size;
        do {
            _size *= 2;
        } while (_size <= domNo);

        final DOMAdapter[] newArray = new DOMAdapter[_size];
        System.arraycopy(_adapters, 0, newArray, 0, oldSize);
        _adapters = newArray;
    }

    _free = domNo + 1;

    if (dtmSize == 1) {
        _adapters[domNo] = adapter;
    }
    else if (dtmIds != null) {
        int domPos = 0;
        for (int i = dtmSize - 1; i >= 0; i--) {
            domPos = dtmIds.elementAt(i) >>> DTMManager.IDENT_DTM_NODE_BITS;
            _adapters[domPos] = adapter;
        }
        domNo = domPos;
    }

    // Store reference to document (URI) in the Map
    if (indexByURI) {
        String uri = adapter.getDocumentURI(0);
        _documents.put(uri, domNo);
    }

    // If the dom is an AdaptiveResultTreeImpl, we need to create a
    // DOMAdapter around its nested dom object (if it is non-null) and
    // add the DOMAdapter to the list.
    if (dom instanceof AdaptiveResultTreeImpl) {
        AdaptiveResultTreeImpl adaptiveRTF = (AdaptiveResultTreeImpl)dom;
        DOM nestedDom = adaptiveRTF.getNestedDOM();
        if (nestedDom != null) {
            DOMAdapter newAdapter = new DOMAdapter(nestedDom,
                                                   adapter.getNamesArray(),
                                                   adapter.getUrisArray(),
                                                   adapter.getTypesArray(),
                                                   adapter.getNamespaceArray());
            addDOMAdapter(newAdapter);
        }
    }

    return domNo;
}
 
Example 13
Source File: SAX2DTM2.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Copy  namespace nodes.
 *
 * @param nodeID The Element node identity
 * @param handler The SerializationHandler
 * @param inScope  true if all namespaces in scope should be copied,
 *  false if only the namespace declarations should be copied.
 */
protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope)
    throws SAXException
{
    // %OPT% Optimization for documents which does not have any explicit
    // namespace nodes. For these documents, there is an implicit
    // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace")
    // declared on the root element node. In this case, there is no
    // need to do namespace copying. We can safely return without
    // doing anything.
    if (m_namespaceDeclSetElements != null &&
        m_namespaceDeclSetElements.size() == 1 &&
        m_namespaceDeclSets != null &&
        ((SuballocatedIntVector)m_namespaceDeclSets.elementAt(0))
        .size() == 1)
        return;

    SuballocatedIntVector nsContext = null;
    int nextNSNode;

    // Find the first namespace node
    if (inScope) {
        nsContext = findNamespaceContext(nodeID);
        if (nsContext == null || nsContext.size() < 1)
            return;
        else
            nextNSNode = makeNodeIdentity(nsContext.elementAt(0));
    }
    else
        nextNSNode = getNextNamespaceNode2(nodeID);

    int nsIndex = 1;
    while (nextNSNode != DTM.NULL) {
        // Retrieve the name of the namespace node
        int eType = _exptype2(nextNSNode);
        String nodeName = m_extendedTypes[eType].getLocalName();

        // Retrieve the node value of the namespace node
        int dataIndex = m_dataOrQName.elementAt(nextNSNode);

        if (dataIndex < 0) {
            dataIndex = -dataIndex;
            dataIndex = m_data.elementAt(dataIndex + 1);
        }

        String nodeValue = (String)m_values.elementAt(dataIndex);

        handler.namespaceAfterStartElement(nodeName, nodeValue);

        if (inScope) {
            if (nsIndex < nsContext.size()) {
                nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex));
                nsIndex++;
            }
            else
                return;
        }
        else
            nextNSNode = getNextNamespaceNode2(nextNSNode);
    }
}
 
Example 14
Source File: SAX2DTM2.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copy  namespace nodes.
 *
 * @param nodeID The Element node identity
 * @param handler The SerializationHandler
 * @param inScope  true if all namespaces in scope should be copied,
 *  false if only the namespace declarations should be copied.
 */
protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope)
    throws SAXException
{
    // %OPT% Optimization for documents which does not have any explicit
    // namespace nodes. For these documents, there is an implicit
    // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace")
    // declared on the root element node. In this case, there is no
    // need to do namespace copying. We can safely return without
    // doing anything.
    if (m_namespaceDeclSetElements != null &&
        m_namespaceDeclSetElements.size() == 1 &&
        m_namespaceDeclSets != null &&
        ((SuballocatedIntVector)m_namespaceDeclSets.elementAt(0))
        .size() == 1)
        return;

    SuballocatedIntVector nsContext = null;
    int nextNSNode;

    // Find the first namespace node
    if (inScope) {
        nsContext = findNamespaceContext(nodeID);
        if (nsContext == null || nsContext.size() < 1)
            return;
        else
            nextNSNode = makeNodeIdentity(nsContext.elementAt(0));
    }
    else
        nextNSNode = getNextNamespaceNode2(nodeID);

    int nsIndex = 1;
    while (nextNSNode != DTM.NULL) {
        // Retrieve the name of the namespace node
        int eType = _exptype2(nextNSNode);
        String nodeName = m_extendedTypes[eType].getLocalName();

        // Retrieve the node value of the namespace node
        int dataIndex = m_dataOrQName.elementAt(nextNSNode);

        if (dataIndex < 0) {
            dataIndex = -dataIndex;
            dataIndex = m_data.elementAt(dataIndex + 1);
        }

        String nodeValue = m_values.get(dataIndex);

        handler.namespaceAfterStartElement(nodeName, nodeValue);

        if (inScope) {
            if (nsIndex < nsContext.size()) {
                nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex));
                nsIndex++;
            }
            else
                return;
        }
        else
            nextNSNode = getNextNamespaceNode2(nextNSNode);
    }
}
 
Example 15
Source File: MultiDOM.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
private int addDOMAdapter(DOMAdapter adapter, boolean indexByURI) {
    // Add the DOM adapter to the array of DOMs
    DOM dom = adapter.getDOMImpl();

    int domNo = 1;
    int dtmSize = 1;
    SuballocatedIntVector dtmIds = null;
    if (dom instanceof DTMDefaultBase) {
        DTMDefaultBase dtmdb = (DTMDefaultBase)dom;
        dtmIds = dtmdb.getDTMIDs();
        dtmSize = dtmIds.size();
        domNo = dtmIds.elementAt(dtmSize-1) >>> DTMManager.IDENT_DTM_NODE_BITS;
    }
    else if (dom instanceof SimpleResultTreeImpl) {
        SimpleResultTreeImpl simpleRTF = (SimpleResultTreeImpl)dom;
        domNo = simpleRTF.getDocument() >>> DTMManager.IDENT_DTM_NODE_BITS;
    }

    if (domNo >= _size) {
        int oldSize = _size;
        do {
            _size *= 2;
        } while (_size <= domNo);

        final DOMAdapter[] newArray = new DOMAdapter[_size];
        System.arraycopy(_adapters, 0, newArray, 0, oldSize);
        _adapters = newArray;
    }

    _free = domNo + 1;

    if (dtmSize == 1) {
        _adapters[domNo] = adapter;
    }
    else if (dtmIds != null) {
        int domPos = 0;
        for (int i = dtmSize - 1; i >= 0; i--) {
            domPos = dtmIds.elementAt(i) >>> DTMManager.IDENT_DTM_NODE_BITS;
            _adapters[domPos] = adapter;
        }
        domNo = domPos;
    }

    // Store reference to document (URI) in the Map
    if (indexByURI) {
        String uri = adapter.getDocumentURI(0);
        _documents.put(uri, domNo);
    }

    // If the dom is an AdaptiveResultTreeImpl, we need to create a
    // DOMAdapter around its nested dom object (if it is non-null) and
    // add the DOMAdapter to the list.
    if (dom instanceof AdaptiveResultTreeImpl) {
        AdaptiveResultTreeImpl adaptiveRTF = (AdaptiveResultTreeImpl)dom;
        DOM nestedDom = adaptiveRTF.getNestedDOM();
        if (nestedDom != null) {
            DOMAdapter newAdapter = new DOMAdapter(nestedDom,
                                                   adapter.getNamesArray(),
                                                   adapter.getUrisArray(),
                                                   adapter.getTypesArray(),
                                                   adapter.getNamespaceArray());
            addDOMAdapter(newAdapter);
        }
    }

    return domNo;
}
 
Example 16
Source File: SAX2DTM2.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copy  namespace nodes.
 *
 * @param nodeID The Element node identity
 * @param handler The SerializationHandler
 * @param inScope  true if all namespaces in scope should be copied,
 *  false if only the namespace declarations should be copied.
 */
protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope)
    throws SAXException
{
    // %OPT% Optimization for documents which does not have any explicit
    // namespace nodes. For these documents, there is an implicit
    // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace")
    // declared on the root element node. In this case, there is no
    // need to do namespace copying. We can safely return without
    // doing anything.
    if (m_namespaceDeclSetElements != null &&
        m_namespaceDeclSetElements.size() == 1 &&
        m_namespaceDeclSets != null &&
        ((SuballocatedIntVector)m_namespaceDeclSets.elementAt(0))
        .size() == 1)
        return;

    SuballocatedIntVector nsContext = null;
    int nextNSNode;

    // Find the first namespace node
    if (inScope) {
        nsContext = findNamespaceContext(nodeID);
        if (nsContext == null || nsContext.size() < 1)
            return;
        else
            nextNSNode = makeNodeIdentity(nsContext.elementAt(0));
    }
    else
        nextNSNode = getNextNamespaceNode2(nodeID);

    int nsIndex = 1;
    while (nextNSNode != DTM.NULL) {
        // Retrieve the name of the namespace node
        int eType = _exptype2(nextNSNode);
        String nodeName = m_extendedTypes[eType].getLocalName();

        // Retrieve the node value of the namespace node
        int dataIndex = m_dataOrQName.elementAt(nextNSNode);

        if (dataIndex < 0) {
            dataIndex = -dataIndex;
            dataIndex = m_data.elementAt(dataIndex + 1);
        }

        String nodeValue = (String)m_values.elementAt(dataIndex);

        handler.namespaceAfterStartElement(nodeName, nodeValue);

        if (inScope) {
            if (nsIndex < nsContext.size()) {
                nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex));
                nsIndex++;
            }
            else
                return;
        }
        else
            nextNSNode = getNextNamespaceNode2(nextNSNode);
    }
}
 
Example 17
Source File: SAX2DTM2.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copy  namespace nodes.
 *
 * @param nodeID The Element node identity
 * @param handler The SerializationHandler
 * @param inScope  true if all namespaces in scope should be copied,
 *  false if only the namespace declarations should be copied.
 */
protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope)
    throws SAXException
{
    // %OPT% Optimization for documents which does not have any explicit
    // namespace nodes. For these documents, there is an implicit
    // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace")
    // declared on the root element node. In this case, there is no
    // need to do namespace copying. We can safely return without
    // doing anything.
    if (m_namespaceDeclSetElements != null &&
        m_namespaceDeclSetElements.size() == 1 &&
        m_namespaceDeclSets != null &&
        ((SuballocatedIntVector)m_namespaceDeclSets.elementAt(0))
        .size() == 1)
        return;

    SuballocatedIntVector nsContext = null;
    int nextNSNode;

    // Find the first namespace node
    if (inScope) {
        nsContext = findNamespaceContext(nodeID);
        if (nsContext == null || nsContext.size() < 1)
            return;
        else
            nextNSNode = makeNodeIdentity(nsContext.elementAt(0));
    }
    else
        nextNSNode = getNextNamespaceNode2(nodeID);

    int nsIndex = 1;
    while (nextNSNode != DTM.NULL) {
        // Retrieve the name of the namespace node
        int eType = _exptype2(nextNSNode);
        String nodeName = m_extendedTypes[eType].getLocalName();

        // Retrieve the node value of the namespace node
        int dataIndex = m_dataOrQName.elementAt(nextNSNode);

        if (dataIndex < 0) {
            dataIndex = -dataIndex;
            dataIndex = m_data.elementAt(dataIndex + 1);
        }

        String nodeValue = (String)m_values.elementAt(dataIndex);

        handler.namespaceAfterStartElement(nodeName, nodeValue);

        if (inScope) {
            if (nsIndex < nsContext.size()) {
                nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex));
                nsIndex++;
            }
            else
                return;
        }
        else
            nextNSNode = getNextNamespaceNode2(nextNSNode);
    }
}
 
Example 18
Source File: MultiDOM.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private int addDOMAdapter(DOMAdapter adapter, boolean indexByURI) {
    // Add the DOM adapter to the array of DOMs
    DOM dom = adapter.getDOMImpl();

    int domNo = 1;
    int dtmSize = 1;
    SuballocatedIntVector dtmIds = null;
    if (dom instanceof DTMDefaultBase) {
        DTMDefaultBase dtmdb = (DTMDefaultBase)dom;
        dtmIds = dtmdb.getDTMIDs();
        dtmSize = dtmIds.size();
        domNo = dtmIds.elementAt(dtmSize-1) >>> DTMManager.IDENT_DTM_NODE_BITS;
    }
    else if (dom instanceof SimpleResultTreeImpl) {
        SimpleResultTreeImpl simpleRTF = (SimpleResultTreeImpl)dom;
        domNo = simpleRTF.getDocument() >>> DTMManager.IDENT_DTM_NODE_BITS;
    }

    if (domNo >= _size) {
        int oldSize = _size;
        do {
            _size *= 2;
        } while (_size <= domNo);

        final DOMAdapter[] newArray = new DOMAdapter[_size];
        System.arraycopy(_adapters, 0, newArray, 0, oldSize);
        _adapters = newArray;
    }

    _free = domNo + 1;

    if (dtmSize == 1) {
        _adapters[domNo] = adapter;
    }
    else if (dtmIds != null) {
        int domPos = 0;
        for (int i = dtmSize - 1; i >= 0; i--) {
            domPos = dtmIds.elementAt(i) >>> DTMManager.IDENT_DTM_NODE_BITS;
            _adapters[domPos] = adapter;
        }
        domNo = domPos;
    }

    // Store reference to document (URI) in hashtable
    if (indexByURI) {
        String uri = adapter.getDocumentURI(0);
        _documents.put(uri, new Integer(domNo));
    }

    // If the dom is an AdaptiveResultTreeImpl, we need to create a
    // DOMAdapter around its nested dom object (if it is non-null) and
    // add the DOMAdapter to the list.
    if (dom instanceof AdaptiveResultTreeImpl) {
        AdaptiveResultTreeImpl adaptiveRTF = (AdaptiveResultTreeImpl)dom;
        DOM nestedDom = adaptiveRTF.getNestedDOM();
        if (nestedDom != null) {
            DOMAdapter newAdapter = new DOMAdapter(nestedDom,
                                                   adapter.getNamesArray(),
                                                   adapter.getUrisArray(),
                                                   adapter.getTypesArray(),
                                                   adapter.getNamespaceArray());
            addDOMAdapter(newAdapter);
        }
    }

    return domNo;
}
 
Example 19
Source File: SAX2DTM2.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copy  namespace nodes.
 *
 * @param nodeID The Element node identity
 * @param handler The SerializationHandler
 * @param inScope  true if all namespaces in scope should be copied,
 *  false if only the namespace declarations should be copied.
 */
protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope)
    throws SAXException
{
    // %OPT% Optimization for documents which does not have any explicit
    // namespace nodes. For these documents, there is an implicit
    // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace")
    // declared on the root element node. In this case, there is no
    // need to do namespace copying. We can safely return without
    // doing anything.
    if (m_namespaceDeclSetElements != null &&
        m_namespaceDeclSetElements.size() == 1 &&
        m_namespaceDeclSets != null &&
        ((SuballocatedIntVector)m_namespaceDeclSets.elementAt(0))
        .size() == 1)
        return;

    SuballocatedIntVector nsContext = null;
    int nextNSNode;

    // Find the first namespace node
    if (inScope) {
        nsContext = findNamespaceContext(nodeID);
        if (nsContext == null || nsContext.size() < 1)
            return;
        else
            nextNSNode = makeNodeIdentity(nsContext.elementAt(0));
    }
    else
        nextNSNode = getNextNamespaceNode2(nodeID);

    int nsIndex = 1;
    while (nextNSNode != DTM.NULL) {
        // Retrieve the name of the namespace node
        int eType = _exptype2(nextNSNode);
        String nodeName = m_extendedTypes[eType].getLocalName();

        // Retrieve the node value of the namespace node
        int dataIndex = m_dataOrQName.elementAt(nextNSNode);

        if (dataIndex < 0) {
            dataIndex = -dataIndex;
            dataIndex = m_data.elementAt(dataIndex + 1);
        }

        String nodeValue = (String)m_values.elementAt(dataIndex);

        handler.namespaceAfterStartElement(nodeName, nodeValue);

        if (inScope) {
            if (nsIndex < nsContext.size()) {
                nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex));
                nsIndex++;
            }
            else
                return;
        }
        else
            nextNSNode = getNextNamespaceNode2(nextNSNode);
    }
}
 
Example 20
Source File: SAX2DTM2.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Copy  namespace nodes.
 *
 * @param nodeID The Element node identity
 * @param handler The SerializationHandler
 * @param inScope  true if all namespaces in scope should be copied,
 *  false if only the namespace declarations should be copied.
 */
protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope)
    throws SAXException
{
    // %OPT% Optimization for documents which does not have any explicit
    // namespace nodes. For these documents, there is an implicit
    // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace")
    // declared on the root element node. In this case, there is no
    // need to do namespace copying. We can safely return without
    // doing anything.
    if (m_namespaceDeclSetElements != null &&
        m_namespaceDeclSetElements.size() == 1 &&
        m_namespaceDeclSets != null &&
        ((SuballocatedIntVector)m_namespaceDeclSets.elementAt(0))
        .size() == 1)
        return;

    SuballocatedIntVector nsContext = null;
    int nextNSNode;

    // Find the first namespace node
    if (inScope) {
        nsContext = findNamespaceContext(nodeID);
        if (nsContext == null || nsContext.size() < 1)
            return;
        else
            nextNSNode = makeNodeIdentity(nsContext.elementAt(0));
    }
    else
        nextNSNode = getNextNamespaceNode2(nodeID);

    int nsIndex = 1;
    while (nextNSNode != DTM.NULL) {
        // Retrieve the name of the namespace node
        int eType = _exptype2(nextNSNode);
        String nodeName = m_extendedTypes[eType].getLocalName();

        // Retrieve the node value of the namespace node
        int dataIndex = m_dataOrQName.elementAt(nextNSNode);

        if (dataIndex < 0) {
            dataIndex = -dataIndex;
            dataIndex = m_data.elementAt(dataIndex + 1);
        }

        String nodeValue = (String)m_values.elementAt(dataIndex);

        handler.namespaceAfterStartElement(nodeName, nodeValue);

        if (inScope) {
            if (nsIndex < nsContext.size()) {
                nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex));
                nsIndex++;
            }
            else
                return;
        }
        else
            nextNSNode = getNextNamespaceNode2(nextNSNode);
    }
}