2362N/A * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * ElementIterator, as the name suggests, iteratates over the Element 0N/A * tree. The constructor can be invoked with either Document or an Element 0N/A * as an argument. If the constructor is invoked with a Document as an 0N/A * argument then the root of the iteration is the return value of 0N/A * document.getDefaultRootElement(). 0N/A * The iteration happens in a depth-first manner. In terms of how 0N/A * boundary conditions are handled: 0N/A * a) if next() is called before first() or current(), the 0N/A * root will be returned. 0N/A * b) next() returns null to indicate the end of the list. 0N/A * c) previous() returns null when the current element is the root 0N/A * or next() has returned null. 0N/A * The ElementIterator does no locking of the Element tree. This means 0N/A * that it does not track any changes. It is the responsibility of the 0N/A * user of this class, to ensure that no changes happen during element 0N/A * Simple usage example: 0N/A * public void iterate() { 0N/A * ElementIterator it = new ElementIterator(root); 0N/A * if ((elem = next()) != null) { 0N/A * // process element 0N/A * System.out.println("elem: " + elem.getName()); 0N/A * @author Sunita Mani 0N/A * The StackItem class stores the element 0N/A * as well as a child index. If the 0N/A * index is -1, then the element represented 0N/A * on the stack is the element itself. 0N/A * Otherwise, the index functions as as index 0N/A * into the vector of children of the element. 0N/A * In this case, the item on the stack 0N/A * represents the "index"th child of the element 0N/A * -1 index implies a self reference, 0N/A * as opposed to an index into its 0N/A * Creates a new ElementIterator. The 0N/A * root element is taken to get the 0N/A * default root element of the document. 0N/A * @param document a Document. 0N/A * Creates a new ElementIterator. 0N/A * @param root the root Element. 0N/A * Clones the ElementIterator. 0N/A * @return a cloned ElementIterator Object. 0N/A * Fetches the first element. 0N/A * @return an Element. 0N/A * Fetches the current depth of element tree. 0N/A * @return the depth. 0N/A * Fetches the current Element. 0N/A * @return element on top of the stack or 0N/A * <code>null</code> if the root element is <code>null</code> 0N/A get a handle to the element on top of the stack. 0N/A // return the child at location "index". 0N/A * Fetches the next Element. The strategy 0N/A * used to locate the next element is 0N/A * a depth-first search. 0N/A * @return the next element or <code>null</code> 0N/A * at the end of the list. 0N/A /* if current() has not been invoked 0N/A and next is invoked, the very first 0N/A element will be returned. */ 0N/A // get a handle to the element on top of the stack 0N/A /* In this case we merely want to increment 0N/A the child index of the item on top of the 0N/A /* In this case we need to push the child(branch) 0N/A on the stack so that we can iterate over its 0N/A /* No more children for the item on top of the 0N/A stack therefore pop the stack. */ 0N/A /* Increment the child index for the item that 0N/A is now on top of the stack. */ 0N/A /* We now want to return its next child, therefore 0N/A call next() recursively. */ 0N/A * Fetches the previous Element. If howver the current 0N/A * element is the last element, or the current element 0N/A * is null, then null is returned. 0N/A * @return previous <code>Element</code> if available 0N/A // get a handle to the element on top of the stack 0N/A /* return child at previous index. */ 0N/A /* this implies that current is the element's 0N/A first child, therefore previous is the 0N/A // current is the root, nothing before it. 0N/A /* We need to return either the item 0N/A below the top item or one of the 0N/A former's children. */ 0N/A // restore the top item. 0N/A // should never get here. 0N/A * Returns the last child of <code>parent</code> that is a leaf. If the 0N/A * last child is a not a leaf, this method is called with the last child. 0N/A Iterates through the element tree and prints 0N/A out each element and its attributes. 0N/A // don't go recursive 0N/A s = s +
key +
"=**AttributeSet** ";