Debian Codegraph @

net/sf/saxon/value/NotationValue.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.value;
9
10 import net.sf.saxon.om.NameChecker;
11 import net.sf.saxon.om.SequenceTool;
12 import net.sf.saxon.om.StructuredQName;
13 import net.sf.saxon.trans.XPathException;
14 import net.sf.saxon.type.AtomicType;
15 import net.sf.saxon.type.BuiltInAtomicType;
16
17
18 /**
19 * An xs:NOTATION value.
20 */
21
22 public final class NotationValue extends QualifiedNameValue {
23
24 /**
25 * Constructor
26 *
27 * @param prefix The prefix part of the QName (not used in comparisons). Use null or "" to represent the
28 * default prefix.
29 * @param uri The namespace part of the QName. Use null or "" to represent the null namespace.
30 * @param localName The local part of the QName
31 * @param check Used for request checking names against XML 1.0 or XML 1.1 syntax rules
32 */
33
34 public NotationValue(String prefix, String uri, String localName, boolean check) throws XPathException {
35 if (check && !NameChecker.isValidNCName(localName)) {
36 XPathException err = new XPathException("Malformed local name in NOTATION: '" + localName + '\'');
37 err.setErrorCode("FORG0001");
38 throw err;
39 }
40 prefix = prefix == null ? "" : prefix;
41 uri = uri == null ? "" : uri;
42 if (check && uri.isEmpty() && prefix.length() != 0) {
43 XPathException err = new XPathException("NOTATION has null namespace but non-empty prefix");
44 err.setErrorCode("FOCA0002");
45 throw err;
46 }
47 qName = new StructuredQName(prefix, uri, localName);
48 typeLabel = BuiltInAtomicType.NOTATION;
49 }
50
51 /**
52 * Constructor for a value that is known to be valid
53 *
54 * @param prefix The prefix part of the QName (not used in comparisons). Use null or "" to represent the
55 * default prefix.
56 * @param uri The namespace part of the QName. Use null or "" to represent the null namespace.
57 * @param localName The local part of the QName
58 */
59
60 public NotationValue(String prefix, String uri, String localName) {
61 qName = new StructuredQName(prefix, uri, localName);
62 typeLabel = BuiltInAtomicType.NOTATION;
63 }
64
65 /**
66 * Constructor for a value that is known to be valid
67 *
68 * @param prefix The prefix part of the QName (not used in comparisons). Use null or "" to represent the
69 * default prefix.
70 * @param uri The namespace part of the QName. Use null or "" to represent the null namespace.
71 * @param localName The local part of the QName
72 * @param typeLabel A type derived from xs:NOTATION to be used for the new value
73 */
74
75 public NotationValue(String prefix, String uri, String localName, AtomicType typeLabel) {
76 qName = new StructuredQName(prefix, uri, localName);
77 this.typeLabel = typeLabel;
78 }
79
80 /**
81 * Constructor
82 *
83 * @param qName the name as a StructuredQName
84 * @param typeLabel idenfies a subtype of xs:QName
85 */
86
87 public NotationValue(/*@Nullable*/ StructuredQName qName, /*@Nullable*/ AtomicType typeLabel) {
88 if (qName == null) {
89 throw new NullPointerException("qName");
90 }
91 if (typeLabel == null) {
92 throw new NullPointerException("typeLabel");
93 }
94 this.qName = qName;
95 this.typeLabel = typeLabel;
96 }
97
98
99 /**
100 * Create a copy of this atomic value, with a different type label
101 *
102 * @param typeLabel the type label of the new copy. The caller is responsible for checking that
103 * the value actually conforms to this type.
104 */
105
106 /*@NotNull*/
107 public AtomicValue copyAsSubType(AtomicType typeLabel) {
108 NotationValue v = new NotationValue(getPrefix(), getNamespaceURI(), getLocalName());
109 v.typeLabel = typeLabel;
110 return v;
111 }
112
113 /**
114 * Determine the primitive type of the value. This delivers the same answer as
115 * getItemType().getPrimitiveItemType(). The primitive types are
116 * the 19 primitive types of XML Schema, plus xs:integer, xs:dayTimeDuration and xs:yearMonthDuration,
117 * and xs:untypedAtomic. For external objects, the result is AnyAtomicType.
118 */
119
120 /*@NotNull*/
121 public BuiltInAtomicType getPrimitiveType() {
122 return BuiltInAtomicType.NOTATION;
123 }
124
125 /**
126 * Determine if two Notation values are equal. This comparison ignores the prefix part
127 * of the value.
128 *
129 * @throws ClassCastException if they are not comparable
130 * @throws IllegalStateException if the two QNames are in different name pools
131 */
132
133 public boolean equals(/*@NotNull*/ Object other) {
134 return other instanceof NotationValue && qName.equals(((NotationValue) other).qName);
135 }
136
137 /*@NotNull*/
138 public Comparable getSchemaComparable() {
139 return new NotationComparable();
140 }
141
142 private class NotationComparable implements Comparable {
143
144 /*@NotNull*/
145 public NotationValue getNotationValue() {
146 return NotationValue.this;
147 }
148
149 public int compareTo(/*@NotNull*/ Object o) {
150 return equals(o) ? 0 : SequenceTool.INDETERMINATE_ORDERING;
151 }
152
153 public boolean equals(/*@NotNull*/ Object o) {
154 return (o instanceof NotationComparable && qName.equals(((NotationComparable) o).getNotationValue().qName));
155 }
156
157 public int hashCode() {
158 return qName.hashCode();
159 }
160 }
161
162 /**
163 * The toString() method returns the name in the form QName("uri", "local")
164 *
165 * @return the name in Clark notation: {uri}local
166 */
167
168 /*@NotNull*/
169 public String toString() {
170 return "NOTATION(" + getClarkName() + ')';
171 }
172
173 }
174