Project

Profile

Help

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

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

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
		/// <summary>
267
		/// This method is called internally in Saxon to report an error by adding it to the error list.
268
		/// </summary>
269
		/// <param name="xpe">details of the error to be reported</param>
270
        public void report(JXmlProcessingError xpe)
271
        {
272
            reporter.report(new XmlProcessingError(xpe));
273
        }
274
    }
275

    
276

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

    
286
        private IList<XmlProcessingError> errorList;
287

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

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

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

    
322
        private IList<StaticError> errorList;
323

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

    
333
        public IList<StaticError> ErrorList
334
        {
335
            get { return errorList; }
336
        }
337

    
338
		/// <summary>
339
		/// This method is called internally in Saxon to report an error by adding it to the error list.
340
		/// </summary>
341
		/// <param name="xpe">details of the error to be reported</param>
342
        public void report(JXmlProcessingError xpe)
343
        {
344
            errorList.Add(new StaticError(net.sf.saxon.trans.XPathException.fromXmlProcessingError(xpe)));
345
        }
346
    }
347

    
348

    
349
    /// <summary>
350
	/// The <c>DynamicError</c> class contains information about a dynamic error detected during
351
    /// execution of a stylesheet, query, or XPath expression.
352
    /// </summary>
353

    
354
    [Serializable]
355
    public class DynamicError : Exception
356
    {
357

    
358
        private XPathException exception;
359
        internal bool isWarning;
360

    
361
        /// <summary>
362
		/// Create a new <c>DynamicError</c>, specifying the error message.
363
        /// </summary>
364
        /// <param name="message">The error message</param>
365

    
366
        public DynamicError(String message)
367
        {
368
            exception = new XPathException(message);
369
        }
370

    
371
        // internal constructor: Create a new DynamicError, wrapping a Saxon XPathException
372

    
373
        internal DynamicError(JTransformerException err)
374
        {
375
            if (err is XPathException)
376
            {
377
                this.exception = (XPathException)err;
378
            }
379
            else
380
            {
381
                this.exception = XPathException.makeXPathException(err);
382
            }
383
        }
384

    
385
        // internal constructor: Create a new DynamicError, wrapping an SaxonApiException
386

    
387
        internal DynamicError(JSaxonApiException err)
388
        {
389
            if (err.getCause() is XPathException)
390
            {   
391
                this.exception = (XPathException)err.getCause();
392
            }
393
            else
394
            {
395
                this.exception = XPathException.makeXPathException(err);
396
            }
397
        }
398

    
399
        /// <summary>
400
		/// The error code, as a <c>QName</c>. May be null if no error code has been assigned.
401
        /// </summary>
402

    
403
        public QName ErrorCode
404
        {
405
            get
406
            {
407

    
408
                String errorCode = exception.getErrorCodeLocalPart();
409
                if (errorCode == null) {
410
                    return null;
411
                }
412
                return new QName("err",
413
                        exception.getErrorCodeNamespace(),
414
                        errorCode);
415
            }
416
        }
417

    
418
        /// <summary>
419
        /// Return the message associated with this error.
420
        /// </summary>
421

    
422
        public override String Message
423
        {
424
            get
425
            {
426
                return exception.getMessage();
427
            }
428
        }
429

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

    
440
        public String ModuleUri
441
        {
442
            get
443
            {
444
                if (exception.getLocator() == null)
445
                {
446
                    return null;
447
                }
448
                return exception.getLocator().getSystemId();
449
            }
450
        }
451

    
452
        /// <summary>
453
        /// The line number locating the error within a query or stylesheet module.
454
        /// </summary>
455
        /// <remarks>
456
        /// May be set to -1 if the location of the error is unknown.
457
        /// </remarks>        
458

    
459
        public int LineNumber
460
        {
461
            get
462
            {
463
                JSourceLocator loc = exception.getLocator();
464
                if (loc == null)
465
                {
466
                    if (exception.getException() is JTransformerException)
467
                    {
468
                        loc = ((JTransformerException)exception.getException()).getLocator();
469
                        if (loc != null)
470
                        {
471
                            return loc.getLineNumber();
472
                        }
473
                    }
474
                    return -1;
475
                }
476
                return loc.getLineNumber();
477
            }
478
        }
479

    
480
        /// <summary>
481
        /// Indicate whether this error is being reported as a warning condition. If so, applications
482
        /// may ignore the condition, though the results may not be as intended.
483
        /// </summary>
484

    
485
        public bool IsWarning
486
        {
487
            get
488
            {
489
                return isWarning;
490
            }
491
            set
492
            {
493
                isWarning = value;
494
            }
495
        }
496

    
497
        /// <summary>
498
        /// Indicate whether this condition is a type error.
499
        /// </summary>
500

    
501
        public bool IsTypeError
502
        {
503
            get
504
            {
505
                return exception.isTypeError();
506
            }
507
        }
508

    
509
        /// <summary>
510
        /// Return the error message.
511
        /// </summary>
512

    
513
        public override String ToString()
514
        {
515
            return exception.getMessage();
516
        }
517

    
518
        /// <summary>
519
        /// Return the underlying exception. This is unstable as this is an internal object.
520
        /// </summary>
521
		/// <returns>The underlying <c>XPathException</c></returns>
522
        
523
		public XPathException UnderlyingException
524
        {
525
            get
526
            {
527
                return exception;
528
            }
529
        }
530

    
531

    
532

    
533
    }
534

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

    
547
        /// <summary>
548
		/// This get property returns a <c>XmlProcessingError</c> containing the same information, but to be treated as a warning condition.
549
        /// </summary>
550
        public XmlProcessingError AsWarning {
551
            get {
552
                XmlProcessingError e2 = new XmlProcessingError(error);
553
                e2.IsWarning = true;
554
                return e2;
555
            }
556
        }
557

    
558
        /// <summary>
559
        /// Property to get the host language where this error originates from.
560
        /// </summary>
561
        public HostLanguage HostLanguage {
562

    
563
            get {
564
                if (error.getHostLanguage() == net.sf.saxon.s9api.HostLanguage.XSLT)
565
                {
566
                    return HostLanguage.XSLT;
567
                }
568
                else {
569
                    return HostLanguage.XPATH;
570
                }
571
            }
572
        }
573

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

    
585
            set {
586
                error.setFatal(value);
587
            }
588
            get {
589
                return error.getFatalErrorMessage();
590
            }
591
        }
592

    
593
        /// <summary>
594
        /// Property to check if this error is a <c>StaticError</c>.
595
        /// </summary>
596
        public bool StaticError {
597
            get { return error.isStaticError(); }
598
        }
599

    
600
        /// <summary>
601
        /// Property which indicates whether this condition is a type error.
602
        /// </summary>
603
        public bool TypeError {
604
            get { return error.isTypeError(); }
605
        }
606

    
607

    
608
        /// <summary>
609
        /// Ask whether this static error has already been reported.
610
        /// </summary>
611
        /// <returns></returns>
612
        public bool IsAlreadyReported() {
613
            return error.isAlreadyReported();
614
        }
615

    
616

    
617
        /// <summary>
618
        /// Say whether this error has already been reported.
619
        /// </summary>
620
        /// <param name="reported">true if the error has been reported</param>
621
        public void SetAlreadyReported(bool reported)
622
        {
623
            error.setAlreadyReported(reported);
624
        }
625

    
626
    }
627

    
628

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

    
643
        internal ValidationFailure(JValidationFailure failure) {
644
            this.failure = failure; 
645
        }
646

    
647
        /// <summary>
648
        /// Return the character position where the current document event ends.
649
        /// </summary>
650
        /// <returns>the column number, or -1 if none is available</returns>
651
        public int GetColumnNumber()
652
        {
653
            return failure.getColumnNumber();
654
        }
655

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

    
667

    
668
        /// <summary>
669
        /// Get the constraint name.
670
        /// </summary>
671
        /// <returns>The name of the violated constraint, in the form of a fragment identifier within
672
        ///  the published XML Schema specification; or null if the information is not available.</returns>
673
        public String GetConstraintName()
674
        {
675
            return failure.getConstraintName();
676
        }
677

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

    
689
        /// <summary>
690
        /// Get additional location text, if any.
691
        /// </summary>
692
        /// <returns>Additional information about the location of the error, designed to be output
693
        /// as a prefix to the error message if desired.</returns>
694
        public String GetContextPath()
695
        {
696
            return failure.getContextPath().toString();
697
        }
698

    
699

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

    
712
        /// <summary>
713
        /// Return the line number where the current document event ends.
714
        /// </summary>
715
        /// <returns>The line number, or -1 if none is available.</returns>
716
        public int GetLineNumber()
717
        {
718
            return failure.getLineNumber();
719
        }
720

    
721
        /// <summary>
722
        /// Get the text of a message explaining what is wrong.
723
        /// </summary>
724
        /// <returns>A human-readable message explaining the validity error.</returns>
725
        public String GetMessage()
726
        {
727
            return failure.getMessage();
728
        }
729

    
730
        /// <summary>
731
        /// Get a hierarchic path giving the logical position in the instance document where the
732
        /// validation error was found.
733
        /// </summary>
734
        /// <returns>A path to the location in the document.</returns>
735
        public String GetPath()
736
        {
737
            return failure.getPath().toString();
738
        }
739

    
740

    
741
        /// <summary>
742
        /// Return the public identifier for the current document event.
743
        /// </summary>
744
        /// <returns>A string containing the public identifier, or null if none is available.</returns>
745
        public String GetPublicId()
746
        {
747
            return failure.getPublicId();
748
        }
749

    
750
        /// <summary>
751
        /// Get the "schema part" component of the constraint reference.
752
        /// </summary>
753
        /// <returns>1 or 2 depending on whether the violated constraint is in XML Schema Part 1 or Part 2;
754
        /// or -1 if there is no constraint reference.</returns>
755
        public int GetSchemaPart()
756
        {
757
            return failure.getSchemaPart();
758
        }
759

    
760
        /// <summary>
761
        /// Return the system identifier for the current document event.
762
        /// </summary>
763
        /// <returns>A string containing the system identifier, or null if none is available.</returns>
764
        public String GetSystemId()
765
        {
766
            return failure.getSystemId();
767
        }
768
    }
769

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

    
785
        private IList<StaticError> errorList;
786

    
787

    
788
        /// <summary>
789
        /// Initializes a new instance of the <see cref="Saxon.Api.ErrorGatherer"/> class.
790
        /// </summary>
791
        /// <param name="errorList">Error list.</param>
792
        public ErrorGatherer(IList<StaticError> errorList)
793
        {
794
            this.errorList = errorList;
795
        }
796

    
797
        /// <summary>
798
        /// Warning the specified exception.
799
        /// </summary>
800
        /// <param name="exception">TransformerException.</param>
801
        public void warning(JTransformerException exception)
802
        {
803
            StaticError se = new StaticError(exception);
804
            // if(exception)
805
            se.IsWarning = true;
806
            //Console.WriteLine("(Adding warning " + exception.getMessage() + ")");
807
            errorList.Add(se);
808
        }
809

    
810
        /// <summary>
811
        /// Report a Transformer exception thrown.
812
        /// </summary>
813
        /// <param name="error">Error.</param>
814
        public void error(JTransformerException error)
815
        {
816
            StaticError se = new StaticError(error);
817
            se.IsWarning = false;
818
            //Console.WriteLine("(Adding error " + error.getMessage() + ")");
819
            errorList.Add(se);
820
        }
821

    
822
        /// <summary>
823
        /// Report a fatal exception thrown.
824
        /// </summary>
825
        /// <param name="error">TransformerException.</param>
826
        public void fatalError(JTransformerException error)
827
        {
828
            StaticError se = new StaticError(error);
829
            se.IsWarning = false;
830
            errorList.Add(se);
831
            //Console.WriteLine("(Adding fatal error " + error.getMessage() + ")");
832
        }
833

    
834

    
835
        /// <summary>
836
        /// Gets the error list.
837
        /// </summary>
838
        /// <returns>Returns the error list</returns>
839
        public IList<StaticError> ErrorList {
840

    
841
            get
842
            {
843
                return errorList;
844

    
845
            }
846
        }
847
    }
848

    
849

    
850
	/// <summary>
851
	/// Interface for reporting validation errors found during validation of an instance document
852
	/// against a schema.
853
	/// </summary>
854
	public interface IInvalidityHandler {
855

    
856
        /// <summary>
857
        /// At the start of a validation episode, initialize the handler.
858
        /// </summary>
859
        /// <param name="systemId">Optional; may be used to represent the destination of any
860
        /// report produced.</param>
861
		/**public**/ void startReporting(String systemId);
862

    
863

    
864
		/// <summary>
865
		/// Report a validation error found during validation of an instance document
866
		/// against a schema.
867
		/// </summary>
868
		/// <param name="i">Details of the validation error.</param>
869
		/**public**/ void reportInvalidity (ValidationFailure i);
870
		
871

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

    
883

    
884

    
885
	}
886

    
887

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

    
897
        private IInvalidityHandler inHandler;
898

    
899
        /// <summary>
900
        /// Create a standard Invalidity Handler.
901
        /// </summary>
902
		/// <param name="inHandler">The .NET <c>IInvalidityHandler</c>.</param>
903
        public InvalidityHandlerWrapper(IInvalidityHandler inHandler) {
904
            this.inHandler = inHandler;
905
        }
906

    
907

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

    
919
            if (value != null)
920
            {
921
                return inHandler.endReporting().Unwrap();
922
            }
923
            return null;
924

    
925
        }
926

    
927
        /// <summary>
928
        /// Receive notification of a validity error.
929
        /// </summary>
930
        /// <param name="i">Information about the nature of the invalidity.</param>
931
        public void reportInvalidity(JInvalidity i)
932
        {
933
            if (i is JValidationFailure) { 
934
                ValidationFailure error = new ValidationFailure((JValidationFailure)i);
935
                inHandler.reportInvalidity(error);
936
            }
937

    
938
            
939
        }
940

    
941

    
942
        /// <summary>
943
        /// At the start of a validation episode, initialize the handler.
944
        /// </summary>
945
        /// <param name="systemId">Optional; may be used to represent the destination of any report produced.</param>
946
        public void startReporting(string systemId)
947
        {
948
            inHandler.startReporting(systemId);
949
        }
950

    
951
        
952
	}
953

    
954

    
955

    
956

    
957

    
958

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

    
972

    
973
		private IList<ValidationFailure> errorList;
974

    
975

    
976

    
977
		/// <summary>
978
		/// Initializes a new instance of the <see cref="Saxon.Api.InvalidityGatherer"/> class.
979
		/// </summary>
980

    
981
		public InvalidityGatherer(IList<ValidationFailure> errorList)
982
		{
983
            this.errorList = errorList;
984
		}
985

    
986
		public void startReporting(String systemId) {
987
			//invalidityHandler.startReporting (systemId);
988
		}
989

    
990
		public JSequence endReporting() {
991
            //return invalidityHandler.endReporting ();
992
            return null;
993
		}
994

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

    
1010
        public IList<ValidationFailure> ErrorList
1011
        {
1012
            set
1013
            {
1014
                errorList = value;
1015
            }
1016
            get
1017
            {
1018
                return errorList;
1019
            }
1020
        }
1021

    
1022

    
1023

    
1024
        /// <summary>
1025
        /// 
1026
        /// </summary>
1027
        /// <param name="failure">net.sf.saxon.type.ValidationFailure.</param>
1028
        public void reportInvalidity(JInvalidity failure)
1029
		{
1030
            ValidationFailure se = new ValidationFailure((JValidationFailure)failure);
1031
            errorList.Add(se);
1032

    
1033
			//invalidityHandler.reportInvalidity (se);
1034
		}
1035

    
1036

    
1037
	}
1038

    
1039

    
1040

    
1041

    
1042
}
1043

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