/** * Constructor OMNavigator. * * @param node */ public DOMNavigator(OMNode node) { init(node); }
/** * This is a very special method. This allows the navigator to step once it has reached the * existing OM. At this point the isNavigable method will return false but the isComplete method * may return false which means that the navigating the given element is not complete but the * navigator cannot proceed. */ public void step() { if (!end) { next = node; updateNextNode(); } }
/** Method updateNextNode. */ private void updateNextNode() { if (navigator.isNavigable()) { nextNode = navigator.next(); } else { if (!switchingAllowed) { if (navigator.isCompleted()) { nextNode = null; } else { builder.next(); navigator.step(); nextNode = navigator.next(); } } else { // reset caching (the default is ON so it was not needed in the // earlier case! builder.setCache(false); state = SWITCH_AT_NEXT; } } }
/** * Constructor OMStAXWrapper * * @param builder * @param startNode * @param cache */ public DOMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode, boolean cache) { // create a navigator this.navigator = new DOMNavigator(startNode); this.builder = builder; this.rootNode = startNode; if (rootNode != null && rootNode.getParent() != null && rootNode.getParent() instanceof OMDocument) { needToThrowEndDocument = true; } // initaite the next and current nodes // Note - navigator is written in such a way that it first // returns the starting node at the first call to it currentNode = navigator.next(); updateNextNode(); switchingAllowed = !cache; }
/** * Gets the next node. * * @return Returns OMNode in the sequence of preorder traversal. Note however that an element * node is treated slightly differently. Once the element is passed it returns the same * element in the next encounter as well. */ public OMNode next() { if (next == null) { return null; } node = next; visited = backtracked; backtracked = false; updateNextNode(); // set the starting and ending flags if (root.equals(node)) { if (!start) { end = true; } else { start = false; } } return node; }