Debian Codegraph @

net/sf/saxon/s9api/ItemType.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.s9api;
9
10 import net.sf.saxon.lib.ConversionRules;
11 import net.sf.saxon.lib.NamespaceConstant;
12 import net.sf.saxon.lib.StandardURIChecker;
13 import net.sf.saxon.ma.arrays.ArrayItem;
14 import net.sf.saxon.ma.arrays.ArrayItemType;
15 import net.sf.saxon.ma.map.MapItem;
16 import net.sf.saxon.ma.map.MapType;
17 import net.sf.saxon.om.Function;
18 import net.sf.saxon.om.Item;
19 import net.sf.saxon.om.NodeInfo;
20 import net.sf.saxon.om.StructuredQName;
21 import net.sf.saxon.pattern.AnyNodeTest;
22 import net.sf.saxon.pattern.NodeKindTest;
23 import net.sf.saxon.pattern.NodeTest;
24 import net.sf.saxon.type.*;
25 import net.sf.saxon.value.AtomicValue;
26 import net.sf.saxon.value.NumericValue;
27
28 /**
29 * An item type, as defined in the XPath/XQuery specifications.
30 * <p>This class contains a number of static constant fields
31 * referring to instances that represent simple item types, such as
32 * <code>item()</code>, <code>node()</code>, and <code>xs:anyAtomicType</code>. These named types are currently
33 * based on the definitions in XSD 1.0 and XML 1.0. They may be changed in a future version to be based
34 * on a later version.</p>
35 * <p>More complicated item types, especially those that are dependent on information in a schema,
36 * are available using factory methods on the {@link ItemTypeFactory} object. The factory methods can
37 * also be used to create variants of the types that use the rules given in the XML 1.1 and/or XSD 1.1 specifications.</p>
38 */
39
40 public abstract class ItemType {
41
42 private static ConversionRules defaultConversionRules = new ConversionRules();
43
44 static {
45 defaultConversionRules.setStringToDoubleConverter(StringToDouble.getInstance());
46 defaultConversionRules.setNotationSet(null);
47 defaultConversionRules.setURIChecker(StandardURIChecker.getInstance());
48 }
49
50 /**
51 * ItemType representing the type item(), that is, any item at all
52 */
53
54 public static ItemType ANY_ITEM = new ItemType() {
55
56 public ConversionRules getConversionRules() {
57 return defaultConversionRules;
58 }
59
60 public boolean matches(XdmItem item) {
61 return true;
62 }
63
64 public boolean subsumes(ItemType other) {
65 return true;
66 }
67
68 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
69 return AnyItemType.getInstance();
70 }
71 };
72
73
74 /**
75 * ItemType representing the type function(*), that is, any function
76 */
77
78 public static ItemType ANY_FUNCTION = new ItemType() {
79
80 public boolean matches(XdmItem item) {
81 return item.getUnderlyingValue() instanceof Function;
82 }
83
84 public boolean subsumes(ItemType other) {
85 return other.getUnderlyingItemType() instanceof FunctionItemType;
86 }
87
88 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
89 return AnyFunctionType.getInstance();
90 }
91 };
92
93 /**
94 * ItemType representing the type node(), that is, any node
95 */
96
97 public static final ItemType ANY_NODE = new ItemType() {
98
99 public boolean matches(XdmItem item) {
100 return item.getUnderlyingValue() instanceof NodeInfo;
101 }
102
103 public boolean subsumes(ItemType other) {
104 return other.getUnderlyingItemType() instanceof NodeTest;
105 }
106
107 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
108 return AnyNodeTest.getInstance();
109 }
110 };
111
112
113 /**
114 * ItemType representing the ATTRIBUTE node() type
115 */
116
117 public static final ItemType ATTRIBUTE_NODE = new ItemType() {
118
119 public boolean matches(XdmItem item) {
120 Item<?> it = item.getUnderlyingValue();
121 return it instanceof NodeInfo && ((NodeInfo) it).getNodeKind() == Type.ATTRIBUTE;
122 }
123
124 public boolean subsumes(ItemType other) {
125 return other.getUnderlyingItemType().getUType() == UType.ATTRIBUTE;
126 }
127
128 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
129 return NodeKindTest.ATTRIBUTE;
130 }
131 };
132
133
134 /**
135 * ItemType representing the COMMENT node() type
136 */
137
138 public static final ItemType COMMENT_NODE = new ItemType() {
139
140 public boolean matches(XdmItem item) {
141 Item<?> it = item.getUnderlyingValue();
142 return it instanceof NodeInfo && ((NodeInfo) it).getNodeKind() == Type.COMMENT;
143 }
144
145 public boolean subsumes(ItemType other) {
146 return other.getUnderlyingItemType().getUType() == UType.COMMENT;
147 }
148
149 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
150 return NodeKindTest.COMMENT;
151 }
152 };
153
154
155 /**
156 * ItemType representing the TEXT node() type
157 */
158
159 public static final ItemType TEXT_NODE = new ItemType() {
160
161 public boolean matches(XdmItem item) {
162 Item<?> it = item.getUnderlyingValue();
163 return it instanceof NodeInfo && ((NodeInfo) it).getNodeKind() == Type.TEXT;
164 }
165
166 public boolean subsumes(ItemType other) {
167 return other.getUnderlyingItemType().getUType() == UType.TEXT;
168 }
169
170 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
171 return NodeKindTest.TEXT;
172 }
173 };
174
175
176 /**
177 * ItemType representing the ELEMENT node() type
178 */
179
180 public static final ItemType ELEMENT_NODE = new ItemType() {
181
182 public boolean matches(XdmItem item) {
183 Item<?> it = item.getUnderlyingValue();
184 return it instanceof NodeInfo && ((NodeInfo) it).getNodeKind() == Type.ELEMENT;
185 }
186
187 public boolean subsumes(ItemType other) {
188 return other.getUnderlyingItemType().getUType() == UType.ELEMENT;
189 }
190
191 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
192 return NodeKindTest.ELEMENT;
193 }
194 };
195
196 /**
197 * ItemType representing the DOCUMENT node() type
198 */
199
200 public static final ItemType DOCUMENT_NODE = new ItemType() {
201
202 public boolean matches(XdmItem item) {
203 Item<?> it = item.getUnderlyingValue();
204 return it instanceof NodeInfo && ((NodeInfo) it).getNodeKind() == Type.DOCUMENT;
205 }
206
207 public boolean subsumes(ItemType other) {
208 return other.getUnderlyingItemType().getUType() == UType.DOCUMENT;
209 }
210
211 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
212 return NodeKindTest.DOCUMENT;
213 }
214 };
215
216
217 /**
218 * ItemType representing the NAMESPACE node() type
219 */
220
221 public static final ItemType NAMESPACE_NODE = new ItemType() {
222
223 public boolean matches(XdmItem item) {
224 Item<?> it = item.getUnderlyingValue();
225 return it instanceof NodeInfo && ((NodeInfo) it).getNodeKind() == Type.NAMESPACE;
226 }
227
228 public boolean subsumes(ItemType other) {
229 return other.getUnderlyingItemType().getUType() == UType.NAMESPACE;
230 }
231
232 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
233 return NodeKindTest.NAMESPACE;
234 }
235 };
236
237
238 /**
239 * ItemType representing the PROCESSING_INSTRUCTION node() type
240 */
241
242 public static final ItemType PROCESSING_INSTRUCTION_NODE = new ItemType() {
243
244 public boolean matches(XdmItem item) {
245 Item<?> it = item.getUnderlyingValue();
246 return it instanceof NodeInfo && ((NodeInfo) it).getNodeKind() == Type.PROCESSING_INSTRUCTION;
247 }
248
249 public boolean subsumes(ItemType other) {
250 return other.getUnderlyingItemType().getUType() == UType.PI;
251 }
252
253 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
254 return NodeKindTest.PROCESSING_INSTRUCTION;
255 }
256 };
257
258
259 /**
260 * ItemType representing the type map(*), that is, any map
261 */
262
263 public static final ItemType ANY_MAP = new ItemType() {
264
265 public boolean matches(XdmItem item) {
266 return item.getUnderlyingValue() instanceof MapItem;
267 }
268
269 public boolean subsumes(ItemType other) {
270 return other.getUnderlyingItemType() instanceof MapType;
271 }
272
273 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
274 return MapType.ANY_MAP_TYPE;
275 }
276 };
277
278 /**
279 * ItemType representing the type array(*), that is, any array
280 */
281
282 public static final ItemType ANY_ARRAY = new ItemType() {
283
284 public boolean matches(XdmItem item) {
285 return item.getUnderlyingValue() instanceof ArrayItem;
286 }
287
288 public boolean subsumes(ItemType other) {
289 return other.getUnderlyingItemType() instanceof ArrayItemType;
290 }
291
292 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
293 return ArrayItemType.ANY_ARRAY_TYPE;
294 }
295 };
296
297
298 /**
299 * ItemType representing the type xs:anyAtomicType, that is, any atomic value
300 */
301
302 public static final ItemType ANY_ATOMIC_VALUE = new ItemType() {
303
304 public boolean matches(XdmItem item) {
305 return item.getUnderlyingValue() instanceof AtomicValue;
306 }
307
308 public boolean subsumes(ItemType other) {
309 return other.getUnderlyingItemType() instanceof AtomicType;
310 }
311
312 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
313 return BuiltInAtomicType.ANY_ATOMIC;
314 }
315 };
316
317 /**
318 * ItemType representing a built-in atomic type
319 */
320
321 static class BuiltInAtomicItemType extends ItemType {
322
323 private BuiltInAtomicType underlyingType;
324 private ConversionRules conversionRules;
325
326 public BuiltInAtomicItemType(BuiltInAtomicType underlyingType, ConversionRules conversionRules) {
327 this.underlyingType = underlyingType;
328 this.conversionRules = conversionRules;
329 }
330
331 public static BuiltInAtomicItemType makeVariant(BuiltInAtomicItemType type, ConversionRules conversionRules) {
332 return new BuiltInAtomicItemType(type.underlyingType, conversionRules);
333 }
334
335 public ConversionRules getConversionRules() {
336 return conversionRules;
337 }
338
339 public boolean matches(XdmItem item) {
340 Item value = item.getUnderlyingValue();
341 if (!(value instanceof AtomicValue)) {
342 return false;
343 }
344 AtomicType type = ((AtomicValue) value).getItemType();
345 return subsumesUnderlyingType(type);
346 }
347
348 public boolean subsumes(ItemType other) {
349 net.sf.saxon.type.ItemType otherType = other.getUnderlyingItemType();
350 if (!otherType.isPlainType()) {
351 return false;
352 }
353 AtomicType type = (AtomicType) otherType;
354 return subsumesUnderlyingType(type);
355 }
356
357 private boolean subsumesUnderlyingType(AtomicType type) {
358 BuiltInAtomicType builtIn =
359 type instanceof BuiltInAtomicType ? (BuiltInAtomicType) type : (BuiltInAtomicType) type.getBuiltInBaseType();
360 while (true) {
361 if (builtIn.isSameType(underlyingType)) {
362 return true;
363 }
364 SchemaType base = builtIn.getBaseType();
365 if (!(base instanceof BuiltInAtomicType)) {
366 return false;
367 }
368 builtIn = (BuiltInAtomicType) base;
369 }
370 }
371
372 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
373 return underlyingType;
374 }
375 }
376
377 /**
378 * ItemType representing the primitive type xs:string
379 */
380
381 public static final ItemType STRING = atomic(BuiltInAtomicType.STRING, defaultConversionRules);
382
383 /**
384 * ItemType representing the primitive type xs:boolean
385 */
386
387 public static final ItemType BOOLEAN = atomic(BuiltInAtomicType.BOOLEAN, defaultConversionRules);
388
389 /**
390 * ItemType representing the primitive type xs:duration
391 */
392
393 public static final ItemType DURATION = atomic(BuiltInAtomicType.DURATION, defaultConversionRules);
394
395 /**
396 * ItemType representing the primitive type xs:dateTime
397 */
398
399 public static final ItemType DATE_TIME = atomic(BuiltInAtomicType.DATE_TIME, defaultConversionRules);
400
401 /**
402 * ItemType representing the primitive type xs:date
403 */
404
405 public static final ItemType DATE = atomic(BuiltInAtomicType.DATE, defaultConversionRules);
406
407 /**
408 * ItemType representing the primitive type xs:time
409 */
410
411 public static final ItemType TIME = atomic(BuiltInAtomicType.TIME, defaultConversionRules);
412
413 /**
414 * ItemType representing the primitive type xs:gYearMonth
415 */
416
417 public static final ItemType G_YEAR_MONTH = atomic(BuiltInAtomicType.G_YEAR_MONTH, defaultConversionRules);
418
419 /**
420 * ItemType representing the primitive type xs:gMonth
421 */
422
423 public static final ItemType G_MONTH = atomic(BuiltInAtomicType.G_MONTH, defaultConversionRules);
424
425 /**
426 * ItemType representing the primitive type xs:gMonthDay
427 */
428
429 public static final ItemType G_MONTH_DAY = atomic(BuiltInAtomicType.G_MONTH_DAY, defaultConversionRules);
430
431 /**
432 * ItemType representing the primitive type xs:gYear
433 */
434
435 public static final ItemType G_YEAR = atomic(BuiltInAtomicType.G_YEAR, defaultConversionRules);
436
437 /**
438 * ItemType representing the primitive type xs:gDay
439 */
440
441 public static final ItemType G_DAY = atomic(BuiltInAtomicType.G_DAY, defaultConversionRules);
442
443 /**
444 * ItemType representing the primitive type xs:hexBinary
445 */
446
447 public static final ItemType HEX_BINARY = atomic(BuiltInAtomicType.HEX_BINARY, defaultConversionRules);
448
449 /**
450 * ItemType representing the primitive type xs:base64Binary
451 */
452
453 public static final ItemType BASE64_BINARY = atomic(BuiltInAtomicType.BASE64_BINARY, defaultConversionRules);
454
455 /**
456 * ItemType representing the primitive type xs:anyURI
457 */
458
459 public static final ItemType ANY_URI = atomic(BuiltInAtomicType.ANY_URI, defaultConversionRules);
460
461 /**
462 * ItemType representing the primitive type xs:QName
463 */
464
465 public static final ItemType QNAME = atomic(BuiltInAtomicType.QNAME, defaultConversionRules);
466
467 /**
468 * ItemType representing the primitive type xs:NOTATION
469 */
470
471 public static final ItemType NOTATION = atomic(BuiltInAtomicType.NOTATION, defaultConversionRules);
472
473 /**
474 * ItemType representing the XPath-defined type xs:untypedAtomic
475 */
476
477 public static final ItemType UNTYPED_ATOMIC = atomic(BuiltInAtomicType.UNTYPED_ATOMIC, defaultConversionRules);
478
479 /**
480 * ItemType representing the primitive type xs:decimal
481 */
482
483 public static final ItemType DECIMAL = atomic(BuiltInAtomicType.DECIMAL, defaultConversionRules);
484
485 /**
486 * ItemType representing the primitive type xs:float
487 */
488
489 public static final ItemType FLOAT = atomic(BuiltInAtomicType.FLOAT, defaultConversionRules);
490
491 /**
492 * ItemType representing the primitive type xs:double
493 */
494
495 public static final ItemType DOUBLE = atomic(BuiltInAtomicType.DOUBLE, defaultConversionRules);
496
497 /**
498 * ItemType representing the built-in (but non-primitive) type xs:integer
499 */
500
501 public static final ItemType INTEGER = atomic(BuiltInAtomicType.INTEGER, defaultConversionRules);
502
503 /**
504 * ItemType representing the built-in (but non-primitive) type xs:nonPositiveInteger
505 */
506
507 public static final ItemType NON_POSITIVE_INTEGER = atomic(BuiltInAtomicType.NON_POSITIVE_INTEGER, defaultConversionRules);
508
509 /**
510 * ItemType representing the built-in (but non-primitive) type xs:negativeInteger
511 */
512
513 public static final ItemType NEGATIVE_INTEGER = atomic(BuiltInAtomicType.NEGATIVE_INTEGER, defaultConversionRules);
514
515 /**
516 * ItemType representing the built-in (but non-primitive) type xs:long
517 */
518
519 public static final ItemType LONG = atomic(BuiltInAtomicType.LONG, defaultConversionRules);
520
521 /**
522 * ItemType representing the built-in (but non-primitive) type xs:int
523 */
524
525 public static final ItemType INT = atomic(BuiltInAtomicType.INT, defaultConversionRules);
526
527 /**
528 * ItemType representing the built-in (but non-primitive) type xs:short
529 */
530
531 public static final ItemType SHORT = atomic(BuiltInAtomicType.SHORT, defaultConversionRules);
532
533 /**
534 * ItemType representing the built-in (but non-primitive) type xs:byte
535 */
536
537 public static final ItemType BYTE = atomic(BuiltInAtomicType.BYTE, defaultConversionRules);
538
539 /**
540 * ItemType representing the built-in (but non-primitive) type xs:nonNegativeInteger
541 */
542
543 public static final ItemType NON_NEGATIVE_INTEGER = atomic(BuiltInAtomicType.NON_NEGATIVE_INTEGER, defaultConversionRules);
544
545 /**
546 * ItemType representing the built-in (but non-primitive) type xs:positiveInteger
547 */
548
549 public static final ItemType POSITIVE_INTEGER = atomic(BuiltInAtomicType.POSITIVE_INTEGER, defaultConversionRules);
550
551 /**
552 * ItemType representing the built-in (but non-primitive) type xs:unsignedLong
553 */
554
555 public static final ItemType UNSIGNED_LONG = atomic(BuiltInAtomicType.UNSIGNED_LONG, defaultConversionRules);
556
557 /**
558 * ItemType representing the built-in (but non-primitive) type xs:unsignedInt
559 */
560
561 public static final ItemType UNSIGNED_INT = atomic(BuiltInAtomicType.UNSIGNED_INT, defaultConversionRules);
562
563 /**
564 * ItemType representing the built-in (but non-primitive) type xs:unsignedShort
565 */
566
567 public static final ItemType UNSIGNED_SHORT = atomic(BuiltInAtomicType.UNSIGNED_SHORT, defaultConversionRules);
568
569 /**
570 * ItemType representing the built-in (but non-primitive) type xs:unsignedByte
571 */
572
573 public static final ItemType UNSIGNED_BYTE = atomic(BuiltInAtomicType.UNSIGNED_BYTE, defaultConversionRules);
574
575 /**
576 * ItemType representing the built-in (but non-primitive) type xs:yearMonthDuration
577 */
578
579 public static final ItemType YEAR_MONTH_DURATION = atomic(BuiltInAtomicType.YEAR_MONTH_DURATION, defaultConversionRules);
580
581 /**
582 * ItemType representing the built-in (but non-primitive) type xs:dayTimeDuration
583 */
584
585 public static final ItemType DAY_TIME_DURATION = atomic(BuiltInAtomicType.DAY_TIME_DURATION, defaultConversionRules);
586
587 /**
588 * ItemType representing the built-in (but non-primitive) type xs:normalizedString
589 */
590
591 public static final ItemType NORMALIZED_STRING = atomic(BuiltInAtomicType.NORMALIZED_STRING, defaultConversionRules);
592
593 /**
594 * ItemType representing the built-in (but non-primitive) type xs:token
595 */
596
597 public static final ItemType TOKEN = atomic(BuiltInAtomicType.TOKEN, defaultConversionRules);
598
599 /**
600 * ItemType representing the built-in (but non-primitive) type xs:language
601 */
602
603 public static final ItemType LANGUAGE = atomic(BuiltInAtomicType.LANGUAGE, defaultConversionRules);
604
605 /**
606 * ItemType representing the built-in (but non-primitive) type xs:Name
607 */
608
609 public static final ItemType NAME = atomic(BuiltInAtomicType.NAME, defaultConversionRules);
610
611 /**
612 * ItemType representing the built-in (but non-primitive) type xs:NMTOKEN
613 */
614
615 public static final ItemType NMTOKEN = atomic(BuiltInAtomicType.NMTOKEN, defaultConversionRules);
616
617 /**
618 * ItemType representing the built-in (but non-primitive) type xs:NCName
619 */
620
621 public static final ItemType NCNAME = atomic(BuiltInAtomicType.NCNAME, defaultConversionRules);
622
623 /**
624 * ItemType representing the built-in (but non-primitive) type xs:ID
625 */
626
627 public static final ItemType ID = atomic(BuiltInAtomicType.ID, defaultConversionRules);
628
629 /**
630 * ItemType representing the built-in (but non-primitive) type xs:IDREF
631 */
632
633 public static final ItemType IDREF = atomic(BuiltInAtomicType.IDREF, defaultConversionRules);
634
635 /**
636 * ItemType representing the built-in (but non-primitive) type xs:ENTITY
637 */
638
639 public static final ItemType ENTITY = atomic(BuiltInAtomicType.ENTITY, defaultConversionRules);
640
641 /**
642 * ItemType representing the built-in (but non-primitive) type xs:dateTimeStamp
643 * (introduced in XSD 1.1)
644 */
645
646 public static final ItemType DATE_TIME_STAMP = atomic(BuiltInAtomicType.DATE_TIME_STAMP, defaultConversionRules);
647
648 /**
649 * Create an ItemType representing a built-in atomic type.
650 *
651 * @param underlyingType the BuiltInAtomicType object representing this type
652 * @param conversionRules the conversion rules to be used
653 * @return the ItemType.
654 */
655
656 private static ItemType atomic(BuiltInAtomicType underlyingType, ConversionRules conversionRules) {
657 return new BuiltInAtomicItemType(underlyingType, conversionRules);
658 }
659
660 /**
661 * ItemType representing the built-in union type xs:numeric defined in XDM 3.1
662 */
663
664 public static final ItemType NUMERIC = new ItemType() {
665 @Override
666 public ConversionRules getConversionRules() {
667 return defaultConversionRules;
668 }
669
670 @Override
671 public boolean matches(XdmItem item) {
672 return item.getUnderlyingValue() instanceof NumericValue;
673 }
674
675 @Override
676 public boolean subsumes(ItemType other) {
677 return DECIMAL.subsumes(other) || DOUBLE.subsumes(other) || FLOAT.subsumes(other);
678 }
679
680 @Override
681 public net.sf.saxon.type.ItemType getUnderlyingItemType() {
682 return NumericType.getInstance();
683 }
684 };
685
686 /**
687 * Get the conversion rules implemented by this type. The conversion rules reflect variations
688 * between different versions of the W3C specifications, for example XSD 1.1 allows "+INF" as
689 * a lexical representation of xs:double, while XSD 1.0 does not.
690 *
691 * @return the conversion rules
692 */
693
694 /*@Nullable*/
695 public ConversionRules getConversionRules() {
696 return defaultConversionRules;
697 }
698
699 /**
700 * Determine whether this item type matches a given item.
701 *
702 * @param item the item to be tested against this item type
703 * @return true if the item matches this item type, false if it does not match.
704 */
705
706 public abstract boolean matches(XdmItem item);
707
708 /**
709 * Determine whether this ItemType subsumes another ItemType. Specifically,
710 * <code>A.subsumes(B)</code> is true if every value that matches the ItemType B also matches
711 * the ItemType A.
712 *
713 * @param other the other ItemType
714 * @return true if this ItemType subsumes the other ItemType. This includes the case where A and B
715 * represent the same ItemType.
716 * @since 9.1
717 */
718
719 public abstract boolean subsumes(ItemType other);
720
721 /**
722 * Method to get the underlying Saxon implementation object
723 * <p>This gives access to Saxon methods that may change from one release to another.</p>
724 *
725 * @return the underlying Saxon implementation object
726 */
727
728 public abstract net.sf.saxon.type.ItemType getUnderlyingItemType();
729
730 /**
731 * Get the name of the type, if it has one
732 *
733 * @return the name of the type, or null if it is either an anonymous schema-defined type,
734 * or an XDM-defined type such as node() or map().
735 * @since 9.7
736 */
737
738 public QName getTypeName() {
739 net.sf.saxon.type.ItemType type = getUnderlyingItemType();
740 if (type instanceof SchemaType) {
741 StructuredQName name = ((SchemaType) type).getStructuredQName();
742 return name == null ? null : new QName(name);
743 } else {
744 return null;
745 }
746 }
747
748 /**
749 * Test whether two ItemType objects represent the same type
750 *
751 * @param other the other ItemType object
752 * @return true if the other object is an ItemType representing the same type
753 * @since 9.5
754 */
755
756 public final boolean equals(Object other) {
757 return other instanceof ItemType && getUnderlyingItemType().equals(((ItemType) other).getUnderlyingItemType());
758 }
759
760 /**
761 * Get a hash code with semantics corresponding to the equals() method
762 *
763 * @return the hash code
764 * @since 9.5
765 */
766
767 public final int hashCode() {
768 return getUnderlyingItemType().hashCode();
769 }
770
771 /**
772 * Get a string representation of the type. This will be a string that conforms to the
773 * XPath ItemType production, for example a QName (always in "Q{uri}local" format, or a construct
774 * such as "node()" or "map(*)". If the type is an anonymous schema type, the name of the nearest
775 * named base type will be given, preceded by the character "&lt;".
776 *
777 * @return a string representation of the type
778 * @since 9.7
779 */
780
781 public String toString() {
782 net.sf.saxon.type.ItemType type = getUnderlyingItemType();
783 if (type instanceof SchemaType) {
784 String marker = "";
785 SchemaType st = (SchemaType) type;
786 StructuredQName name = null;
787 while (true) {
788 name = st.getStructuredQName();
789 if (name != null) {
790 return marker + name.getEQName();
791 } else {
792 marker = "<";
793 st = st.getBaseType();
794 if (st == null) {
795 return "Q{" + NamespaceConstant.SCHEMA + "}anyType";
796 }
797 }
798 }
799 } else {
800 return type.toString();
801 }
802 }
803
804
805 }
806