📄 elementlistimpl.java
字号:
/** * org/ozone-db/xml/dom/ElementListImpl.java * * The contents of this file are subject to the OpenXML Public * License Version 1.0; you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.openxml.org/license.html * * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING * RIGHTS AND LIMITATIONS UNDER THE LICENSE. * * The Initial Developer of this code under the License is Assaf Arkin. * Portions created by Assaf Arkin are Copyright (C) 1998, 1999. * All Rights Reserved. *//** * Changes for Persistent DOM running with ozone are * Copyright 1999 by SMB GmbH. All rights reserved. */package org.ozoneDB.xml.dom;import java.util.*;import org.w3c.dom.*;/** * Implements a list of elements extracted based on their tag name. * The constructor recieves the root element and tag name. It then obtains * all the elements contained within that element that match the tag name, * or all of them if the tag name is "*". The list is then accessible * through the {@link #item} method. * <P> * The returned list is a snapshot of the element's contents at the time * of calling. Subsequent updates to the element are not reflected in the * list. This might result in inaccuracies when working from multiple threads. * * * @version $Revision: 1.10 $ $Date: 2000/10/28 16:55:23 $ * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a> * @see org.w3c.dom.NodeList * @see ElementImpl */final class ElementListImpl implements NodeList { final static long serialVersionUID = 1; public Node item( int index ) { if (index < 0 || index >= _elements.size()) { return null; } else { return (Node)_elements.elementAt( index ); } } public int getLength() { return _elements.size(); } /** * Add a single element to the list of elements. * * @param newElem The element to add */ void addElement( Element newElem ) { _elements.addElement( newElem ); } /** * Add all the elements contained in the root element and matching the * tag name. If the tag name is "*", all elements are added. Each element * is added by calling {@link #addElement} and the method is recursed on * all sub-elements. * * @param element The root element from which to extract all sub elements * @param tagName The tag name to match or "*" to match all tags */ void addElements( Node element, String tagName ) { Node node; // If tag name is "*" use null. if (tagName.equals( "*" )) { tagName = null; } // Traverse all the child nodes of this element. Each node that is // an element is added to the list if its tag name matches and this // method is recursed on that element. node = element.getFirstChild(); while (node != null) { if (node instanceof ElementProxy) { if (tagName == null || node.getNodeName().equals( tagName )) { addElement( (Element)node ); } addElements( node, tagName ); } node = node.getNextSibling(); } } /** * Constructor receieves an element and tag name and extracts all the * matching sub elements. After construction this object is ready for * element retrieval. * * @param element The root element from which to extract all sub elements * @param tagName The tag name to match or "*" to match all tags */ ElementListImpl( Node element, String tagName ) { init( element, tagName ); } public void init( Node element, String tagName ) { if (tagName == null) { throw new NullPointerException( "Argument 'tagName' is null." ); } _elements = new Vector(); addElements( element, tagName ); } public void init( NodeProxy node ) { throw new NullPointerException( "Argument 'tagName' is null." ); } /** * Holds a list of all the matching elements. This list is not live, updates * to the node tree are not reflected in this list. */ private Vector _elements; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -