Exemplo n.º 1
0
    /**
     * Evaluate the reference to the <code>key</code> or <code>id</code> function with the context
     * specified by {@link #setStartNode(int)} and set up this iterator to iterate over the DTM
     * nodes that are to be returned.
     */
    protected void init() {
      super.init();
      _position = 0;

      // All nodes retrieved are in the same document
      int rootHandle = _dom.getAxisIterator(Axis.ROOT).setStartNode(_startNode).next();

      // Is the argument not a node set?
      if (_keyValueIterator == null) {
        // Look up nodes returned for the single string argument
        _nodes = lookupNodes(rootHandle, _keyValue);

        if (_nodes == null) {
          _nodes = EMPTY_NODES;
        }
      } else {
        DTMAxisIterator keyValues = _keyValueIterator.reset();
        int retrievedKeyValueIdx = 0;
        boolean foundNodes = false;

        _nodes = null;

        // For each node in the node set argument, get the string value
        // and look up the nodes returned by key or id for that string
        // value.  If at most one string value has nodes associated,
        // the nodes will be stored in _nodes; otherwise, the nodes
        // will be placed in a heap.
        for (int keyValueNode = keyValues.next();
            keyValueNode != DTMAxisIterator.END;
            keyValueNode = keyValues.next()) {

          String keyValue = BasisLibrary.stringF(keyValueNode, _dom);

          IntegerArray nodes = lookupNodes(rootHandle, keyValue);

          if (nodes != null) {
            if (!foundNodes) {
              _nodes = nodes;
              foundNodes = true;
            } else {
              if (_nodes != null) {
                addHeapNode(new KeyIndexHeapNode(_nodes));
                _nodes = null;
              }
              addHeapNode(new KeyIndexHeapNode(nodes));
            }
          }
        }

        if (!foundNodes) {
          _nodes = EMPTY_NODES;
        }
      }
    }
  public DTMAxisIterator setStartNode(int node) {
    if (_isRestartable) {
      _source.setStartNode(_startNode = node);

      _nodes.clear();
      while ((node = _source.next()) != END) {
        _nodes.add(node);
      }
      _currentIndex = 0;
      resetPosition();
    }
    return this;
  }
Exemplo n.º 3
0
 public DTMAxisIterator setStartNode(int node) {
   if (_isRestartable) {
     _source.setStartNode(_startNode = node);
     return resetPosition();
   }
   return this;
 }
 public CurrentNodeListIterator(
     DTMAxisIterator source,
     CurrentNodeListFilter filter,
     int currentNode,
     AbstractTranslet translet) {
   this(source, !source.isReverse(), filter, currentNode, translet);
 }
Exemplo n.º 5
0
 public int next() {
   int node;
   while ((node = _source.next()) != END) {
     if (_filter.acceptNode(node, DTMFilter.SHOW_ALL) == DTMIterator.FILTER_ACCEPT) {
       return returnNode(node);
     }
   }
   return END;
 }
Exemplo n.º 6
0
  public DTMAxisIterator cloneIterator() {

    try {
      final FilterIterator clone = (FilterIterator) super.clone();
      clone._source = _source.cloneIterator();
      clone._isRestartable = false;
      return clone.reset();
    } catch (CloneNotSupportedException e) {
      BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR, e.toString());
      return null;
    }
  }
 public DTMAxisIterator cloneIterator() {
   try {
     final CurrentNodeListIterator clone = (CurrentNodeListIterator) super.clone();
     clone._nodes = (IntegerArray) _nodes.clone();
     clone._source = _source.cloneIterator();
     clone._isRestartable = false;
     return clone.reset();
   } catch (CloneNotSupportedException e) {
     BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR, e.toString());
     return null;
   }
 }
Exemplo n.º 8
0
    /**
     * Set context node for the iterator. This will cause the iterator to reset itself, reevaluate
     * arguments to the function, look up nodes in the input and reinitialize its internal heap.
     *
     * @param node the context node
     * @return A {@link DTMAxisIterator} set to the start of the iteration.
     */
    public DTMAxisIterator setStartNode(int node) {
      _startNode = node;

      // If the arugment to the function is a node set, set the
      // context node on it.
      if (_keyValueIterator != null) {
        _keyValueIterator = _keyValueIterator.setStartNode(node);
      }

      init();

      return super.setStartNode(node);
    }
 public int getNode(int index) {
   if (index < _numCachedNodes) {
     return _nodes.at(index);
   } else if (!_isEnded) {
     int node = _source.next();
     if (node != END) {
       _nodes.add(node);
       _numCachedNodes++;
     } else {
       _isEnded = true;
     }
     return node;
   } else return END;
 }
 public void copy(DTMAxisIterator nodes, SerializationHandler handler) throws TransletException {
   int node;
   while ((node = nodes.next()) != DTM.NULL) {
     copy(node, handler);
   }
 }
Exemplo n.º 11
0
 public DTMAxisIterator reset() {
   _source.reset();
   return resetPosition();
 }
Exemplo n.º 12
0
 public void setRestartable(boolean isRestartable) {
   _isRestartable = isRestartable;
   _source.setRestartable(isRestartable);
 }
Exemplo n.º 13
0
 public FilterIterator(DTMAxisIterator source, DTMFilter filter) {
   _source = source;
   // System.out.println("FI souce = " + source + " this = " + this);
   _filter = filter;
   _isReverse = source.isReverse();
 }
Exemplo n.º 14
0
 public void gotoMark() {
   _source.gotoMark();
 }
Exemplo n.º 15
0
 public void setMark() {
   _source.setMark();
 }