Project

Profile

Help

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

he / src / main / csharp / api / Saxon.Api / Errors.cs @ 2699858e

1
using System;
2
using System.Collections.Generic;
3
using XPathException = net.sf.saxon.trans.XPathException;
4
using JException = java.lang.Exception;
5
using JErrorReporter = net.sf.saxon.lib.ErrorReporter;
6
using JInvalidityHandler = net.sf.saxon.lib.InvalidityHandler;
7
using JInvalidity = net.sf.saxon.lib.Invalidity;
8
using JValidationFailure = net.sf.saxon.type.ValidationFailure;
9
using JValidationException = net.sf.saxon.type.ValidationException;
10
using JSequence = net.sf.saxon.om.Sequence;
11
using JTransformerException = javax.xml.transform.TransformerException;
12
using JSourceLocator = javax.xml.transform.SourceLocator;
13
using JSaxonApiException = net.sf.saxon.s9api.SaxonApiException;
14
using JXmlProcessingError = net.sf.saxon.s9api.XmlProcessingError;
15

    
16
namespace Saxon.Api
17
{
18

    
19
    /// <summary>
20
	/// The <c>StaticError</c> class contains information about a static error detected during
21
    /// compilation of a stylesheet, query, or XPath expression.
22
    /// </summary>
23

    
24
    [Serializable]
25
    public class StaticError : Exception
26
    {
27

    
28
        private XPathException exception;
29
        internal bool isWarning;
30

    
31
        // internal constructor: Create a new StaticError, wrapping a Saxon XPathException
32

    
33
        internal StaticError(JException err)
34
        {
35
            if (err is XPathException)
36
            {
37
                this.exception = (XPathException)err;
38
            }
39
            else
40
            {
41
                this.exception = XPathException.makeXPathException(err);
42
            }
43
        }
44

    
45
        /// <summary>
46
		/// The error code, as a <c>QName</c>. May be null if no error code has been assigned.
47
        /// </summary>
48

    
49
        public QName ErrorCode
50
        {
51
            get
52
            {
53
                if (exception.getErrorCodeLocalPart() != null) {
54
                    return new QName("err",
55
                        exception.getErrorCodeNamespace(),
56
                        exception.getErrorCodeLocalPart());
57
                } else {
58
                    return null;
59
                }
60
            }
61
        }
62

    
63
        /// <summary>
64
        /// Return the message associated with this error.
65
        /// </summary>
66

    
67
        public override String Message
68
        {
69
            get
70
            {
71
                return exception.getMessage();
72
            }
73
        }
74

    
75

    
76
        /// <summary>
77
        /// Return the message associated with this error concatenated with the message from the causing exception.
78
        /// </summary> 
79
        public String InnerMessage
80
        {
81
            get {
82

    
83
                return exception.getMessage() + ": " + exception.getCause().Message;
84
            }
85

    
86
        }
87

    
88

    
89

    
90

    
91
        /// <summary>
92
        /// The URI of the query or stylesheet module in which the error was detected
93
        /// (as a string).
94
        /// </summary>
95
        /// <remarks>
96
        /// May be null if the location of the error is unknown, or if the error is not
97
        /// localized to a specific module, or if the module in question has no known URI
98
		/// (for example, if it was supplied as an anonymous <c>Stream</c>).
99
        /// </remarks>
100

    
101
        public String ModuleUri
102
        {
103
            get
104
            {
105
                if (exception.getLocator() == null)
106
                {
107
                    return null;
108
                }
109
                return exception.getLocator().getSystemId();
110
            }
111
        }
112

    
113
        /// <summary>
114
        /// The line number locating the error within a query or stylesheet module.
115
        /// </summary>
116
        /// <remarks>
117
        /// May be set to -1 if the location of the error is unknown.
118
        /// </remarks>        
119

    
120
        public int LineNumber
121
        {
122
            get
123
            {
124
                JSourceLocator loc = exception.getLocator();
125
                if (loc == null)
126
                {
127
                    if (exception.getException() is JTransformerException)
128
                    {
129
                        loc = ((JTransformerException)exception.getException()).getLocator();
130
                        if (loc != null)
131
                        {
132
                            return loc.getLineNumber();
133
                        }
134
                    }
135
                    return -1;
136
                }
137
                return loc.getLineNumber();
138
            }
139
        }
140

    
141

    
142
        /// <summary>
143
        /// The line number locating the error within a query or stylesheet module.
144
        /// </summary>
145
        /// <remarks>
146
        /// May be set to -1 if the location of the error is unknown.
147
        /// </remarks>        
148

    
149
        public int ColumnNumber
150
        {
151
            get
152
            {
153
                JSourceLocator loc = exception.getLocator();
154
                if (loc == null)
155
                {
156
                    if (exception.getException() is JTransformerException)
157
                    {
158
                        loc = ((JTransformerException)exception.getException()).getLocator();
159
                        if (loc != null)
160
                        {
161
                            return loc.getColumnNumber();
162
                        }
163
                    }
164
                    return -1;
165
                }
166
                return loc.getColumnNumber();
167
            }
168
        }
169

    
170
        /// <summary>
171
        /// Indicate whether this error is being reported as a warning condition. If so, applications
172
        /// may ignore the condition, though the results may not be as intended.
173
        /// </summary>
174

    
175
        public bool IsWarning
176
        {
177
            get
178
            {
179
                return isWarning;
180
            }
181
            set
182
            {
183
                isWarning = value;
184
            }
185
        }
186

    
187
        /// <summary>
188
        /// Indicate whether this condition is a type error.
189
        /// </summary>
190

    
191
        public bool IsTypeError
192
        {
193
            get
194
            {
195
                return exception.isTypeError();
196
            }
197
        }
198

    
199
        /// <summary>
200
        /// Return the underlying exception. This is unstable as this is an internal object.
201
        /// </summary>
202
		/// <returns>The underlying <c>XPathException</c></returns>
203
        
204
		public XPathException UnderlyingException
205
        {
206
            get
207
            {
208
                return exception;
209
            }
210
        }
211

    
212
        /// <summary>
213
        /// Return the error message.
214
        /// </summary>
215

    
216
        public override String ToString()
217
        {
218
            return exception.getMessage();
219
        }
220
    }
221

    
222

    
223
    /// <summary>
224
	/// The <c>IErrorReporter</c> is a generic functional interface for reporting errors and warnings.
225
    /// </summary>
226
    /// <remarks>
227
    /// <p>The error or warning is reported in the form of an <c>XmlProcessingError</c> which
228
    /// adds the possibility to report errors without expensive construction of an exception object.</p>
229
    /// </remarks>
230
    public interface IErrorReporter {
231

    
232

    
233

    
234
        /// <summary>
235
        /// Report an error. This method is called by Saxon when an error needs to be reported to the calling application.
236
        /// </summary>
237
        /// <param name="error">Details of the error to be reported</param>
238
        /**public**/
239
        void report(XmlProcessingError error);
240

    
241
    }
242

    
243

    
244
    /// <summary>
245
	/// <c>ErrorReporter</c> wrapper class for internal use in Saxon.
246
    /// </summary>
247
	public class ErrorReporterWrapper : JErrorReporter
248

    
249
    {
250

    
251
        private IErrorReporter reporter;
252

    
253
        /// <summary>
254
		/// Create a standard <c>ErrorReporter</c>
255
        /// </summary>
256
		/// <param name="reporter">The .NET <c>IErrorReporter</c></param>
257
        public ErrorReporterWrapper(IErrorReporter reporter)
258
        {
259
            this.reporter = reporter;
260
        }
261

    
262
        public IErrorReporter ErrorReporter {
263
            get { return reporter; }
264
        }
265

    
266

    
267
        public void report(JXmlProcessingError xpe)
268
        {
269
            reporter.report(new XmlProcessingError(xpe));
270
        }
271
    }
272

    
273

    
274
    /// <summary>
275
	/// The <c>ErrorReporter</c> is a generic functional class for reporting errors and warnings.
276
	/// This class wraps an <c>IList</c> of <c>XmlProcessingError</c> objects.
277
    /// It is designed to be used internally by Saxon.
278
    /// </summary>
279
    [Serializable]
280
	public class ErrorReporter : JErrorReporter
281
    {
282

    
283
        private IList<XmlProcessingError> errorList;
284

    
285
        /// <summary>
286
        /// Initializes a new instance of the <see cref="Saxon.Api.ErrorReporter"/> class.
287
        /// </summary>
288
        /// <param name="errorList">Error list.</param>
289
        public ErrorReporter(IList<XmlProcessingError> errorList)
290
        {
291
            this.errorList = errorList;
292
        }
293

    
294
        /// <summary>
295
        /// Get property on the wrapped error list.
296
        /// </summary>
297
        public IList<XmlProcessingError> ErrorList {
298
            get { return errorList; }
299
        }
300
        
301
        /// <summary>
302
        /// This method is called internally in Saxon to report an error by adding it to the error list.
303
        /// </summary>
304
        /// <param name="xpe"></param>
305
        public void report(JXmlProcessingError xpe)
306
        {
307
            errorList.Add(new XmlProcessingError(xpe));
308
        }
309
    }
310

    
311
    /// <summary>
312
	/// <c>ErrorReporter</c> for gathering errors as <c>XmlProcessorError</c> to then
313
	/// convert them to a list of <c>StaticError</c>s.
314
    /// </summary>
315
    [Serializable]
316
	public class ErrorReporterToStaticError : JErrorReporter
317
    {
318

    
319
        private IList<StaticError> errorList;
320

    
321
        /// <summary>
322
        /// Initializes a new instance of the <see cref="Saxon.Api.ErrorReporter"/> class.
323
        /// </summary>
324
        /// <param name="errorList">Error list.</param>
325
        public ErrorReporterToStaticError(IList<StaticError> errorList)
326
        {
327
            this.errorList = errorList;
328
        }
329

    
330
        public IList<StaticError> ErrorList
331
        {
332
            get { return errorList; }
333
        }
334

    
335

    
336
        public void report(JXmlProcessingError xpe)
337
        {
338
            errorList.Add(new StaticError(net.sf.saxon.trans.XPathException.fromXmlProcessingError(xpe)));
339
        }
340
    }
341

    
342

    
343
    /// <summary>
344
	/// The <c>DynamicError</c> class contains information about a dynamic error detected during
345
    /// execution of a stylesheet, query, or XPath expression.
346
    /// </summary>
347

    
348
    [Serializable]
349
    public class DynamicError : Exception
350
    {
351

    
352
        private XPathException exception;
353
        internal bool isWarning;
354

    
355
        /// <summary>
356
		/// Create a new <c>DynamicError</c>, specifying the error message.
357
        /// </summary>
358
        /// <param name="message">The error message</param>
359

    
360
        public DynamicError(String message)
361
        {
362
            exception = new XPathException(message);
363
        }
364

    
365
        // internal constructor: Create a new DynamicError, wrapping a Saxon XPathException
366

    
367
        internal DynamicError(JTransformerException err)
368
        {
369
            if (err is XPathException)
370
            {
371
                this.exception = (XPathException)err;
372
            }
373
            else
374
            {
375
                this.exception = XPathException.makeXPathException(err);
376
            }
377
        }
378

    
379
        // internal constructor: Create a new DynamicError, wrapping an SaxonApiException
380

    
381
        internal DynamicError(JSaxonApiException err)
382
        {
383
            if (err.getCause() is XPathException)
384
            {   
385
                this.exception = (XPathException)err.getCause();
386
            }
387
            else
388
            {
389
                this.exception = XPathException.makeXPathException(err);
390
            }
391
        }
392

    
393
        /// <summary>
394
		/// The error code, as a <c>QName</c>. May be null if no error code has been assigned.
395
        /// </summary>
396

    
397
        public QName ErrorCode
398
        {
399
            get
400
            {
401

    
402
                String errorCode = exception.getErrorCodeLocalPart();
403
                if (errorCode == null) {
404
                    return null;
405
                }
406
                return new QName("err",
407
                        exception.getErrorCodeNamespace(),
408
                        errorCode);
409
            }
410
        }
411

    
412
        /// <summary>
413
        /// Return the message associated with this error.
414
        /// </summary>
415

    
416
        public override String Message
417
        {
418
            get
419
            {
420
                return exception.getMessage();
421
            }
422
        }
423

    
424
        /// <summary>
425
        /// The URI of the query or stylesheet module in which the error was detected
426
        /// (as a string).
427
        /// </summary>
428
        /// <remarks>
429
        /// May be null if the location of the error is unknown, or if the error is not
430
        /// localized to a specific module, or if the module in question has no known URI
431
		/// (for example, if it was supplied as an anonymous <c>Stream</c>).
432
        /// </remarks>
433

    
434
        public String ModuleUri
435
        {
436
            get
437
            {
438
                if (exception.getLocator() == null)
439
                {
440
                    return null;
441
                }
442
                return exception.getLocator().getSystemId();
443
            }
444
        }
445

    
446
        /// <summary>
447
        /// The line number locating the error within a query or stylesheet module.
448
        /// </summary>
449
        /// <remarks>
450
        /// May be set to -1 if the location of the error is unknown.
451
        /// </remarks>        
452

    
453
        public int LineNumber
454
        {
455
            get
456
            {
457
                JSourceLocator loc = exception.getLocator();
458
                if (loc == null)
459
                {
460
                    if (exception.getException() is JTransformerException)
461
                    {
462
                        loc = ((JTransformerException)exception.getException()).getLocator();
463
                        if (loc != null)
464
                        {
465
                            return loc.getLineNumber();
466
                        }
467
                    }
468
                    return -1;
469
                }
470
                return loc.getLineNumber();
471
            }
472
        }
473

    
474
        /// <summary>
475
        /// Indicate whether this error is being reported as a warning condition. If so, applications
476
        /// may ignore the condition, though the results may not be as intended.
477
        /// </summary>
478

    
479
        public bool IsWarning
480
        {
481
            get
482
            {
483
                return isWarning;
484
            }
485
            set
486
            {
487
                isWarning = value;
488
            }
489
        }
490

    
491
        /// <summary>
492
        /// Indicate whether this condition is a type error.
493
        /// </summary>
494

    
495
        public bool IsTypeError
496
        {
497
            get
498
            {
499
                return exception.isTypeError();
500
            }
501
        }
502

    
503
        /// <summary>
504
        /// Return the error message.
505
        /// </summary>
506

    
507
        public override String ToString()
508
        {
509
            return exception.getMessage();
510
        }
511

    
512
        /// <summary>
513
        /// Return the underlying exception. This is unstable as this is an internal object.
514
        /// </summary>
515
		/// <returns>The underlying <c>XPathException</c></returns>
516
        
517
		public XPathException UnderlyingException
518
        {
519
            get
520
            {
521
                return exception;
522
            }
523
        }
524

    
525

    
526

    
527
    }
528

    
529
    /// <summary>
530
	/// The <c>XmlProcessorError</c> class contains information about an error detected during
531
    /// compilation or execution of a stylesheet, query, XPath expression, or schema.
532
    /// </summary>
533
    public class XmlProcessingError : StaticError
534
    {
535
        JXmlProcessingError error;
536
        internal XmlProcessingError(JXmlProcessingError err) : base(XPathException.fromXmlProcessingError(err))
537
        {
538
            this.error = err;
539
        }
540

    
541
        /// <summary>
542
		/// This get property returns a <c>XmlProcessingError</c> containing the same information, but to be treated as a warning condition.
543
        /// </summary>
544
        public XmlProcessingError AsWarning {
545
            get {
546
                XmlProcessingError e2 = new XmlProcessingError(error);
547
                e2.IsWarning = true;
548
                return e2;
549
            }
550
        }
551

    
552
        /// <summary>
553
        /// Property to get the host language where this error originates from.
554
        /// </summary>
555
        public HostLanguage HostLanguage {
556

    
557
            get {
558
                if (error.getHostLanguage() == net.sf.saxon.s9api.HostLanguage.XSLT)
559
                {
560
                    return HostLanguage.XSLT;
561
                }
562
                else {
563
                    return HostLanguage.XPATH;
564
                }
565
            }
566
        }
567

    
568
        /// <summary>
569
        /// Property to indicate that this error is to be treated as fatal, that is,
570
        /// execution will be abandoned after reporting this error. This method may be called
571
        /// by <c>ErrorReporter</c>, for example if the error is considered so server that further processing
572
        /// is not worthwhile, or if too many errors have been signalled. there is no absolute guarantee that
573
        /// setting this property will cause execution to be abandoned.
574
        /// It can also be used to ask whether this error is to be treated as fatal, 
575
        /// and if so, return the relevant message.
576
        /// </summary>
577
        public String FatalMessage {
578

    
579
            set {
580
                error.setFatal(value);
581
            }
582
            get {
583
                return error.getFatalErrorMessage();
584
            }
585
        }
586

    
587
        /// <summary>
588
        /// Property to check if this error is a <c>StaticError</c>.
589
        /// </summary>
590
        public bool StaticError {
591
            get { return error.isStaticError(); }
592
        }
593

    
594
        /// <summary>
595
        /// Property which indicates whether this condition is a type error.
596
        /// </summary>
597
        public bool TypeError {
598
            get { return error.isTypeError(); }
599
        }
600

    
601

    
602
        /// <summary>
603
        /// Ask whether this static error has already been reported.
604
        /// </summary>
605
        /// <returns></returns>
606
        public bool IsAlreadyReported() {
607
            return error.isAlreadyReported();
608
        }
609

    
610

    
611
        /// <summary>
612
        /// Say whether this error has already been reported.
613
        /// </summary>
614
        /// <param name="reported">true if the error has been reported</param>
615
        public void SetAlreadyReported(bool reported)
616
        {
617
            error.setAlreadyReported(reported);
618
        }
619

    
620
    }
621

    
622

    
623
    /// <summary>
624
    /// This exception indicates a failure when validating an instance against a type
625
    ///  defined in a schema.
626
    /// </summary>
627
	/// <remarks>
628
	/// This class holds the same information as a <c>ValidationException</c>, except that it is not an exception,
629
	///  and does not carry system overheads such as a stack trace. It is used because operations such as "castable",
630
	///  and validation of values in a union, cause validation failures on a success path and it is costly to throw,
631
	///  or even to create, exception objects on a success path.
632
	/// </remarks>
633
    public class ValidationFailure
634
    {
635
        private JValidationFailure failure;
636

    
637
        internal ValidationFailure(JValidationFailure failure) {
638
            this.failure = failure; 
639
        }
640

    
641
        /// <summary>
642
        /// Return the character position where the current document event ends.
643
        /// </summary>
644
        /// <returns>the column number, or -1 if none is available</returns>
645
        public int GetColumnNumber()
646
        {
647
            return failure.getColumnNumber();
648
        }
649

    
650
        /// <summary>
651
        /// Get the constraint clause number.
652
        /// </summary>
653
        /// <returns>The section number of the clause containing the constraint that has been violated.
654
        /// Generally a decimal number in the form n.n.n; possibly a sequence of such numbers separated
655
        ///  by semicolons.Or null if the information is not available.</returns>
656
        public String GetConstraintClauseNumber()
657
        {
658
            return failure.getConstraintClauseNumber();
659
        }
660

    
661

    
662
        /// <summary>
663
        /// Get the constraint name.
664
        /// </summary>
665
        /// <returns>The name of the violated constraint, in the form of a fragment identifier within
666
        ///  the published XML Schema specification; or null if the information is not available.</returns>
667
        public String GetConstraintName()
668
        {
669
            return failure.getConstraintName();
670
        }
671

    
672
        /// <summary>
673
        /// Get the constraint name and clause in the format defined in XML Schema Part C (Outcome Tabulations).
674
        /// This mandates the format validation-rule-name.clause-number
675
        /// </summary>
676
        /// <returns>The constraint reference, for example "cos-ct-extends.1.2"; or null if the reference
677
        ///  is not known.</returns>
678
        public String getConstraintReference()
679
        {
680
            return failure.getConstraintReference();
681
        }
682

    
683
        /// <summary>
684
        /// Get additional location text, if any.
685
        /// </summary>
686
        /// <returns>Additional information about the location of the error, designed to be output
687
        /// as a prefix to the error message if desired.</returns>
688
        public String GetContextPath()
689
        {
690
            return failure.getContextPath().toString();
691
        }
692

    
693

    
694
        /// <summary>
695
        /// Get the error code associated with the validity error. This is relevant only when validation
696
        /// is run from within XSLT or XQuery, which define different error codes for validation errors.
697
        /// </summary>
698
        /// <returns>The error code associated with the error, if any. The error is returned as a simple
699
        /// string if it is in the standard error namespace, or as an EQName (that is Q{uri}local) 
700
		/// otherwise.</returns>
701
        public String GetErrorCode()
702
        {
703
            return failure.getErrorCode();
704
        }
705

    
706
        /// <summary>
707
        /// Return the line number where the current document event ends.
708
        /// </summary>
709
        /// <returns>The line number, or -1 if none is available.</returns>
710
        public int GetLineNumber()
711
        {
712
            return failure.getLineNumber();
713
        }
714

    
715
        /// <summary>
716
        /// Get the text of a message explaining what is wrong.
717
        /// </summary>
718
        /// <returns>A human-readable message explaining the validity error.</returns>
719
        public String GetMessage()
720
        {
721
            return failure.getMessage();
722
        }
723

    
724
        /// <summary>
725
        /// Get a hierarchic path giving the logical position in the instance document where the
726
        /// validation error was found.
727
        /// </summary>
728
        /// <returns>A path to the location in the document.</returns>
729
        public String GetPath()
730
        {
731
            return failure.getPath().toString();
732
        }
733

    
734

    
735
        /// <summary>
736
        /// Return the public identifier for the current document event.
737
        /// </summary>
738
        /// <returns>A string containing the public identifier, or null if none is available.</returns>
739
        public String GetPublicId()
740
        {
741
            return failure.getPublicId();
742
        }
743

    
744
        /// <summary>
745
        /// Get the "schema part" component of the constraint reference.
746
        /// </summary>
747
        /// <returns>1 or 2 depending on whether the violated constraint is in XML Schema Part 1 or Part 2;
748
        /// or -1 if there is no constraint reference.</returns>
749
        public int GetSchemaPart()
750
        {
751
            return failure.getSchemaPart();
752
        }
753

    
754
        /// <summary>
755
        /// Return the system identifier for the current document event.
756
        /// </summary>
757
        /// <returns>A string containing the system identifier, or null if none is available.</returns>
758
        public String GetSystemId()
759
        {
760
            return failure.getSystemId();
761
        }
762
    }
763

    
764
    /// <summary>
765
    /// Error gatherer. This class is used to provide customized error handling. 
766
	/// </summary>
767
    /// <remarks><para>If an application does <em>not</em> register its own custom
768
    /// <code>ErrorListener</code>, the default <code>ErrorGatherer</code>
769
    /// is used which keeps track of all warnings and errors in a list,
770
    /// and does not throw any <code>Exception</code>s.
771
    /// Applications are <em>strongly</em> encouraged to register and use
772
    /// <code>ErrorListener</code>s that insure proper behavior for warnings and
773
    /// errors.</para>
774
    /// </remarks>
775
    [Serializable]
776
    internal class ErrorGatherer : javax.xml.transform.ErrorListener
777
    {
778

    
779
        private IList<StaticError> errorList;
780

    
781

    
782
        /// <summary>
783
        /// Initializes a new instance of the <see cref="Saxon.Api.ErrorGatherer"/> class.
784
        /// </summary>
785
        /// <param name="errorList">Error list.</param>
786
        public ErrorGatherer(IList<StaticError> errorList)
787
        {
788
            this.errorList = errorList;
789
        }
790

    
791
        /// <summary>
792
        /// Warning the specified exception.
793
        /// </summary>
794
        /// <param name="exception">TransformerException.</param>
795
        public void warning(JTransformerException exception)
796
        {
797
            StaticError se = new StaticError(exception);
798
            // if(exception)
799
            se.IsWarning = true;
800
            //Console.WriteLine("(Adding warning " + exception.getMessage() + ")");
801
            errorList.Add(se);
802
        }
803

    
804
        /// <summary>
805
        /// Report a Transformer exception thrown.
806
        /// </summary>
807
        /// <param name="error">Error.</param>
808
        public void error(JTransformerException error)
809
        {
810
            StaticError se = new StaticError(error);
811
            se.IsWarning = false;
812
            //Console.WriteLine("(Adding error " + error.getMessage() + ")");
813
            errorList.Add(se);
814
        }
815

    
816
        /// <summary>
817
        /// Report a fatal exception thrown.
818
        /// </summary>
819
        /// <param name="error">TransformerException.</param>
820
        public void fatalError(JTransformerException error)
821
        {
822
            StaticError se = new StaticError(error);
823
            se.IsWarning = false;
824
            errorList.Add(se);
825
            //Console.WriteLine("(Adding fatal error " + error.getMessage() + ")");
826
        }
827

    
828

    
829
        /// <summary>
830
        /// Gets the error list.
831
        /// </summary>
832
        /// <returns>Returns the error list</returns>
833
        public IList<StaticError> ErrorList {
834

    
835
            get
836
            {
837
                return errorList;
838

    
839
            }
840
        }
841
    }
842

    
843

    
844
	/// <summary>
845
	/// Interface for reporting validation errors found during validation of an instance document
846
	/// against a schema.
847
	/// </summary>
848
	public interface IInvalidityHandler {
849

    
850
        /// <summary>
851
        /// At the start of a validation episode, initialize the handler.
852
        /// </summary>
853
        /// <param name="systemId">Optional; may be used to represent the destination of any
854
        /// report produced.</param>
855
		/**public**/ void startReporting(String systemId);
856

    
857

    
858
		/// <summary>
859
		/// Report a validation error found during validation of an instance document
860
		/// against a schema.
861
		/// </summary>
862
		/// <param name="i">Details of the validation error.</param>
863
		/**public**/ void reportInvalidity (ValidationFailure i);
864
		
865

    
866
		/// <summary>
867
		/// At the end of a validation episode, do any closedown actions, and optionally return
868
		/// information collected in the course of validation (for example a list of error messages).
869
		/// </summary>
870
		/// <returns>A value to be associated with a validation exception. May be the empty sequence.
871
		/// In the case of the <c>InvalidityReportGenerator</c>, this returns the XML document
872
		/// containing the validation report. This will be the value returned as the value of
873
		/// the variable <c>$err:value</c> during try/catch processing.</returns>
874
		/**public**/ XdmValue endReporting(); 
875
		
876

    
877

    
878

    
879
	}
880

    
881

    
882
    /// <summary>
883
	/// This class <c>InvalidityHandlerWrapper</c> extends the standard error handler for errors found during
884
    /// validation of an instance document against a schema, used if a user specifies the -report option on validate.
885
    /// Its effect is to output the validation errors found into the filename specified, in an XML format.
886
	/// This is a wrapper class to wrap a .NET <c>InvalidityHandler</c> class for interfacing within Java.
887
    /// </summary>
888
	public class InvalidityHandlerWrapper : JInvalidityHandler
889
    {
890

    
891
        private IInvalidityHandler inHandler;
892

    
893
        /// <summary>
894
        /// Create a standard Invalidity Handler.
895
        /// </summary>
896
		/// <param name="inHandler">The .NET <c>IInvalidityHandler</c>.</param>
897
        public InvalidityHandlerWrapper(IInvalidityHandler inHandler) {
898
            this.inHandler = inHandler;
899
        }
900

    
901

    
902
        /// <summary>
903
        /// Get the value to be associated with a validation exception. May return null.
904
		/// In the case of the <c>InvalidityGenerator</c>, this returns the XML document
905
        /// containing the validation report.
906
        /// </summary>
907
        /// <returns>A value (or null). This will be the value returned as the value of the variable
908
		/// <c>$err:value</c> during try/catch processor.</returns>
909
        public JSequence endReporting()
910
        {
911
            XdmValue value = inHandler.endReporting();
912

    
913
            if (value != null)
914
            {
915
                return inHandler.endReporting().Unwrap();
916
            }
917
            return null;
918

    
919
        }
920

    
921
        /// <summary>
922
        /// Receive notification of a validity error.
923
        /// </summary>
924
        /// <param name="i">Information about the nature of the invalidity.</param>
925
        public void reportInvalidity(JInvalidity i)
926
        {
927
            if (i is JValidationFailure) { 
928
                ValidationFailure error = new ValidationFailure((JValidationFailure)i);
929
                inHandler.reportInvalidity(error);
930
            }
931

    
932
            
933
        }
934

    
935

    
936
        /// <summary>
937
        /// At the start of a validation episode, initialize the handler.
938
        /// </summary>
939
        /// <param name="systemId">Optional; may be used to represent the destination of any report produced.</param>
940
        public void startReporting(string systemId)
941
        {
942
            inHandler.startReporting(systemId);
943
        }
944

    
945
        
946
	}
947

    
948

    
949

    
950

    
951

    
952

    
953
	/// <summary>
954
	/// <para>If an application does <em>not</em> register its own custom
955
	/// <code>InvalidityHandler</code>, the default <code>InvalidityGatherer</code>
956
	/// is used which keeps track of all warnings and errors in a list,
957
	/// and does not throw any <code>Exception</code>s.
958
	/// Applications are <em>strongly</em> encouraged to register and use
959
	/// <code>InvalidityHandler</code>s that insure proper behavior for warnings and
960
	/// errors.</para>
961
	/// </summary>
962
	[Serializable]
963
	internal class InvalidityGatherer : JInvalidityHandler
964
	{
965

    
966

    
967
		private IList<ValidationFailure> errorList;
968

    
969

    
970

    
971
		/// <summary>
972
		/// Initializes a new instance of the <see cref="Saxon.Api.InvalidityGatherer"/> class.
973
		/// </summary>
974

    
975
		public InvalidityGatherer(IList<ValidationFailure> errorList)
976
		{
977
            this.errorList = errorList;
978
		}
979

    
980
		public void startReporting(String systemId) {
981
			//invalidityHandler.startReporting (systemId);
982
		}
983

    
984
		public JSequence endReporting() {
985
            //return invalidityHandler.endReporting ();
986
            return null;
987
		}
988

    
989
        /// <summary>
990
		/// List of errors. The caller may supply an empty list before calling <c>Compile</c>;
991
        /// the processor will then populate the list with error information obtained during
992
		/// the schema compilation. Each error will be included as an object of type <c>StaticError</c>.
993
        /// If no error list is supplied by the caller, error information will be written to
994
        /// the standard error stream.
995
        /// </summary>
996
        /// <remarks>
997
		/// <para>By supplying a custom <c>List</c> with a user-written <c>add()</c> method, it is possible to
998
        /// intercept error conditions as they occur.</para>
999
        /// <para>Note that this error list is used only for errors detected while 
1000
        /// using the schema to validate a source document. It is not used to report errors
1001
        /// in the schema itself.</para>
1002
        /// </remarks>
1003

    
1004
        public IList<ValidationFailure> ErrorList
1005
        {
1006
            set
1007
            {
1008
                errorList = value;
1009
            }
1010
            get
1011
            {
1012
                return errorList;
1013
            }
1014
        }
1015

    
1016

    
1017

    
1018
        /// <summary>
1019
        /// 
1020
        /// </summary>
1021
        /// <param name="failure">net.sf.saxon.type.ValidationFailure.</param>
1022
        public void reportInvalidity(JInvalidity failure)
1023
		{
1024
            ValidationFailure se = new ValidationFailure((JValidationFailure)failure);
1025
            errorList.Add(se);
1026

    
1027
			//invalidityHandler.reportInvalidity (se);
1028
		}
1029

    
1030

    
1031
	}
1032

    
1033

    
1034

    
1035

    
1036
}
1037

    
1038
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1039
// Copyright (c) 2020 Saxonica Limited.
1040
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
1041
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
1042
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
1043
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
(3-3/11)