Project

Profile

Help

How to connect?
Download (38.1 KB) Statistics
| Branch: | Tag: | Revision:

he / latest9.9 / hen / csource / api / Saxon.Api / Types.cs @ a2e6e9df

1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Xml;
5
using JType = net.sf.saxon.type.Type;
6
using JXdmItemType = net.sf.saxon.s9api.ItemType;
7
using JItemTypeType = net.sf.saxon.type.ItemType;
8
using JAnyItemType = net.sf.saxon.type.AnyItemType;
9
using JAtomicType = net.sf.saxon.type.AtomicType;
10
using JAnyMapType = net.sf.saxon.ma.map.MapType;
11
using JAnyArrayType = net.sf.saxon.ma.arrays.ArrayItemType;
12
using JNodeTest = net.sf.saxon.pattern.NodeTest;
13
using JAnyNodeType = net.sf.saxon.pattern.AnyNodeTest;
14
using JErrorType = net.sf.saxon.type.ErrorType;
15
using JFunctionItemType = net.sf.saxon.type.FunctionItemType;
16
using JNodeKindTest = net.sf.saxon.pattern.NodeKindTest;
17
using JSequenceType = net.sf.saxon.value.SequenceType;
18
using JXdmSequenceType = net.sf.saxon.s9api.SequenceType;
19
using JStandardNames = net.sf.saxon.om.StandardNames;
20
using JStructuredQName = net.sf.saxon.om.StructuredQName;
21
using JStaticProperty = net.sf.saxon.expr.StaticProperty;
22
using JConversionRules = net.sf.saxon.lib.ConversionRules;
23
using JOccurrenceIndicator = net.sf.saxon.s9api.OccurrenceIndicator;
24

    
25
namespace Saxon.Api
26
{
27
    /// <summary>
28
    /// Abstract class representing an item type. This may be the generic item type <c>item()</c>,
29
    /// an atomic type, the generic node type <code>node()</code>, a specific node kind such as
30
    /// <c>element()</c> or <c>text()</c>, or the generic function type <code>function()</code>.
31
    /// </summary>
32
    /// <remarks>
33
	/// More specific node types (such as <c>element(E)</c> or <c>schema-element(E)</c>) cannot currently
34
    /// be instantiated in this API.
35
    /// </remarks>
36

    
37
    public abstract class XdmItemType
38
    {
39
        protected JXdmItemType type;
40

    
41
        private JConversionRules defaultConversionRules = new JConversionRules();
42

    
43
        internal static XdmItemType MakeXdmItemType(JItemTypeType type)
44
        {
45
            
46
            if (type is JAtomicType)
47
            {
48
                XdmAtomicType itype = XdmAtomicType.BuiltInAtomicType(QName.FromStructuredQName(((JAtomicType)type).getStructuredQName()));
49
               
50
                return itype;
51
            }
52
            else if (type is JErrorType)
53
            {
54
                return XdmAnyNodeType.Instance;  // TODO: need to represent this properly
55
            }
56
            else if (type is JNodeTest)
57
            {
58
                if (type is JAnyNodeType)
59
                {
60
                    return XdmAnyNodeType.Instance;
61
                }
62
                else
63
                {
64
                    int kind = ((JNodeTest)type).getPrimitiveType();
65
                    return XdmNodeKind.ForNodeKindTest((JNodeKindTest)JNodeKindTest.makeNodeKindTest(kind));
66
                }
67
            }
68
            else if (type is JAnyMapType) {
69
                return XdmAnyMapType.Instance;
70
            }
71
            else if (type is JAnyArrayType)
72
            {
73
                return XdmAnyArrayType.Instance;
74
            }
75
            else if (type is JAnyItemType)
76
            {
77
                return XdmAnyItemType.Instance;
78
            }
79
            else if (type is JFunctionItemType)
80
            {
81
                return XdmAnyFunctionType.Instance;
82
            }
83
            else
84
            {
85
                return null;
86
            }
87
        }
88

    
89
        internal JXdmItemType Unwrap() {
90
            return type;
91
        }
92

    
93
        internal void SetJXdmItemType(JXdmItemType type) {
94
            this.type = type;
95
        }
96

    
97

    
98
        /// <summary>
99
        /// Determine whether this item type matches a given item.
100
        /// </summary>
101
        /// <param name="item">the item to be tested against this item type</param>
102
        /// <returns>true if the item matches this item type, false if it does not match.</returns>
103
        virtual public bool Matches(XdmItem item) {
104
            return type.matches((net.sf.saxon.s9api.XdmItem)XdmValue.FromGroundedValueToJXdmValue(item.value));
105
        }
106

    
107
        /// <summary>
108
        /// Determine whether this ItemType subsumes another ItemType. Specifically,
109
        /// <code>A.subsumes(B)</code> is true if every value that matches the ItemType B also matches
110
        /// the ItemType A.
111
        /// </summary>
112
		/// <param name="other">the other ItemType</param>
113
        /// <returns>true if this ItemType subsumes the other ItemType. This includes the case where A and B
114
        ///         represent the same ItemType.</returns>
115
        virtual public bool Subsumes(XdmItemType other) {
116
            return type.subsumes(other.type);
117
        }
118

    
119

    
120
        /// <summary>
121
        /// Get a string representation of the type. This will be a string that confirms to
122
        /// XPath ItemType production, for example a QName (always in 'Q{uri}local' format, or a
123
        /// construct such as 'node()' or 'map(*)'). If the type is an anonymous schema type, the 
124
        /// name of the nearest named base type will be given, preceded by the character '&lt;'
125
        /// </summary>
126
        /// <returns>a string representation of the type</returns>
127
        public override String ToString() {
128
            return type.toString();
129
        }
130

    
131

    
132
    }
133

    
134
    
135

    
136
    /// <summary>
137
    /// Singleton class representing the item type <c>item()</c>, which matches any item.
138
    /// </summary>
139

    
140
    public class XdmAnyItemType : XdmItemType
141
	{
142

    
143
		/// <summary>
144
		/// The singleton instance of this class: an <c>XdmItemType</c> corresponding to the
145
		/// item type <c>item()</c>, which matches any item.
146
		/// </summary>
147

    
148
		public static XdmAnyItemType Instance = new XdmAnyItemType();
149

    
150
		internal XdmAnyItemType()
151
		{
152
			this.type = JXdmItemType.ANY_ITEM;
153
		}
154

    
155
        /// <summary>
156
        /// Determine whether this item type matches a given item.
157
        /// </summary>
158
        /// <param name="item">the item to be tested against this item type</param>
159
        /// <returns>true if the item matches this item type, false if it does not match.</returns>
160
        public override bool Matches(XdmItem item)
161
        {
162
            return true;
163
        }
164

    
165
        /// <summary>
166
        /// Determine whether this ItemType subsumes another ItemType. Specifically,
167
        /// <code>A.subsumes(B)</code> is true if every value that matches the ItemType B also matches
168
        /// the ItemType A.
169
        /// </summary>
170
		/// <param name="other">the other ItemType</param>
171
        /// <returns>true if this ItemType subsumes the other ItemType. This includes the case where A and B
172
        ///         represent the same ItemType.</returns>
173
		public override bool Subsumes(XdmItemType other)
174
        {
175
            return true;
176
        }
177
    }
178

    
179
	/// <summary>
180
	/// Singleton class representing the item type <c>map(*)</c>, which matches any map.
181
	/// </summary>
182

    
183
    public class XdmAnyMapType : XdmItemType
184
    {
185

    
186

    
187
        /// <summary>
188
        /// The singleton instance of this class: an <c>XdmMapType</c> corresponding to the
189
        /// item type <c>map(*)</c>, which matches any map.
190
        /// </summary>
191

    
192
        public static XdmAnyMapType Instance = new XdmAnyMapType();
193

    
194
        internal XdmAnyMapType()
195
        {
196
            this.type = JXdmItemType.ANY_MAP;
197
        }
198

    
199

    
200

    
201
	}
202

    
203
	/// <summary>
204
	/// Singleton class representing the item type <c>array(*)</c>, which matches any array.
205
	/// </summary>
206

    
207
    public class XdmAnyArrayType : XdmItemType
208
    {
209

    
210

    
211
        /// <summary>
212
        /// The singleton instance of this class: an <c>XdmArrayType</c> corresponding to the
213
        /// item type <c>array(*)</c>, which matches any array.
214
        /// </summary>
215

    
216
        public static XdmAnyArrayType Instance = new XdmAnyArrayType();
217

    
218
        internal XdmAnyArrayType()
219
        {
220
            this.type = JXdmItemType.ANY_ARRAY;
221
        }
222

    
223

    
224
    }
225

    
226
    /// <summary>
227
    /// Singleton class representing the item type <c>node()</c>, which matches any node.
228
    /// </summary>
229

    
230
    public class XdmAnyNodeType : XdmItemType
231
	{
232

    
233
		/// <summary>
234
		/// The singleton instance of this class: an <c>XdmItemType</c> corresponding to the
235
		/// item type <c>node()</c>, which matches any node.
236
		/// </summary>
237

    
238
		public static XdmAnyNodeType Instance = new XdmAnyNodeType();
239

    
240
		internal XdmAnyNodeType()
241
		{
242
			this.type = JXdmItemType.ANY_NODE;
243
		}
244

    
245
        /// <summary>
246
        /// Determine whether this item type matches a given item.
247
        /// </summary>
248
        /// <param name="item">the item to be tested against this item type</param>
249
        /// <returns>true if the item matches this item type, false if it does not match.</returns>
250
        public override bool Matches(XdmItem item)
251
        {
252
            return ((net.sf.saxon.om.Item)item.value) is net.sf.saxon.om.NodeInfo;
253
        }
254

    
255
        /// <summary>
256
        ///  Determine whether this ItemType subsumes another ItemType. Specifically,
257
        /// <code>A.subsumes(B)</code> is true if every value that matches the ItemType B also matches
258
        /// the ItemType A.
259
        /// </summary>
260
		/// <param name="other">the other ItemType</param>
261
        /// <returns>true if this ItemType subsumes the other ItemType. This includes the case where A and B
262
        ///         represent the same ItemType.</returns>
263
        public override bool Subsumes(XdmItemType other)
264
        {
265
            return true;
266
        }
267
    }
268

    
269

    
270
	/// <summary>
271
	/// Singleton class representing the item type <c>function(*)</c>, which matches any function item.
272
	/// </summary>
273

    
274
	public class XdmAnyFunctionType : XdmItemType
275
	{
276

    
277
		/// <summary>
278
		/// The singleton instance of this class: an <c>XdmItemType</c> corresponding to the
279
		/// item type <c>function(*)</c>, which matches any function item.
280
		/// </summary>
281

    
282
		public static XdmAnyFunctionType Instance = new XdmAnyFunctionType();
283

    
284
		internal XdmAnyFunctionType()
285
		{
286
			this.type = JXdmItemType.ANY_FUNCTION;
287
		}
288

    
289

    
290
    }
291

    
292
	/// <summary>
293
	/// An instance of class <c>XdmAtomicType</c> represents a specific atomic type, for example
294
	/// <c>xs:double</c>, <c>xs:integer</c>, or <c>xs:anyAtomicType</c>. This may be either a built-in
295
	/// atomic type or a type defined in a user-written schema.
296
	/// </summary>
297
	/// <remarks>
298
	/// To get an <c>XdmAtomicType</c> instance representing a built-in atomic type, use one of the predefined instances
299
	/// of the subclass <c>XdmBuiltInAtomicType</c>. To get an <c>XdmAtomicType</c> instance representing a user-defined
300
	/// atomic type (defined in a schema), use the method <c>GetAtomicType</c> defined on the <c>SchemaManager</c> class.
301
	/// </remarks>
302

    
303
	public class XdmAtomicType : XdmItemType
304
	{
305

    
306
        /// <summary>
307
		/// Instance object of the <c>XdmAtomicType</c> class
308
        /// </summary>
309
        public static XdmAtomicType Instance = new XdmAtomicType(JXdmItemType.ANY_ATOMIC_VALUE);
310

    
311
        internal XdmAtomicType(JXdmItemType type)
312
        {
313
            this.type = type;
314
        }
315

    
316
        /// <summary>
317
        ///  ItemType representing the built-in (but non-primitive) type xs:short
318
        /// </summary>
319
        public static XdmAtomicType SHORT = BuiltInAtomicType(JStandardNames.XS_SHORT);
320

    
321

    
322
        /// <summary>
323
        /// ItemType representing the primitive type xs:string
324
        /// </summary>
325
        public static XdmAtomicType STRING = BuiltInAtomicType(JStandardNames.XS_STRING);
326

    
327
        /// <summary>
328
        /// ItemType representing the primitive type xs:boolean
329
        /// </summary>
330
        public static XdmAtomicType BOOLEAN = BuiltInAtomicType(JStandardNames.XS_BOOLEAN);
331

    
332
        /// <summary>
333
        /// ItemType representing the primitive type xs:duration
334
        /// </summary>
335

    
336
        public static XdmAtomicType DURATION = BuiltInAtomicType(JStandardNames.XS_DURATION);
337

    
338
        /// <summary>
339
        /// ItemType representing the primitive type xs:dateTime
340
        /// </summary>
341

    
342
        public static XdmAtomicType DATE_TIME = BuiltInAtomicType(JStandardNames.XS_DATE_TIME);
343

    
344
        /// <summary>
345
        /// ItemType representing the primitive type xs:date
346
        /// </summary>
347

    
348
        public static XdmAtomicType DATE = BuiltInAtomicType(JStandardNames.XS_DATE);
349

    
350
        /// <summary>
351
        /// ItemType representing the primitive type xs:time
352
        /// </summary>
353

    
354
        public static XdmAtomicType TIME = BuiltInAtomicType(JStandardNames.XS_TIME);
355

    
356
        /// <summary>
357
        /// ItemType representing the primitive type xs:gYearMonth
358
        /// </summary>
359

    
360
        public static XdmAtomicType G_YEAR_MONTH = BuiltInAtomicType(JStandardNames.XS_G_YEAR_MONTH);
361

    
362
        /// <summary>
363
        ///  ItemType representing the primitive type xs:gMonth
364
        /// </summary>
365

    
366
        public static XdmAtomicType G_MONTH = BuiltInAtomicType(JStandardNames.XS_G_MONTH);
367

    
368
        /// <summary>
369
        /// ItemType representing the primitive type xs:gMonthDay
370
        /// </summary>
371

    
372
        public static XdmAtomicType G_MONTH_DAY = BuiltInAtomicType(JStandardNames.XS_G_MONTH_DAY);
373

    
374
        /// <summary>
375
        /// ItemType representing the primitive type xs:gYear
376
        /// </summary>
377

    
378
        public static XdmAtomicType G_YEAR = BuiltInAtomicType(JStandardNames.XS_G_YEAR);
379

    
380
        /// <summary>
381
        /// ItemType representing the primitive type xs:gDay
382
        /// </summary>
383

    
384
        public static XdmAtomicType G_DAY = BuiltInAtomicType(JStandardNames.XS_G_DAY);
385

    
386
        /// <summary>
387
        /// ItemType representing the primitive type xs:hexBinary
388
        /// </summary>
389

    
390
        public static XdmAtomicType HEX_BINARY = BuiltInAtomicType(JStandardNames.XS_HEX_BINARY);
391

    
392
        /// <summary>
393
        ///  ItemType representing the primitive type xs:base64Binary
394
        /// </summary>
395

    
396
        public static XdmAtomicType BASE64_BINARY = BuiltInAtomicType(JStandardNames.XS_BASE64_BINARY);
397

    
398
        /// <summary>
399
        /// ItemType representing the primitive type xs:anyURI
400
        /// </summary>
401

    
402
        public static XdmAtomicType ANY_URI = BuiltInAtomicType(JStandardNames.XS_ANY_URI);
403

    
404
        /// <summary>
405
        /// ItemType representing the primitive type xs:QName
406
        /// </summary>
407

    
408
        public static XdmAtomicType QNAME = BuiltInAtomicType(JStandardNames.XS_QNAME);
409

    
410
        /// <summary>
411
        /// ItemType representing the primitive type xs:NOTATION
412
        /// </summary>
413

    
414
        public static XdmAtomicType NOTATION = BuiltInAtomicType(JStandardNames.XS_NOTATION);
415

    
416
        /// <summary>
417
        ///  ItemType representing the XPath-defined type xs:untypedAtomic
418
        /// </summary>
419

    
420
        public static XdmAtomicType UNTYPED_ATOMIC = BuiltInAtomicType(JStandardNames.XS_UNTYPED_ATOMIC);
421

    
422
        /// <summary>
423
        /// ItemType representing the primitive type xs:decimal
424
        /// </summary>
425

    
426
        public static XdmAtomicType DECIMAL = BuiltInAtomicType(JStandardNames.XS_DECIMAL);
427

    
428
        /// <summary>
429
        /// ItemType representing the primitive type xs:float
430
        /// </summary>
431

    
432
        public static XdmAtomicType FLOAT = BuiltInAtomicType(JStandardNames.XS_FLOAT);
433

    
434
        /// <summary>
435
        /// ItemType representing the primitive type xs:double
436
        /// </summary>
437

    
438
        public static XdmAtomicType DOUBLE = BuiltInAtomicType(JStandardNames.XS_DOUBLE);
439

    
440
        /// <summary>
441
        /// ItemType representing the built-in (but non-primitive) type xs:integer
442
        /// </summary>
443

    
444
        public static XdmAtomicType INTEGER = BuiltInAtomicType(JStandardNames.XS_INTEGER);
445

    
446
        /// <summary>
447
        /// 
448
        /// </summary>
449

    
450
        public static XdmAtomicType NON_POSITIVE_INTEGER = BuiltInAtomicType(JStandardNames.XS_NON_POSITIVE_INTEGER);
451

    
452
        /// <summary>
453
        /// ItemType representing the built-in (but non-primitive) type xs:negativeInteger
454
        /// </summary>
455

    
456
        public static XdmAtomicType NEGATIVE_INTEGER = BuiltInAtomicType(JStandardNames.XS_NEGATIVE_INTEGER);
457

    
458
        /// <summary>
459
        /// ItemType representing the built-in (but non-primitive) type xs:long
460
        /// </summary>
461

    
462
        public static XdmAtomicType LONG = BuiltInAtomicType(JStandardNames.XS_LONG);
463

    
464
        /// <summary>
465
        /// ItemType representing the built-in (but non-primitive) type xs:int
466
        /// </summary>
467

    
468
        public static XdmAtomicType INT = BuiltInAtomicType(JStandardNames.XS_INT);
469

    
470

    
471
        /// <summary>
472
        /// ItemType representing the built-in (but non-primitive) type xs:byte
473
        /// </summary>
474

    
475
        public static XdmAtomicType BYTE = BuiltInAtomicType(JStandardNames.XS_BYTE);
476

    
477
        /// <summary>
478
        /// ItemType representing the built-in (but non-primitive) type xs:nonNegativeInteger
479
        /// </summary>
480

    
481
        public static XdmAtomicType NON_NEGATIVE_INTEGER = BuiltInAtomicType(JStandardNames.XS_NON_NEGATIVE_INTEGER);
482

    
483
        /// <summary>
484
        /// ItemType representing the built-in (but non-primitive) type xs:positiveInteger
485
        /// </summary>
486

    
487
        public static XdmAtomicType POSITIVE_INTEGER = BuiltInAtomicType(JStandardNames.XS_POSITIVE_INTEGER);
488

    
489
        /// <summary>
490
        /// ItemType representing the built-in (but non-primitive) type xs:unsignedLong
491
        /// </summary>
492

    
493
        public static XdmAtomicType UNSIGNED_LONG = BuiltInAtomicType(JStandardNames.XS_UNSIGNED_LONG);
494

    
495
        /// <summary>
496
        /// ItemType representing the built-in (but non-primitive) type xs:unsignedInt
497
        /// </summary>
498

    
499
        public static XdmAtomicType UNSIGNED_INT = BuiltInAtomicType(JStandardNames.XS_UNSIGNED_INT);
500

    
501
        /// <summary>
502
        /// ItemType representing the built-in (but non-primitive) type xs:unsignedShort
503
        /// </summary>
504

    
505
        public static XdmAtomicType UNSIGNED_SHORT = BuiltInAtomicType(JStandardNames.XS_UNSIGNED_SHORT);
506

    
507
        /// <summary>
508
        /// ItemType representing the built-in (but non-primitive) type xs:unsignedByte
509
        /// </summary>
510

    
511
        public static XdmAtomicType UNSIGNED_BYTE = BuiltInAtomicType(JStandardNames.XS_UNSIGNED_BYTE);
512

    
513
        /// <summary>
514
        /// ItemType representing the built-in (but non-primitive) type xs:yearMonthDuration
515
        /// </summary>
516

    
517
        public static XdmAtomicType YEAR_MONTH_DURATION = BuiltInAtomicType(JStandardNames.XS_YEAR_MONTH_DURATION);
518

    
519
        /// <summary>
520
        /// ItemType representing the built-in (but non-primitive) type xs:dayTimeDuration
521
        /// </summary>
522

    
523
        public static XdmAtomicType DAY_TIME_DURATION = BuiltInAtomicType(JStandardNames.XS_DAY_TIME_DURATION);
524

    
525
        /// <summary>
526
        /// ItemType representing the built-in (but non-primitive) type xs:normalizedString
527
        /// </summary>
528

    
529
        public static XdmAtomicType NORMALIZED_STRING = BuiltInAtomicType(JStandardNames.XS_NORMALIZED_STRING);
530

    
531
        /// <summary>
532
        /// ItemType representing the built-in (but non-primitive) type xs:token
533
        /// </summary>
534

    
535
        public static XdmAtomicType TOKEN = BuiltInAtomicType(JStandardNames.XS_TOKEN);
536

    
537
        /// <summary>
538
        /// ItemType representing the built-in (but non-primitive) type xs:language
539
        /// </summary>
540

    
541
        public static XdmAtomicType LANGUAGE = BuiltInAtomicType(JStandardNames.XS_LANGUAGE);
542

    
543
        /// <summary>
544
        /// ItemType representing the built-in (but non-primitive) type xs:Name
545
        /// </summary>
546

    
547
        public static XdmAtomicType NAME = BuiltInAtomicType(JStandardNames.XS_NAME);
548

    
549
        /// <summary>
550
        /// ItemType representing the built-in (but non-primitive) type xs:NMTOKEN
551
        /// </summary>
552

    
553
        public static XdmAtomicType NMTOKEN = BuiltInAtomicType(JStandardNames.XS_NMTOKEN);
554

    
555
        /// <summary>
556
        /// ItemType representing the built-in (but non-primitive) type xs:NCName
557
        /// </summary>
558

    
559
        public static XdmAtomicType NCNAME = BuiltInAtomicType(JStandardNames.XS_NCNAME);
560

    
561
        /// <summary>
562
        /// ItemType representing the built-in (but non-primitive) type xs:ID
563
        /// </summary>
564

    
565
        public static XdmAtomicType ID = BuiltInAtomicType(JStandardNames.XS_ID);
566

    
567
        /// <summary>
568
        /// ItemType representing the built-in (but non-primitive) type xs:IDREF
569
        /// </summary>
570

    
571
        public static XdmAtomicType IDREF = BuiltInAtomicType(JStandardNames.XS_IDREF);
572

    
573
        /// <summary>
574
        /// ItemType representing the built-in (but non-primitive) type xs:ENTITY
575
        /// </summary>
576

    
577
        public static XdmAtomicType ENTITY = BuiltInAtomicType(JStandardNames.XS_ENTITY);
578

    
579
        /// <summary>
580
        /// ItemType representing the built-in (but non-primitive) type xs:dateTimeStamp
581
        /// (introduced in XSD 1.1)
582
        /// </summary>
583

    
584
        public static XdmAtomicType DATE_TIME_STAMP = BuiltInAtomicType(JStandardNames.XS_DATE_TIME_STAMP);
585

    
586

    
587
        /// <summary>
588
        /// Get an <c>XdmAtomicType</c> object representing a built-in atomic type with a given name.
589
        /// </summary>
590
        /// <param name="name">The name of the required built-in atomic type</param>
591
        /// <returns>An <c>XdmAtomicType</c> object representing the built-in atomic type with the supplied name.
592
        /// Returns null if there is no built-in atomic type with this name.
593
        /// It is undefined whether two requests for the same built-in type will return the same object.</returns>
594

    
595

    
596
        public static XdmAtomicType BuiltInAtomicType(QName name) {
597
            int fingerprint = JStandardNames.getFingerprint(name.Uri, name.LocalName);
598
            return BuiltInAtomicType(fingerprint);
599
        }
600

    
601
        internal static XdmAtomicType BuiltInAtomicType(int fingerprint)
602
		{
603

    
604
			if (fingerprint == -1)
605
			{
606
				return null;
607
			}
608
            switch (fingerprint) {
609
                case JStandardNames.XS_ANY_ATOMIC_TYPE:
610
                    return XdmAtomicType.Instance;
611

    
612
                case JStandardNames.XS_STRING:
613
                    return new XdmAtomicType(JXdmItemType.STRING);
614

    
615
                case JStandardNames.XS_BOOLEAN:
616
                    return new XdmAtomicType(JXdmItemType.BOOLEAN);
617

    
618
                case JStandardNames.XS_DURATION:
619
                    return new XdmAtomicType(JXdmItemType.DURATION);
620

    
621
                case JStandardNames.XS_DATE_TIME:
622
                    return new XdmAtomicType(JXdmItemType.DATE_TIME);
623

    
624
                case JStandardNames.XS_DATE:
625
                    return new XdmAtomicType(JXdmItemType.DATE);
626

    
627
                case JStandardNames.XS_TIME:
628
                    return new XdmAtomicType(JXdmItemType.TIME);
629

    
630
                case JStandardNames.XS_G_YEAR_MONTH:
631
                    return new XdmAtomicType(JXdmItemType.G_YEAR_MONTH);
632

    
633
                case JStandardNames.XS_G_MONTH:
634
                    return new XdmAtomicType(JXdmItemType.G_MONTH);
635

    
636
                case JStandardNames.XS_G_MONTH_DAY:
637
                    return new XdmAtomicType(JXdmItemType.G_MONTH_DAY);
638

    
639
                case JStandardNames.XS_G_YEAR:
640
                    return new XdmAtomicType(JXdmItemType.G_YEAR);
641

    
642
                case JStandardNames.XS_G_DAY:
643
                    return new XdmAtomicType(JXdmItemType.G_DAY);
644

    
645
                case JStandardNames.XS_HEX_BINARY:
646
                    return new XdmAtomicType(JXdmItemType.HEX_BINARY);
647

    
648
                case JStandardNames.XS_BASE64_BINARY:
649
                    return new XdmAtomicType(JXdmItemType.BASE64_BINARY);
650

    
651
                case JStandardNames.XS_ANY_URI:
652
                    return new XdmAtomicType(JXdmItemType.ANY_URI);
653

    
654
                case JStandardNames.XS_QNAME:
655
                    return new XdmAtomicType(JXdmItemType.QNAME);
656

    
657
                case JStandardNames.XS_NOTATION:
658
                    return new XdmAtomicType(JXdmItemType.NOTATION);
659

    
660
                case JStandardNames.XS_UNTYPED_ATOMIC:
661
                    return new XdmAtomicType(JXdmItemType.UNTYPED_ATOMIC);
662

    
663
                case JStandardNames.XS_DECIMAL:
664
                    return new XdmAtomicType(JXdmItemType.DECIMAL);
665

    
666
                case JStandardNames.XS_FLOAT:
667
                    return new XdmAtomicType(JXdmItemType.FLOAT);
668

    
669
                case JStandardNames.XS_DOUBLE:
670
                    return new XdmAtomicType(JXdmItemType.DOUBLE);
671

    
672
                case JStandardNames.XS_INTEGER:
673
                    return new XdmAtomicType(JXdmItemType.INTEGER);
674

    
675
                case JStandardNames.XS_NON_POSITIVE_INTEGER:
676
                    return new XdmAtomicType(JXdmItemType.NON_POSITIVE_INTEGER);
677

    
678
                case JStandardNames.XS_NEGATIVE_INTEGER:
679
                    return new XdmAtomicType(JXdmItemType.NEGATIVE_INTEGER);
680

    
681
                case JStandardNames.XS_LONG:
682
                    return new XdmAtomicType(JXdmItemType.LONG);
683

    
684
                case JStandardNames.XS_INT:
685
                    return new XdmAtomicType(JXdmItemType.INT);
686

    
687
                case JStandardNames.XS_SHORT:
688
                    return new XdmAtomicType(JXdmItemType.SHORT);
689

    
690
                case JStandardNames.XS_BYTE:
691
                    return new XdmAtomicType(JXdmItemType.BYTE);
692

    
693
                case JStandardNames.XS_NON_NEGATIVE_INTEGER:
694
                    return new XdmAtomicType(JXdmItemType.NON_NEGATIVE_INTEGER);
695

    
696
                case JStandardNames.XS_POSITIVE_INTEGER:
697
                    return new XdmAtomicType(JXdmItemType.POSITIVE_INTEGER);
698

    
699
                case JStandardNames.XS_UNSIGNED_LONG:
700
                    return new XdmAtomicType(JXdmItemType.UNSIGNED_LONG);
701

    
702
                case JStandardNames.XS_UNSIGNED_INT:
703
                    return new XdmAtomicType(JXdmItemType.UNSIGNED_INT);
704

    
705
                case JStandardNames.XS_UNSIGNED_SHORT:
706
                    return new XdmAtomicType(JXdmItemType.UNSIGNED_SHORT);
707

    
708
                case JStandardNames.XS_UNSIGNED_BYTE:
709
                    return new XdmAtomicType(JXdmItemType.UNSIGNED_BYTE);
710

    
711
                case JStandardNames.XS_YEAR_MONTH_DURATION:
712
                    return new XdmAtomicType(JXdmItemType.YEAR_MONTH_DURATION);
713

    
714
                case JStandardNames.XS_DAY_TIME_DURATION:
715
                    return new XdmAtomicType(JXdmItemType.DAY_TIME_DURATION);
716

    
717
                case JStandardNames.XS_NORMALIZED_STRING:
718
                    return new XdmAtomicType(JXdmItemType.NORMALIZED_STRING);
719

    
720
                case JStandardNames.XS_TOKEN:
721
                    return new XdmAtomicType(JXdmItemType.TOKEN);
722

    
723
                case JStandardNames.XS_LANGUAGE:
724
                    return new XdmAtomicType(JXdmItemType.LANGUAGE);
725

    
726
                case JStandardNames.XS_NAME:
727
                    return new XdmAtomicType(JXdmItemType.NAME);
728

    
729
                case JStandardNames.XS_NMTOKEN:
730
                    return new XdmAtomicType(JXdmItemType.NMTOKEN);
731

    
732
                case JStandardNames.XS_NCNAME:
733
                    return new XdmAtomicType(JXdmItemType.NCNAME);
734

    
735
                case JStandardNames.XS_ID:
736
                    return new XdmAtomicType(JXdmItemType.ID);
737

    
738
                case JStandardNames.XS_IDREF:
739
                    return new XdmAtomicType(JXdmItemType.IDREF);
740

    
741
                case JStandardNames.XS_ENTITY:
742
                    return new XdmAtomicType(JXdmItemType.ENTITY);
743

    
744
                case JStandardNames.XS_DATE_TIME_STAMP:
745
                    return new XdmAtomicType(JXdmItemType.DATE_TIME_STAMP);
746

    
747

    
748
                case JStandardNames.XS_ERROR:
749
                    return null;
750

    
751
                default:
752
                    throw new StaticError(new net.sf.saxon.s9api.SaxonApiException("Unknown atomic type " + JStandardNames.getClarkName(fingerprint)));
753

    
754

    
755
            }
756
            
757
		}
758

    
759
    
760

    
761
        /// <summary>
762
        /// The name of the atomic type, or null if the type is anonymous.
763
        /// </summary>
764

    
765
        public QName Name
766
		{
767
			get
768
			{
769
				JStructuredQName jQName = ((JAtomicType)type).getTypeName();
770
				if (jQName == null)
771
				{
772
					return null;
773
				}
774
				return new QName(jQName.getPrefix(), jQName.getURI(), jQName.getLocalPart());
775

    
776

    
777
            }
778
		}
779

    
780
        /// <summary>
781
        /// Determine whether this item type matches a given item
782
        /// </summary>
783
        /// <param name="item">the item to be tested against this item type</param>
784
        /// <returns>true if the item matches this item type, false if it does not match</returns>
785
        public override bool Matches(XdmItem item)
786
        {
787
            return type.matches(XdmItem.FromXdmItemItemToJXdmItem(item));
788
        }
789

    
790

    
791
        /// <summary>
792
        /// Determine whether this ItemType subsumes another ItemType. Specifically
793
        /// <code>A.Sumsumes(B)</code> is true if every value that matches the ItemType B also
794
        /// matches the ItemType A.
795
        /// </summary>
796
        /// <param name="other">the other ItemType</param>
797
        /// <returns>true if this ItemType subsumes the other ItemType. This includes the case where A and B
798
        /// represent the same ItemType.</returns>
799
        public override bool Subsumes(XdmItemType other)
800
        {
801
            return type.subsumes(other.Unwrap());
802
        }
803
    }
804

    
805
	/// <summary>
806
	/// Instances of <c>XdmNodeKind</c> represent the item types denoted in XPath as <c>document-node()</c>,
807
	/// <c>element()</c>, <c>attribute()</c>, <c>text()</c>, and so on. These are all represented by singular named instances.
808
	/// </summary>
809

    
810
	public class XdmNodeKind : XdmItemType
811
	{
812

    
813
        //public static XdmNodeKind Instance = new XdmNodeKind();
814
        private JNodeKindTest nodekind;
815
        private int kind;
816

    
817
        internal XdmNodeKind(JNodeKindTest test, JXdmItemType type)
818
		{
819
			nodekind = test;
820
            this.type = type;
821
            kind = test.getNodeKind();
822
        }
823

    
824
		/// <summary>
825
		/// The item type <c>document-node()</c>
826
		/// </summary>
827

    
828
		public static XdmNodeKind Document = new XdmNodeKind(JNodeKindTest.DOCUMENT, JXdmItemType.DOCUMENT_NODE);
829

    
830
		/// <summary>
831
		/// The item type <c>element()</c>
832
		/// </summary>
833

    
834
		public static XdmNodeKind Element = new XdmNodeKind(JNodeKindTest.ELEMENT, JXdmItemType.ELEMENT_NODE);
835

    
836
		/// <summary>
837
		/// The item type <c>attribute()</c>
838
		/// </summary>
839

    
840
		public static XdmNodeKind Attribute = new XdmNodeKind(JNodeKindTest.ATTRIBUTE, JXdmItemType.ATTRIBUTE_NODE);
841

    
842
		/// <summary>
843
		/// The item type <c>text()</c>
844
		/// </summary>
845

    
846
		public static XdmNodeKind Text = new XdmNodeKind(JNodeKindTest.TEXT, JXdmItemType.TEXT_NODE);
847

    
848
		/// <summary>
849
		/// The item type <c>comment()</c>
850
		/// </summary>
851

    
852
		public static XdmNodeKind Comment = new XdmNodeKind(JNodeKindTest.COMMENT, JXdmItemType.COMMENT_NODE);
853

    
854
		/// <summary>
855
		/// The item type <c>processing-instruction()</c>
856
		/// </summary>
857

    
858
		public static XdmNodeKind ProcessingInstruction = new XdmNodeKind(JNodeKindTest.PROCESSING_INSTRUCTION, JXdmItemType.PROCESSING_INSTRUCTION_NODE);
859

    
860
		/// <summary>
861
		/// The item type <c>namespace-node()</c>
862
		/// </summary>
863

    
864
		public static XdmNodeKind Namespace = new XdmNodeKind(JNodeKindTest.NAMESPACE, JXdmItemType.NAMESPACE_NODE);
865

    
866
		internal static XdmNodeKind ForNodeKindTest(JNodeKindTest test)
867
		{
868
			int kind = test.getPrimitiveType();
869
			switch (kind)
870
			{
871
			case JType.DOCUMENT:
872
				return Document;
873
			case JType.ELEMENT:
874
				return Element;
875
			case JType.ATTRIBUTE:
876
				return Attribute;
877
			case JType.TEXT:
878
				return Text;
879
			case JType.COMMENT:
880
				return Comment;
881
			case JType.PROCESSING_INSTRUCTION:
882
				return ProcessingInstruction;
883
			case JType.NAMESPACE:
884
				return Namespace;
885
			default:
886
				throw new ArgumentException("Unknown node kind");
887
			}
888
		}
889

    
890
		/// <summary>
891
		/// Get the item type representing the node kind of a supplied node
892
		/// </summary>
893
		/// <param name="node">The node whose node kind is required</param>
894
		/// <returns>The relevant node kind</returns>
895

    
896
		public static XdmNodeKind ForNode(XdmNode node)
897
		{
898
			return ForNodeType(node.NodeKind);
899
		}
900

    
901
        /// <summary>
902
        /// Determine whether this item type matches a given item.
903
        /// </summary>
904
        /// <param name="item">item the item to be tested against this item type</param>
905
        /// <returns>true if the item matches this item type, false if it does not match.</returns>
906
        public override bool Matches(XdmItem item)
907
        {
908
            return item.Unwrap() is JNodeTest && kind == ((net.sf.saxon.om.NodeInfo)item.Unwrap()).getNodeKind();
909
        }
910

    
911
        /// <summary>
912
        ///  Determine whether this ItemType subsumes another ItemType. Specifically,
913
        /// <code>A.subsumes(B)</code> is true if every value that matches the ItemType B also matches
914
        /// the ItemType A.
915
        /// </summary>
916
		/// <param name="other">the other ItemType</param>
917
        /// <returns>true if this ItemType subsumes the other ItemType. This includes the case where A and B
918
        ///         represent the same ItemType.</returns>
919
        public override bool Subsumes(XdmItemType other)
920
        {
921
            return true;
922
        }
923

    
924
        /// <summary>
925
		/// Get the item type corresponding to an <c>XmlNodeType</c> as defined in the <c>System.Xml</c> package
926
        /// </summary>
927
        /// <param name="type">The <c>XmlNodeType</c> to be converted</param>
928
        /// <returns>The corresponding <c>XdmNodeKind</c></returns>
929

    
930
        public static XdmNodeKind ForNodeType(XmlNodeType type)
931
		{
932
			switch (type)
933
			{
934
			case XmlNodeType.Document:
935
				return Document;
936
			case XmlNodeType.Element:
937
				return Element;
938
			case XmlNodeType.Attribute:
939
				return Attribute;
940
			case XmlNodeType.Text:
941
				return Text;
942
			case XmlNodeType.Comment:
943
				return Comment;
944
			case XmlNodeType.ProcessingInstruction:
945
				return ProcessingInstruction;
946
			default:
947
				throw new ArgumentException("Unknown node kind");
948
			}
949
		}
950
	}
951

    
952
	/// <summary>
953
	/// An instance of class <c>XdmSequenceType</c> represents a sequence type, that is, the combination
954
	/// of an item type and an occurrence indicator.
955
	/// </summary>
956

    
957
	public class XdmSequenceType
958
	{
959

    
960
		internal XdmItemType itemType;
961
		internal char occurrenceIn;
962
        internal int occurrence;
963

    
964
		public const char ZERO_OR_MORE='*';
965
		public const char ONE_OR_MORE = '+';
966
		public const char ZERO_OR_ONE = '?';
967
		public const char ZERO = '0'; //xBA
968
		public const char ONE = ' ';
969

    
970
		/// <summary>
971
		/// Create an <c>XdmSequenceType</c> corresponding to a given <c>XdmItemType</c> and occurrence indicator
972
		/// </summary>
973
		/// <param name="itemType">The item type</param>
974
		/// <param name="occurrenceIndicator">The occurrence indicator, one of '?' (zero-or-one), 
975
		/// '*' (zero-or-more), '+' (one-or-more), ' ' (a single space) (exactly one),
976
		/// or 'º' (masculine ordinal indicator, xBA) (exactly zero). The type <c>empty-sequence()</c>
977
		/// can be represented by an occurrence indicator of 'º' with any item type.</param>
978

    
979
		public XdmSequenceType(XdmItemType itemType, char occurrenceIndicator)
980
		{
981
			int occ;
982
			switch (occurrenceIndicator)
983
			{
984
			case ZERO_OR_MORE:
985
				occ = JStaticProperty.ALLOWS_ZERO_OR_MORE;
986
				break;
987
			case ONE_OR_MORE:
988
				occ = JStaticProperty.ALLOWS_ONE_OR_MORE;
989
				break;
990
			case ZERO_OR_ONE:
991
				occ = JStaticProperty.ALLOWS_ZERO_OR_ONE;
992
				break;
993
			case ONE:
994

    
995
				occ = JStaticProperty.EXACTLY_ONE;
996
				break;
997
			case ZERO:
998
				occ = JStaticProperty.ALLOWS_ZERO;
999
				break;
1000
			default:
1001
				throw new ArgumentException("Unknown occurrence indicator");
1002
			}
1003
			this.itemType = itemType;
1004
            this.occurrence = occ;
1005
            this.occurrenceIn = occurrenceIndicator;
1006
        }
1007

    
1008
		internal static XdmSequenceType FromSequenceType(JSequenceType seqType)
1009
		{
1010
			XdmItemType itemType = XdmItemType.MakeXdmItemType(seqType.getPrimaryType());
1011
			char occ;
1012
			if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO_OR_MORE)
1013
			{
1014
				occ = ZERO_OR_MORE;
1015
			}
1016
			else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ONE_OR_MORE)
1017
			{
1018
				occ = ONE_OR_MORE;
1019
			}
1020
			else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO_OR_ONE)
1021
			{
1022
				occ = ZERO_OR_ONE;
1023
			}
1024
			else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO)
1025
			{
1026
				occ = ZERO;
1027
			}
1028
			else
1029
			{
1030
				occ = ONE;
1031
			}
1032
            if (itemType == null) {
1033
                return null;
1034
            }
1035
			return new XdmSequenceType(itemType, occ);
1036
		}
1037

    
1038
       
1039

    
1040
        internal JSequenceType ToSequenceType() {
1041
            JItemTypeType jit = itemType.Unwrap().getUnderlyingItemType();
1042
			return JSequenceType.makeSequenceType(jit, occurrence);
1043
		}
1044

    
1045
        internal JOccurrenceIndicator GetJOccurrenceIndicator(int cardinality) {
1046
            switch (cardinality) {
1047
                case JStaticProperty.EMPTY:
1048
                    return JOccurrenceIndicator.ZERO;
1049
                case JStaticProperty.ALLOWS_ZERO_OR_ONE:
1050
                    return JOccurrenceIndicator.ZERO_OR_ONE;
1051
                case JStaticProperty.ALLOWS_ZERO_OR_MORE:
1052
                    return JOccurrenceIndicator.ZERO_OR_MORE;
1053
                case JStaticProperty.ALLOWS_ONE:
1054
                    return JOccurrenceIndicator.ONE;
1055
                case JStaticProperty.ALLOWS_ONE_OR_MORE:
1056
                    return JOccurrenceIndicator.ONE_OR_MORE;
1057
                default:
1058
                    return JOccurrenceIndicator.ZERO_OR_MORE;
1059
            }
1060
        }
1061

    
1062
        internal JXdmSequenceType ToJXdmSequenceType()
1063
        {
1064
            JItemTypeType jit = itemType.Unwrap().getUnderlyingItemType();
1065
            return JXdmSequenceType.makeSequenceType(itemType.Unwrap(), GetJOccurrenceIndicator(occurrence));
1066
        }
1067

    
1068

    
1069
    }
1070

    
1071

    
1072
}
1073

    
1074
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1075
// Copyright (c) 2018 Saxonica Limited.
1076
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
1077
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
1078
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
1079
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
(10-10/13)