Search in sources :

Example 6 with NodeVector

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

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

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

the class NodeSequence method nextNode.

/**
 * @see DTMIterator#nextNode()
 */
public int nextNode() {
    // If the cache is on, and the node has already been found, then
    // just return from the list.
    NodeVector vec = getVector();
    if (null != vec) {
        // There is a cache
        if (m_next < vec.size()) {
            // The node is in the cache, so just return it.
            int next = vec.elementAt(m_next);
            m_next++;
            return next;
        } else if (cacheComplete() || (-1 != m_last) || (null == m_iter)) {
            m_next++;
            return DTM.NULL;
        }
    }
    if (null == m_iter)
        return DTM.NULL;
    int next = m_iter.nextNode();
    if (DTM.NULL != next) {
        if (hasCache()) {
            if (m_iter.isDocOrdered()) {
                getVector().addElement(next);
                m_next++;
            } else {
                int insertIndex = addNodeInDocOrder(next);
                if (insertIndex >= 0)
                    m_next++;
            }
        } else
            m_next++;
    } else {
        // We have exhausted the iterator, and if there is a cache
        // it must have all nodes in it by now, so let the cache
        // know that it is complete.
        markCacheComplete();
        m_last = m_next;
        m_next++;
    }
    return next;
}
Also used : NodeVector(org.apache.xml.utils.NodeVector)

Example 8 with NodeVector

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

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

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

the class NodeSequence method nextNode.

/**
   * @see DTMIterator#nextNode()
   */
public int nextNode() {
    // If the cache is on, and the node has already been found, then 
    // just return from the list.
    NodeVector vec = getVector();
    if (null != vec) {
        // There is a cache
        if (m_next < vec.size()) {
            // The node is in the cache, so just return it.
            int next = vec.elementAt(m_next);
            m_next++;
            return next;
        } else if (cacheComplete() || (-1 != m_last) || (null == m_iter)) {
            m_next++;
            return DTM.NULL;
        }
    }
    if (null == m_iter)
        return DTM.NULL;
    int next = m_iter.nextNode();
    if (DTM.NULL != next) {
        if (hasCache()) {
            if (m_iter.isDocOrdered()) {
                getVector().addElement(next);
                m_next++;
            } else {
                int insertIndex = addNodeInDocOrder(next);
                if (insertIndex >= 0)
                    m_next++;
            }
        } else
            m_next++;
    } else {
        // We have exhausted the iterator, and if there is a cache
        // it must have all nodes in it by now, so let the cache
        // know that it is complete.
        markCacheComplete();
        m_last = m_next;
        m_next++;
    }
    return next;
}
Also used : NodeVector(org.apache.xml.utils.NodeVector)

Example 10 with NodeVector

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

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)

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