KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom4j > o3impl > DefaultNamespace


1 /*
2  * Copyright 2001 (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  * $Id: AbstractNamespace.java,v 1.3 2003/06/10 16:18:36 per_nyfelt Exp $
8  */

9
10 package org.ozoneDB.xml.dom4j.o3impl;
11
12 import org.dom4j.Element;
13
14 /** <p><code>AbstractNamespace</code> implements a doubly linked node which
15  * supports the parent relationship and is mutable.
16  * It is useful when returning results from XPath expressions.</p>
17  *
18  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
19  * @author Per Nyfelt
20  * @version $Revision: 1.3 $
21  */

22 public class DefaultNamespace extends AbstractNamespace {
23
24     /** The parent of this node */
25     private Element parent;
26
27     /** @param prefix is the prefix for this namespace
28      * @param uri is the URI for this namespace
29      */

30     public DefaultNamespace(String JavaDoc prefix, String JavaDoc uri) {
31         super(prefix, uri);
32     }
33
34     /** @param parent is the parent element
35      * @param prefix is the prefix for this namespace
36      * @param uri is the URI for this namespace
37      */

38     public DefaultNamespace(Element parent, String JavaDoc prefix, String JavaDoc uri) {
39         super(prefix, uri);
40         this.parent = parent;
41     }
42
43     /** @return the hash code based on the qualified name and the URI of the
44      * namespace and the hashCode() of the parent element.
45      */

46     protected int createHashCode() {
47         int hashCode = super.createHashCode();
48         if (parent != null) {
49             hashCode ^= parent.hashCode();
50         }
51         return hashCode;
52     }
53
54     /** Implements an identity based comparsion using the parent element as well as
55      * the prefix and URI
56      */

57     public boolean equals(Object JavaDoc object) {
58         if (object instanceof DefaultNamespace) {
59             DefaultNamespace that = (DefaultNamespace) object;
60             if (that.parent == parent) {
61                 return super.equals(object);
62             }
63         }
64         return false;
65     }
66
67
68     public Element getParent() {
69         return parent;
70     }
71
72     public void setParent(Element parent) {
73         this.parent = parent;
74     }
75
76     public boolean supportsParent() {
77         return true;
78     }
79 }
80
81
82 /*
83  * Redistribution and use of this software and associated documentation
84  * ("Software"), with or without modification, are permitted provided
85  * that the following conditions are met:
86  *
87  * 1. Redistributions of source code must retain copyright
88  * statements and notices. Redistributions must also contain a
89  * copy of this document.
90  *
91  * 2. Redistributions in binary form must reproduce the
92  * above copyright notice, this list of conditions and the
93  * following disclaimer in the documentation and/or other
94  * materials provided with the distribution.
95  *
96  * 3. The name "DOM4J" must not be used to endorse or promote
97  * products derived from this Software without prior written
98  * permission of MetaStuff, Ltd. For written permission,
99  * please contact dom4j-info@metastuff.com.
100  *
101  * 4. Products derived from this Software may not be called "DOM4J"
102  * nor may "DOM4J" appear in their names without prior written
103  * permission of MetaStuff, Ltd. DOM4J is a registered
104  * trademark of MetaStuff, Ltd.
105  *
106  * 5. Due credit should be given to the DOM4J Project
107  * (http://dom4j.org/).
108  *
109  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
110  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
111  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
112  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
113  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
114  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
115  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
116  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
117  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
118  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
119  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
120  * OF THE POSSIBILITY OF SUCH DAMAGE.
121  *
122  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
123  *
124  * $Id: AbstractNamespace.java,v 1.3 2003/06/10 16:18:36 per_nyfelt Exp $
125  */

126
Popular Tags