|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DefaultNamespace.java | 66,7% | 94,1% | 100% | 90,6% |
|
||||||||||||||
| 1 | /* | |
| 2 | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. | |
| 3 | * | |
| 4 | * This software is open source. | |
| 5 | * See the bottom of this file for the licence. | |
| 6 | */ | |
| 7 | ||
| 8 | package org.dom4j.tree; | |
| 9 | ||
| 10 | import org.dom4j.Element; | |
| 11 | import org.dom4j.Namespace; | |
| 12 | ||
| 13 | /** | |
| 14 | * <p> | |
| 15 | * <code>DefaultNamespace</code> implements a doubly linked node which | |
| 16 | * supports the parent relationship and is mutable. It is useful when returning | |
| 17 | * results from XPath expressions. | |
| 18 | * </p> | |
| 19 | * | |
| 20 | * @author <a href="mailto:jstrachan@apache.org">James Strachan </a> | |
| 21 | * @version $Revision: 1.16 $ | |
| 22 | */ | |
| 23 | public class DefaultNamespace extends Namespace { | |
| 24 | /** The parent of this node */ | |
| 25 | private Element parent; | |
| 26 | ||
| 27 | /** | |
| 28 | * DOCUMENT ME! | |
| 29 | * | |
| 30 | * @param prefix | |
| 31 | * is the prefix for this namespace | |
| 32 | * @param uri | |
| 33 | * is the URI for this namespace | |
| 34 | */ | |
| 35 | 159 | public DefaultNamespace(String prefix, String uri) { |
| 36 | 159 | super(prefix, uri); |
| 37 | } | |
| 38 | ||
| 39 | /** | |
| 40 | * DOCUMENT ME! | |
| 41 | * | |
| 42 | * @param parent | |
| 43 | * is the parent element | |
| 44 | * @param prefix | |
| 45 | * is the prefix for this namespace | |
| 46 | * @param uri | |
| 47 | * is the URI for this namespace | |
| 48 | */ | |
| 49 | 107 | public DefaultNamespace(Element parent, String prefix, String uri) { |
| 50 | 107 | super(prefix, uri); |
| 51 | 107 | this.parent = parent; |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * DOCUMENT ME! | |
| 56 | * | |
| 57 | * @return the hash code based on the qualified name and the URI of the | |
| 58 | * namespace and the hashCode() of the parent element. | |
| 59 | */ | |
| 60 | 170 | protected int createHashCode() { |
| 61 | 170 | int hashCode = super.createHashCode(); |
| 62 | ||
| 63 | 170 | if (parent != null) { |
| 64 | 29 | hashCode ^= parent.hashCode(); |
| 65 | } | |
| 66 | ||
| 67 | 170 | return hashCode; |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * Implements an identity based comparsion using the parent element as well | |
| 72 | * as the prefix and URI | |
| 73 | * | |
| 74 | * @param object | |
| 75 | * DOCUMENT ME! | |
| 76 | * | |
| 77 | * @return DOCUMENT ME! | |
| 78 | */ | |
| 79 | 137 | public boolean equals(Object object) { |
| 80 | 137 | if (object instanceof DefaultNamespace) { |
| 81 | 137 | DefaultNamespace that = (DefaultNamespace) object; |
| 82 | ||
| 83 | 137 | if (that.parent == parent) { |
| 84 | 137 | return super.equals(object); |
| 85 | } | |
| 86 | } | |
| 87 | ||
| 88 | 0 | return false; |
| 89 | } | |
| 90 | ||
| 91 | 448 | public int hashCode() { |
| 92 | 448 | return super.hashCode(); |
| 93 | } | |
| 94 | ||
| 95 | 581 | public Element getParent() { |
| 96 | 581 | return parent; |
| 97 | } | |
| 98 | ||
| 99 | 20 | public void setParent(Element parent) { |
| 100 | 20 | this.parent = parent; |
| 101 | } | |
| 102 | ||
| 103 | 29 | public boolean supportsParent() { |
| 104 | 29 | return true; |
| 105 | } | |
| 106 | ||
| 107 | 1 | public boolean isReadOnly() { |
| 108 | 1 | return false; |
| 109 | } | |
| 110 | } | |
| 111 | ||
| 112 | /* | |
| 113 | * Redistribution and use of this software and associated documentation | |
| 114 | * ("Software"), with or without modification, are permitted provided that the | |
| 115 | * following conditions are met: | |
| 116 | * | |
| 117 | * 1. Redistributions of source code must retain copyright statements and | |
| 118 | * notices. Redistributions must also contain a copy of this document. | |
| 119 | * | |
| 120 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 121 | * this list of conditions and the following disclaimer in the documentation | |
| 122 | * and/or other materials provided with the distribution. | |
| 123 | * | |
| 124 | * 3. The name "DOM4J" must not be used to endorse or promote products derived | |
| 125 | * from this Software without prior written permission of MetaStuff, Ltd. For | |
| 126 | * written permission, please contact dom4j-info@metastuff.com. | |
| 127 | * | |
| 128 | * 4. Products derived from this Software may not be called "DOM4J" nor may | |
| 129 | * "DOM4J" appear in their names without prior written permission of MetaStuff, | |
| 130 | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd. | |
| 131 | * | |
| 132 | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org | |
| 133 | * | |
| 134 | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND | |
| 135 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 136 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 137 | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE | |
| 138 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 139 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 140 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 141 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 142 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 143 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 144 | * POSSIBILITY OF SUCH DAMAGE. | |
| 145 | * | |
| 146 | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. | |
| 147 | */ |
|
||||||||||