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