sax2dtm2.java
来自「JAVA 所有包」· Java 代码 · 共 2,403 行 · 第 1/5 页
JAVA
2,403 行
while ((node = _nextsib2(node)) != DTM.NULL && _exptype2(node) < DTM.NTYPES) {} } _currentNode = node; return (node == DTM.NULL) ? DTM.NULL : returnNode(makeNodeHandle(node)); } } // end of TypedFollowingSiblingIterator /** * Iterator that returns attribute nodes (of what nodes?) */ public final class AttributeIterator extends InternalAxisIteratorBase { // assumes caller will pass element nodes /** * Set start to END should 'close' the iterator, * i.e. subsequent call to next() should return END. * * @param node Sets the root of the iteration. * * @return A DTMAxisIterator set to the start of the iteration. */ public DTMAxisIterator setStartNode(int node) {//%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily if (node == DTMDefaultBase.ROOTNODE) node = getDocument(); if (_isRestartable) { _startNode = node; _currentNode = getFirstAttributeIdentity(makeNodeIdentity(node)); return resetPosition(); } return this; } /** * Get the next node in the iteration. * * @return The next node handle in the iteration, or END. */ public int next() { final int node = _currentNode; if (node != NULL) { _currentNode = getNextAttributeIdentity(node); return returnNode(makeNodeHandle(node)); } return NULL; } } // end of AttributeIterator /** * Iterator that returns attribute nodes of a given type */ public final class TypedAttributeIterator extends InternalAxisIteratorBase { /** The extended type ID that was requested. */ private final int _nodeType; /** * Constructor TypedAttributeIterator * * * @param nodeType The extended type ID that is requested. */ public TypedAttributeIterator(int nodeType) { _nodeType = nodeType; } // assumes caller will pass element nodes /** * Set start to END should 'close' the iterator, * i.e. subsequent call to next() should return END. * * @param node Sets the root of the iteration. * * @return A DTMAxisIterator set to the start of the iteration. */ public DTMAxisIterator setStartNode(int node) { if (_isRestartable) { _startNode = node; _currentNode = getTypedAttribute(node, _nodeType); return resetPosition(); } return this; } /** * Get the next node in the iteration. * * @return The next node handle in the iteration, or END. */ public int next() { final int node = _currentNode; // singleton iterator, since there can only be one attribute of // a given type. _currentNode = NULL; return returnNode(node); } } // end of TypedAttributeIterator /** * Iterator that returns preceding siblings of a given node */ public class PrecedingSiblingIterator extends InternalAxisIteratorBase { /** * The node identity of _startNode for this iterator */ protected int _startNodeID; /** * True if this iterator has a reversed axis. * * @return true. */ public boolean isReverse() { return true; } /** * Set start to END should 'close' the iterator, * i.e. subsequent call to next() should return END. * * @param node Sets the root of the iteration. * * @return A DTMAxisIterator set to the start of the iteration. */ public DTMAxisIterator setStartNode(int node) {//%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily if (node == DTMDefaultBase.ROOTNODE) node = getDocument(); if (_isRestartable) { _startNode = node; node = _startNodeID = makeNodeIdentity(node); if(node == NULL) { _currentNode = node; return resetPosition(); } int type = _type2(node); if(ExpandedNameTable.ATTRIBUTE == type || ExpandedNameTable.NAMESPACE == type ) { _currentNode = node; } else { // Be careful to handle the Document node properly _currentNode = _parent2(node); if(NULL!=_currentNode) _currentNode = _firstch2(_currentNode); else _currentNode = node; } return resetPosition(); } return this; } /** * Get the next node in the iteration. * * @return The next node handle in the iteration, or END. */ public int next() { if (_currentNode == _startNodeID || _currentNode == DTM.NULL) { return NULL; } else { final int node = _currentNode; _currentNode = _nextsib2(node); return returnNode(makeNodeHandle(node)); } } } // end of PrecedingSiblingIterator /** * Iterator that returns preceding siblings of a given type for * a given node */ public final class TypedPrecedingSiblingIterator extends PrecedingSiblingIterator { /** The extended type ID that was requested. */ private final int _nodeType; /** * Constructor TypedPrecedingSiblingIterator * * * @param type The extended type ID being requested. */ public TypedPrecedingSiblingIterator(int type) { _nodeType = type; } /** * Get the next node in the iteration. * * @return The next node handle in the iteration, or END. */ public int next() { int node = _currentNode; final int nodeType = _nodeType; final int startNodeID = _startNodeID; if (nodeType != DTM.ELEMENT_NODE) { while (node != NULL && node != startNodeID && _exptype2(node) != nodeType) { node = _nextsib2(node); } } else { while (node != NULL && node != startNodeID && _exptype2(node) < DTM.NTYPES) { node = _nextsib2(node); } } if (node == DTM.NULL || node == startNodeID) { _currentNode = NULL; return NULL; } else { _currentNode = _nextsib2(node); return returnNode(makeNodeHandle(node)); } } /** * Return the index of the last node in this iterator. */ public int getLast() { if (_last != -1) return _last; setMark(); int node = _currentNode; final int nodeType = _nodeType; final int startNodeID = _startNodeID; int last = 0; if (nodeType != DTM.ELEMENT_NODE) { while (node != NULL && node != startNodeID) { if (_exptype2(node) == nodeType) { last++; } node = _nextsib2(node); } } else { while (node != NULL && node != startNodeID) { if (_exptype2(node) >= DTM.NTYPES) { last++; } node = _nextsib2(node); } } gotoMark(); return (_last = last); } } // end of TypedPrecedingSiblingIterator /** * Iterator that returns preceding nodes of a given node. * This includes the node set {root+1, start-1}, but excludes * all ancestors, attributes, and namespace nodes. */ public class PrecedingIterator extends InternalAxisIteratorBase { /** The max ancestors, but it can grow... */ private final int _maxAncestors = 8; /** * The stack of start node + ancestors up to the root of the tree, * which we must avoid. */ protected int[] _stack = new int[_maxAncestors]; /** (not sure yet... -sb) */ protected int _sp, _oldsp; protected int _markedsp, _markedNode, _markedDescendant; /* _currentNode precedes candidates. This is the identity, not the handle! */ /** * True if this iterator has a reversed axis. * * @return true since this iterator is a reversed axis. */ public boolean isReverse() { return true; } /** * Returns a deep copy of this iterator. The cloned iterator is not reset. * * @return a deep copy of this iterator. */ public DTMAxisIterator cloneIterator() { _isRestartable = false; try { final PrecedingIterator clone = (PrecedingIterator) super.clone(); final int[] stackCopy = new int[_stack.length]; System.arraycopy(_stack, 0, stackCopy, 0, _stack.length); clone._stack = stackCopy; // return clone.reset(); return clone; } catch (CloneNotSupportedException e) { throw new DTMException(XMLMessages.createXMLMessage(XMLErrorResources.ER_ITERATOR_CLONE_NOT_SUPPORTED, null)); //"Iterator clone not supported."); } } /** * Set start to END should 'close' the iterator, * i.e. subsequent call to next() should return END. * * @param node Sets the root of the iteration. * * @return A DTMAxisIterator set to the start of the iteration. */ public DTMAxisIterator setStartNode(int node) {//%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily if (node == DTMDefaultBase.ROOTNODE) node = getDocument(); if (_isRestartable) { node = makeNodeIdentity(node); // iterator is not a clone int parent, index; if (_type2(node) == DTM.ATTRIBUTE_NODE) node = _parent2(node); _startNode = node; _stack[index = 0] = node; parent=node; while ((parent = _parent2(parent)) != NULL) { if (++index == _stack.length) { final int[] stack = new int[index*2]; System.arraycopy(_stack, 0, stack, 0, index); _stack = stack; } _stack[index] = parent; } if(index>0) --index; // Pop actual root node (if not start) back off the stack _currentNode=_stack[index]; // Last parent before root node _oldsp = _sp = index; return resetPosition(); } return this; } /** * Get the next node in the iteration. * * @return The next node handle in the iteration, or END. */ public int next() { // Bugzilla 8324: We were forgetting to skip Attrs and NS nodes. // Also recoded the loop controls for clarity and to flatten out // the tail-recursion. for(++_currentNode; _sp>=0; ++_currentNode) { if(_currentNode < _stack[_sp]) { int type = _type2(_currentNode); if(type != ATTRIBUTE_NODE && type != NAMESPACE_NODE) return returnNode(makeNodeHandle(_currentNode)); } else --_sp; } return NULL; } // redefine DTMAxisIteratorBase's reset /** * Resets the iterator to the last start node. * * @return A DTMAxisIterator, which may or may not be the same as this * iterator. */ public DTMAxisIterator reset() { _sp = _oldsp; return resetPosition(); } public void setMark() { _markedsp = _sp; _markedNode = _currentNode; _markedDescendant = _stack[0]; } public void gotoMark() { _sp = _markedsp; _currentNode = _markedNode; } } // end of PrecedingIterator /** * Iterator that returns preceding nodes of agiven type for a * given node. This includes the node set {root+1, start-1}, but * excludes all ancestors. */ public final class TypedPrecedingIterator extends PrecedingIterator { /** The extended type ID that was requested. */ private final int _nodeType;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?