Project

Profile

Help

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

he / src / samples / cs / TestRunner10.0 / ErrorCollector.cs @ be17ef52

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using Saxon.Api;
6
using JXPathException = net.sf.saxon.trans.XPathException;
7

    
8
namespace TestRunner
9
{
10
   
11

    
12

    
13
	public class ErrorCollector : IMessageListener {
14

    
15
		private IList<QName> errorCodes = new List<QName>();
16

    
17
		TestOutcome outcome1;
18

    
19
		public ErrorCollector(TestOutcome out1)
20
			: base()
21
		{
22
			outcome1 = out1;
23
		}
24

    
25
		public void Message(XdmNode content, bool terminate, IXmlLocation location)
26
		{
27
			outcome1.AddXslMessage(content);
28
		}
29

    
30
    
31
    public void error(Exception exception) {
32
        addErrorCode(exception);
33
        //super.error(exception);
34
    }
35

    
36

    
37

    
38
    
39
    public void fatalError(Exception exception)  {
40
        addErrorCode(exception);
41
        //super.fatalError(exception);
42
    }
43

    
44
    /**
45
     * Make a clean copy of this ErrorListener. This is necessary because the
46
     * standard error listener is stateful (it remembers how many errors there have been)
47
     *
48
     * @param hostLanguage the host language (not used by this implementation)
49
     * @return a copy of this error listener
50
     */
51
    
52
    public ErrorCollector makeAnother(int hostLanguage) {
53
        return this;
54
    }
55

    
56
    private void addErrorCode(Exception exception) {
57
			if (exception is JXPathException) {
58
            String errorCode = ((JXPathException) exception).getErrorCodeLocalPart();
59
            if (errorCode != null) {
60
                String ns = ((JXPathException) exception).getErrorCodeNamespace();
61
					if (ns != null && !net.sf.saxon.lib.NamespaceConstant.ERR.Equals(ns)) {
62
                    errorCode = "Q{" + ns + "}" + errorCode;
63
                }
64
					errorCodes.Add(new QName(errorCode));
65
            } else {
66
					errorCodes.Add(new QName("ZZZZ9999"));
67
            }
68
        }
69
    }
70

    
71
	public IList<QName> getErrorCodes() {
72
        return errorCodes;
73
    }
74

    
75

    
76
}
77
}
(2-2/19)