1
2
3
4
5
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 public DefaultNamespace(String prefix, String uri) {
36 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 public DefaultNamespace(Element parent, String prefix, String uri) {
50 super(prefix, uri);
51 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 protected int createHashCode() {
61 int hashCode = super.createHashCode();
62
63 if (parent != null) {
64 hashCode ^= parent.hashCode();
65 }
66
67 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 public boolean equals(Object object) {
80 if (object instanceof DefaultNamespace) {
81 DefaultNamespace that = (DefaultNamespace) object;
82
83 if (that.parent == parent) {
84 return super.equals(object);
85 }
86 }
87
88 return false;
89 }
90
91 public int hashCode() {
92 return super.hashCode();
93 }
94
95 public Element getParent() {
96 return parent;
97 }
98
99 public void setParent(Element parent) {
100 this.parent = parent;
101 }
102
103 public boolean supportsParent() {
104 return true;
105 }
106
107 public boolean isReadOnly() {
108 return false;
109 }
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147