Search in sources :

Example 11 with NodeVector

use of org.apache.xml.utils.NodeVector in project robovm by robovm.

the class NodeSequence method addNodeInDocOrder.

/**
   * Add the node into a vector of nodes where it should occur in
   * document order.
   * @param node The node to be added.
   * @return insertIndex.
   * @throws RuntimeException thrown if this NodeSetDTM is not of 
   * a mutable type.
   */
protected int addNodeInDocOrder(int node) {
    assertion(hasCache(), "addNodeInDocOrder must be done on a mutable sequence!");
    int insertIndex = -1;
    NodeVector vec = getVector();
    // This needs to do a binary search, but a binary search 
    // is somewhat tough because the sequence test involves 
    // two nodes.
    int size = vec.size(), i;
    for (i = size - 1; i >= 0; i--) {
        int child = vec.elementAt(i);
        if (child == node) {
            // Duplicate, suppress insert
            i = -2;
            break;
        }
        DTM dtm = m_dtmMgr.getDTM(node);
        if (!dtm.isNodeAfter(node, child)) {
            break;
        }
    }
    if (i != -2) {
        insertIndex = i + 1;
        vec.insertElementAt(node, insertIndex);
    }
    // checkDups();
    return insertIndex;
}
Also used : NodeVector(org.apache.xml.utils.NodeVector) NodeSetDTM(org.apache.xpath.NodeSetDTM) DTM(org.apache.xml.dtm.DTM)

Example 12 with NodeVector

use of org.apache.xml.utils.NodeVector in project robovm by robovm.

the class NodeSequence method setItem.

/**
   * @see DTMIterator#setItem(int, int)
   */
public void setItem(int node, int index) {
    NodeVector vec = getVector();
    if (null != vec) {
        int oldNode = vec.elementAt(index);
        if (oldNode != node && m_cache.useCount() > 1) {
            /* If we are going to set the node at the given index
             * to a different value, and the cache is shared
             * (has a use count greater than 1)
             * then make a copy of the cache and use it
             * so we don't overwrite the value for other
             * users of the cache.
             */
            IteratorCache newCache = new IteratorCache();
            final NodeVector nv;
            try {
                nv = (NodeVector) vec.clone();
            } catch (CloneNotSupportedException e) {
                // This should never happen
                e.printStackTrace();
                RuntimeException rte = new RuntimeException(e.getMessage());
                throw rte;
            }
            newCache.setVector(nv);
            newCache.setCacheComplete(true);
            m_cache = newCache;
            vec = nv;
            // Keep our superclass informed of the current NodeVector
            super.setObject(nv);
        /* When we get to here the new cache has
             * a use count of 1 and when setting a
             * bunch of values on the same NodeSequence,
             * such as when sorting, we will keep setting
             * values in that same copy which has a use count of 1.
             */
        }
        vec.setElementAt(node, index);
        m_last = vec.size();
    } else
        m_iter.setItem(node, index);
}
Also used : NodeVector(org.apache.xml.utils.NodeVector)

Example 13 with NodeVector

use of org.apache.xml.utils.NodeVector in project j2objc by google.

the class NodeSequence method setObject.

// end addNodeInDocOrder(Vector v, Object obj)
/**
 * It used to be that many locations in the code simply
 * did an assignment to this.m_obj directly, rather than
 * calling the setObject(Object) method. The problem is
 * that our super-class would be updated on what the
 * cache associated with this NodeSequence, but
 * we wouldn't know ourselves.
 * <p>
 * All setting of m_obj is done through setObject() now,
 * and this method over-rides the super-class method.
 * So now we are in the loop have an opportunity
 * to update some caching information.
 */
protected void setObject(Object obj) {
    if (obj instanceof NodeVector) {
        // Keep our superclass informed of the current NodeVector
        // ... if we don't the smoketest fails (don't know why).
        super.setObject(obj);
        // A copy of the code of what SetVector() would do.
        NodeVector v = (NodeVector) obj;
        if (m_cache != null) {
            m_cache.setVector(v);
        } else if (v != null) {
            m_cache = new IteratorCache();
            m_cache.setVector(v);
        }
    } else if (obj instanceof IteratorCache) {
        IteratorCache cache = (IteratorCache) obj;
        m_cache = cache;
        m_cache.increaseUseCount();
        // Keep our superclass informed of the current NodeVector
        super.setObject(cache.getVector());
    } else {
        super.setObject(obj);
    }
}
Also used : NodeVector(org.apache.xml.utils.NodeVector)

Example 14 with NodeVector

use of org.apache.xml.utils.NodeVector in project j2objc by google.

the class NodeSequence method getLength.

/**
 * @see DTMIterator#getLength()
 */
public int getLength() {
    IteratorCache cache = getCache();
    if (cache != null) {
        // Nodes from the iterator are cached
        if (cache.isComplete()) {
            // All of the nodes from the iterator are cached
            // so just return the number of nodes in the cache
            NodeVector nv = cache.getVector();
            return nv.size();
        }
        // it has been mutated...
        if (m_iter instanceof NodeSetDTM) {
            return m_iter.getLength();
        }
        if (-1 == m_last) {
            int pos = m_next;
            runTo(-1);
            m_next = pos;
        }
        return m_last;
    } else {
        return (-1 == m_last) ? (m_last = m_iter.getLength()) : m_last;
    }
}
Also used : NodeVector(org.apache.xml.utils.NodeVector) NodeSetDTM(org.apache.xpath.NodeSetDTM)

Aggregations

NodeVector (org.apache.xml.utils.NodeVector)14 NodeSetDTM (org.apache.xpath.NodeSetDTM)4 CountersTable (org.apache.xalan.transformer.CountersTable)2 DTM (org.apache.xml.dtm.DTM)2 XPathContext (org.apache.xpath.XPathContext)2 XObject (org.apache.xpath.objects.XObject)2