sax2dtm2.java
来自「JAVA 所有包」· Java 代码 · 共 2,403 行 · 第 1/5 页
JAVA
2,403 行
/** * Constructor TypedPrecedingIterator * * * @param type The extended type ID being requested. */ public TypedPrecedingIterator(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; if (nodeType >= DTM.NTYPES) { while (true) { node++; if (_sp < 0) { node = NULL; break; } else if (node >= _stack[_sp]) { if (--_sp < 0) { node = NULL; break; } } else if (_exptype2(node) == nodeType) { break; } } } else { int expType; while (true) { node++; if (_sp < 0) { node = NULL; break; } else if (node >= _stack[_sp]) { if (--_sp < 0) { node = NULL; break; } } else { expType = _exptype2(node); if (expType < DTM.NTYPES) { if (expType == nodeType) { break; } } else { if (m_extendedTypes[expType].getNodeType() == nodeType) { break; } } } } } _currentNode = node; return (node == NULL) ? NULL : returnNode(makeNodeHandle(node)); } } // end of TypedPrecedingIterator /** * Iterator that returns following nodes of for a given node. */ public class FollowingIterator extends InternalAxisIteratorBase { //DTMAxisTraverser m_traverser; // easier for now public FollowingIterator() { //m_traverser = getAxisTraverser(Axis.FOLLOWING); } /** * 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 = m_traverser.first(node); node = makeNodeIdentity(node); int first; int type = _type2(node); if ((DTM.ATTRIBUTE_NODE == type) || (DTM.NAMESPACE_NODE == type)) { node = _parent2(node); first = _firstch2(node); if (NULL != first) { _currentNode = makeNodeHandle(first); return resetPosition(); } } do { first = _nextsib2(node); if (NULL == first) node = _parent2(node); } while (NULL == first && NULL != node); _currentNode = makeNodeHandle(first); // _currentNode precedes possible following(node) nodes return resetPosition(); } return this; } /** * Get the next node in the iteration. * * @return The next node handle in the iteration, or END. */ public int next() { int node = _currentNode; //_currentNode = m_traverser.next(_startNode, _currentNode); int current = makeNodeIdentity(node); while (true) { current++; int type = _type2(current); if (NULL == type) { _currentNode = NULL; return returnNode(node); } if (ATTRIBUTE_NODE == type || NAMESPACE_NODE == type) continue; _currentNode = makeNodeHandle(current); return returnNode(node); } } } // end of FollowingIterator /** * Iterator that returns following nodes of a given type for a given node. */ public final class TypedFollowingIterator extends FollowingIterator { /** The extended type ID that was requested. */ private final int _nodeType; /** * Constructor TypedFollowingIterator * * * @param type The extended type ID being requested. */ public TypedFollowingIterator(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 current; int node; int type; final int nodeType = _nodeType; int currentNodeID = makeNodeIdentity(_currentNode); if (nodeType >= DTM.NTYPES) { do { node = currentNodeID; current = node; do { current++; type = _type2(current); } while (type != NULL && (ATTRIBUTE_NODE == type || NAMESPACE_NODE == type)); currentNodeID = (type != NULL) ? current : NULL; } while (node != DTM.NULL && _exptype2(node) != nodeType); } else { do { node = currentNodeID; current = node; do { current++; type = _type2(current); } while (type != NULL && (ATTRIBUTE_NODE == type || NAMESPACE_NODE == type)); currentNodeID = (type != NULL) ? current : NULL; } while (node != DTM.NULL && (_exptype2(node) != nodeType && _type2(node) != nodeType)); } _currentNode = makeNodeHandle(currentNodeID); return (node == DTM.NULL ? DTM.NULL :returnNode(makeNodeHandle(node))); } } // end of TypedFollowingIterator /** * Iterator that returns the ancestors of a given node in document * order. (NOTE! This was changed from the XSLTC code!) */ public class AncestorIterator extends InternalAxisIteratorBase { // The initial size of the ancestor array private static final int m_blocksize = 32; // The array for ancestor nodes. This array will grow dynamically. int[] m_ancestors = new int[m_blocksize]; // Number of ancestor nodes in the array int m_size = 0; int m_ancestorsPos; int m_markedPos; /** The real start node for this axes, since _startNode will be adjusted. */ int m_realStartNode; /** * Get start to END should 'close' the iterator, * i.e. subsequent call to next() should return END. * * @return The root node of the iteration. */ public int getStartNode() { return m_realStartNode; } /** * True if this iterator has a reversed axis. * * @return true since this iterator is a reversed axis. */ public final 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; // must set to false for any clone try { final AncestorIterator clone = (AncestorIterator) super.clone(); clone._startNode = _startNode; // 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(); m_realStartNode = node; if (_isRestartable) { int nodeID = makeNodeIdentity(node); m_size = 0; if (nodeID == DTM.NULL) { _currentNode = DTM.NULL; m_ancestorsPos = 0; return this; } // Start from the current node's parent if // _includeSelf is false. if (!_includeSelf) { nodeID = _parent2(nodeID); node = makeNodeHandle(nodeID); } _startNode = node; while (nodeID != END) { //m_ancestors.addElement(node); if (m_size >= m_ancestors.length) { int[] newAncestors = new int[m_size * 2]; System.arraycopy(m_ancestors, 0, newAncestors, 0, m_ancestors.length); m_ancestors = newAncestors; } m_ancestors[m_size++] = node; nodeID = _parent2(nodeID); node = makeNodeHandle(nodeID); } m_ancestorsPos = m_size - 1; _currentNode = (m_ancestorsPos>=0) ? m_ancestors[m_ancestorsPos] : DTM.NULL; return resetPosition(); } return this; } /** * 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() { m_ancestorsPos = m_size - 1; _currentNode = (m_ancestorsPos >= 0) ? m_ancestors[m_ancestorsPos] : DTM.NULL; return resetPosition(); } /** * Get the next node in the iteration. * * @return The next node handle in the iteration, or END. */ public int next() { int next = _currentNode; int pos = --m_ancestorsPos; _currentNode = (pos >= 0) ? m_ancestors[m_ancestorsPos] : DTM.NULL; return returnNode(next); } public void setMark() { m_markedPos = m_ancestorsPos; } public void gotoMark() { m_ancestorsPos = m_markedPos; _currentNode = m_ancestorsPos>=0 ? m_ancestors[m_ancestorsPos] : DTM.NULL; } } // end of AncestorIterator /** * Typed iterator that returns the ancestors of a given node. */ public final class TypedAncestorIterator extends AncestorIterator { /** The extended type ID that was requested. */ private final int _nodeType; /** * Constructor TypedAncestorIterator * * * @param type The extended type ID being requested. */ public TypedAncestorIterator(int type) { _nodeType = type; } /** * 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(); m_realStartNode = node; if (_isRestartable) { int nodeID = makeNodeIdentity(node); m_size = 0; if (nodeID == DTM.NULL) { _currentNode = DTM.NULL; m_ancestorsPos = 0; return this; } final int nodeType = _nodeType; if (!_includeSelf) { nodeID = _parent2(nodeID); node = makeNodeHandle(nodeID); } _startNode = node; if (nodeType >= DTM.NTYPES) { while (nodeID != END) { int eType = _exptype2(nodeID); if (eType == nodeType) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?