Debian Codegraph @

net/sf/saxon/om/NodeName.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.om;
9
10 /**
11 * This interface represents a node name. Actually it represents any QName, but it is intended for use
12 * as an element or attribute name. Various implementations are available.
13 * <p>An important requirement of an implementation of this interface is that the hashCode() and
14 * equals() methods are implemented correctly, so that any two node names compare equal if and only
15 * if the local name and namespace URI parts are equal under Unicode codepoint comparison. To ensure this,
16 * the hashCode must be computed using an algorithm equivalent to that used by the implementation class
17 * {@link FingerprintedQName}</p>
18 * <p>This class is used to carry name information for elements and attributes on the Receiver pipeline.
19 * An advantage of this is that NodeName can include a fingerprint where this is available, but the fingerprint
20 * does not need to be computed if it is not needed. For example, names of nodes constructed by an XSLT
21 * stylesheet and sent down an output pipeline to a Serializer will generally not have fingerprints.</p>
22 * <p>Equality comparisons between NodeNames work reasonably well: the comparison can use the fingerprints
23 * if available, or the QNames otherwise. However, computing hashCodes is inefficient; it is not possible
24 * to take advantage of the fingerprints, because they are not always there. Therefore, using NodeName
25 * objects in structures such as maps and sets is generally a bad idea: it's better to use either the
26 * StructuredQName or the fingerprint as the key.</p>
27 */
28
29 public interface NodeName extends IdentityComparable {
30
31 /**
32 * Get the prefix of the QName.
33 *
34 * @return the prefix. Returns the empty string if the name is unprefixed.
35 */
36
37 String getPrefix();
38
39 /**
40 * Get the namespace URI of the QName.
41 *
42 * @return the URI. Returns the empty string to represent the no-namespace
43 */
44
45 String getURI();
46
47 /**
48 * Get the local part of the QName
49 *
50 * @return the local part of the QName
51 */
52
53 String getLocalPart();
54
55 /**
56 * Get the display name, that is the lexical QName in the form [prefix:]local-part
57 *
58 * @return the lexical QName
59 */
60
61 String getDisplayName();
62
63 /**
64 * Get the name in the form of a StructuredQName
65 *
66 * @return the name in the form of a StructuredQName
67 */
68
69 StructuredQName getStructuredQName();
70
71 /**
72 * Test whether this name is in the same namespace as another name
73 *
74 * @param other the other name
75 * @return true if the two names are in the same namespace
76 */
77
78 boolean isInSameNamespace(NodeName other);
79
80 /**
81 * Test whether this name is in a given namespace
82 *
83 * @param ns the namespace to be tested against
84 * @return true if the name is in the specified namespace
85 */
86
87 boolean hasURI(String ns);
88
89 /**
90 * Get a {@link NamespaceBinding} whose (prefix, uri) pair are the prefix and URI of this
91 * node name
92 *
93 * @return the corresponding NamespaceBinding
94 */
95
96 NamespaceBinding getNamespaceBinding();
97
98 /**
99 * Ask whether this node name representation has a known fingerprint
100 *
101 * @return true if the method getFingerprint() will
102 * return a result other than -1
103 */
104
105 boolean hasFingerprint();
106
107 /**
108 * Get the fingerprint of this name if known. This method should not do any work to allocate
109 * a fingerprint if none is already available
110 *
111 * @return the fingerprint if known; otherwise -1
112 */
113
114 int getFingerprint();
115
116 /**
117 * Get the fingerprint of this name, allocating a new code from the namepool if necessary
118 *
119 * @param namePool the NamePool used to allocate the name
120 * @return a fingerprint for this name, newly allocated if necessary
121 */
122
123 int obtainFingerprint(NamePool namePool);
124
125 }