Search in sources :

Example 1 with NodeVector

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

the class NodeSequence method getCurrentNode.

/**
   * @see DTMIterator#getCurrentNode()
   */
public int getCurrentNode() {
    if (hasCache()) {
        int currentIndex = m_next - 1;
        NodeVector vec = getVector();
        if ((currentIndex >= 0) && (currentIndex < vec.size()))
            return vec.elementAt(currentIndex);
        else
            return DTM.NULL;
    }
    if (null != m_iter) {
        return m_iter.getCurrentNode();
    } else
        return DTM.NULL;
}
Also used : NodeVector(org.apache.xml.utils.NodeVector)

Example 2 with NodeVector

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

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)

Example 3 with NodeVector

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

the class ElemNumber method getCountString.

/**
 * Given an XML source node, get the count according to the
 * parameters set up by the xsl:number attributes.
 * @param transformer non-null reference to the the current transform-time state.
 * @param sourceNode The source node being counted.
 *
 * @return The count of nodes
 *
 * @throws TransformerException
 */
String getCountString(TransformerImpl transformer, int sourceNode) throws TransformerException {
    long[] list = null;
    XPathContext xctxt = transformer.getXPathContext();
    CountersTable ctable = transformer.getCountersTable();
    if (null != m_valueExpr) {
        XObject countObj = m_valueExpr.execute(xctxt, sourceNode, this);
        // According to Errata E24
        double d_count = java.lang.Math.floor(countObj.num() + 0.5);
        if (Double.isNaN(d_count))
            return "NaN";
        else if (d_count < 0 && Double.isInfinite(d_count))
            return "-Infinity";
        else if (Double.isInfinite(d_count))
            return "Infinity";
        else if (d_count == 0)
            return "0";
        else {
            long count = (long) d_count;
            list = new long[1];
            list[0] = count;
        }
    } else {
        if (Constants.NUMBERLEVEL_ANY == m_level) {
            list = new long[1];
            list[0] = ctable.countNode(xctxt, this, sourceNode);
        } else {
            NodeVector ancestors = getMatchingAncestors(xctxt, sourceNode, Constants.NUMBERLEVEL_SINGLE == m_level);
            int lastIndex = ancestors.size() - 1;
            if (lastIndex >= 0) {
                list = new long[lastIndex + 1];
                for (int i = lastIndex; i >= 0; i--) {
                    int target = ancestors.elementAt(i);
                    list[lastIndex - i] = ctable.countNode(xctxt, this, target);
                }
            }
        }
    }
    return (null != list) ? formatNumberList(transformer, list, sourceNode) : "";
}
Also used : NodeVector(org.apache.xml.utils.NodeVector) CountersTable(org.apache.xalan.transformer.CountersTable) XPathContext(org.apache.xpath.XPathContext) XObject(org.apache.xpath.objects.XObject)

Example 4 with NodeVector

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

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 5 with NodeVector

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

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)

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