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: DefaultNamespace.java,v 1.9 2001/08/01 09:17:21 jstrachan Exp $ 008 */ 009 010package org.dom4j.tree; 011 012import org.dom4j.Element; 013import org.dom4j.Node; 014import org.dom4j.Namespace; 015 016/** <p><code>DefaultNamespace</code> implements a doubly linked node which 017 * supports the parent relationship and is mutable. 018 * It is useful when returning results from XPath expressions.</p> 019 * 020 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 021 * @version $Revision: 1.9 $ 022 */ 023public class DefaultNamespace extends Namespace { 024 025 /** The parent of this node */ 026 private Element parent; 027 028 /** @param prefix is the prefix for this namespace 029 * @param uri is the URI for this namespace 030 */ 031 public DefaultNamespace(String prefix,String uri) { 032 super( prefix, uri ); 033 } 034 035 /** @param parent is the parent element 036 * @param prefix is the prefix for this namespace 037 * @param uri is the URI for this namespace 038 */ 039 public DefaultNamespace(Element parent,String prefix,String uri) { 040 super( prefix, uri ); 041 this.parent = parent; 042 } 043 044 /** @return the hash code based on the qualified name and the URI of the 045 * namespace and the hashCode() of the parent element. 046 */ 047 protected int createHashCode() { 048 int hashCode = super.createHashCode(); 049 if ( parent != null ) { 050 hashCode ^= parent.hashCode(); 051 } 052 return hashCode; 053 } 054 055 /** Implements an identity based comparsion using the parent element as well as 056 * the prefix and URI 057 */ 058 public boolean equals(Object object) { 059 if ( object instanceof DefaultNamespace ) { 060 DefaultNamespace that = (DefaultNamespace) object; 061 if ( that.parent == parent ) { 062 return super.equals( object ); 063 } 064 } 065 return false; 066 } 067 068 069 public Element getParent() { 070 return parent; 071 } 072 073 public void setParent(Element parent) { 074 this.parent = parent; 075 } 076 077 public boolean supportsParent() { 078 return true; 079 } 080} 081 082 083 084 085/* 086 * Redistribution and use of this software and associated documentation 087 * ("Software"), with or without modification, are permitted provided 088 * that the following conditions are met: 089 * 090 * 1. Redistributions of source code must retain copyright 091 * statements and notices. Redistributions must also contain a 092 * copy of this document. 093 * 094 * 2. Redistributions in binary form must reproduce the 095 * above copyright notice, this list of conditions and the 096 * following disclaimer in the documentation and/or other 097 * materials provided with the distribution. 098 * 099 * 3. The name "DOM4J" must not be used to endorse or promote 100 * products derived from this Software without prior written 101 * permission of MetaStuff, Ltd. For written permission, 102 * please contact dom4j-info@metastuff.com. 103 * 104 * 4. Products derived from this Software may not be called "DOM4J" 105 * nor may "DOM4J" appear in their names without prior written 106 * permission of MetaStuff, Ltd. DOM4J is a registered 107 * trademark of MetaStuff, Ltd. 108 * 109 * 5. Due credit should be given to the DOM4J Project 110 * (http://dom4j.org/). 111 * 112 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 113 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 114 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 115 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 116 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 117 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 118 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 119 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 120 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 121 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 122 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 123 * OF THE POSSIBILITY OF SUCH DAMAGE. 124 * 125 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 126 * 127 * $Id: DefaultNamespace.java,v 1.9 2001/08/01 09:17:21 jstrachan Exp $ 128 */