001/* 002 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 003 * 004 * This software is open source. 005 * See the bottom of this file for the licence. 006 * 007 * $Id: ElementNameIterator.java,v 1.4 2001/01/30 01:46:48 jstrachan Exp $ 008 */ 009 010package org.dom4j.tree; 011 012import java.util.Iterator; 013 014import org.dom4j.Element; 015import org.dom4j.Namespace; 016 017 018/** <p><code>ElementNameIterator</code> is a filtering {@link Iterator} which 019 * filters out objects which do not implement the {@link Element} 020 * interface and are not of the correct element name.</p> 021 * 022 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> 023 * @version $Revision: 1.4 $ 024 */ 025public class ElementNameIterator extends FilterIterator { 026 027 private String name; 028 029 public ElementNameIterator(Iterator proxy, String name) { 030 super(proxy); 031 this.name = name; 032 } 033 034 /** @return true if the given element implements the {@link Element} 035 * interface 036 */ 037 protected boolean matches(Object object) { 038 if (object instanceof Element) { 039 Element element = (Element) object; 040 return name.equals( element.getName() ); 041 } 042 return false; 043 } 044} 045 046 047 048 049/* 050 * Redistribution and use of this software and associated documentation 051 * ("Software"), with or without modification, are permitted provided 052 * that the following conditions are met: 053 * 054 * 1. Redistributions of source code must retain copyright 055 * statements and notices. Redistributions must also contain a 056 * copy of this document. 057 * 058 * 2. Redistributions in binary form must reproduce the 059 * above copyright notice, this list of conditions and the 060 * following disclaimer in the documentation and/or other 061 * materials provided with the distribution. 062 * 063 * 3. The name "DOM4J" must not be used to endorse or promote 064 * products derived from this Software without prior written 065 * permission of MetaStuff, Ltd. For written permission, 066 * please contact dom4j-info@metastuff.com. 067 * 068 * 4. Products derived from this Software may not be called "DOM4J" 069 * nor may "DOM4J" appear in their names without prior written 070 * permission of MetaStuff, Ltd. DOM4J is a registered 071 * trademark of MetaStuff, Ltd. 072 * 073 * 5. Due credit should be given to the DOM4J Project 074 * (http://dom4j.org/). 075 * 076 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 077 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 078 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 079 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 080 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 081 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 082 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 083 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 084 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 085 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 086 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 087 * OF THE POSSIBILITY OF SUCH DAMAGE. 088 * 089 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 090 * 091 * $Id: ElementNameIterator.java,v 1.4 2001/01/30 01:46:48 jstrachan Exp $ 092 */