1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.helger.schematron.pure.errorhandler;
18
19 import javax.annotation.Nonnull;
20 import javax.annotation.Nullable;
21
22 import com.helger.commons.error.level.EErrorLevel;
23 import com.helger.commons.error.level.IErrorLevel;
24 import com.helger.commons.io.resource.IReadableResource;
25 import com.helger.commons.string.ToStringGenerator;
26 import com.helger.schematron.pure.model.IPSElement;
27
28
29
30
31
32
33 public abstract class AbstractPSErrorHandler implements IPSErrorHandler
34 {
35 private final IPSErrorHandler m_aNestedErrorHandler;
36
37 protected AbstractPSErrorHandler ()
38 {
39 this (null);
40 }
41
42 protected AbstractPSErrorHandler (@Nullable final IPSErrorHandler aNestedErrorHandler)
43 {
44 m_aNestedErrorHandler = aNestedErrorHandler;
45 }
46
47
48
49
50
51 @Nullable
52 public IPSErrorHandler getNestedErrorHandler ()
53 {
54 return m_aNestedErrorHandler;
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 protected abstract void handle (@Nullable IReadableResource aRes,
74 @Nonnull IErrorLevel aErrorLevel,
75 @Nullable IPSElement aSourceElement,
76 @Nonnull String sMessage,
77 @Nullable Throwable t);
78
79 public final void warn (@Nullable final IReadableResource aRes,
80 @Nullable final IPSElement aSourceElement,
81 @Nonnull final String sMessage)
82 {
83 handle (aRes, EErrorLevel.WARN, aSourceElement, sMessage, (Throwable) null);
84
85
86 final IPSErrorHandler aNestedErrorHandler = getNestedErrorHandler ();
87 if (aNestedErrorHandler != null)
88 aNestedErrorHandler.warn (aRes, aSourceElement, sMessage);
89 }
90
91 public final void error (@Nullable final IReadableResource aRes,
92 @Nullable final IPSElement aSourceElement,
93 @Nonnull final String sMessage,
94 @Nullable final Throwable t)
95 {
96 handle (aRes, EErrorLevel.ERROR, aSourceElement, sMessage, t);
97
98
99 final IPSErrorHandler aNestedErrorHandler = getNestedErrorHandler ();
100 if (aNestedErrorHandler != null)
101 aNestedErrorHandler.error (aRes, aSourceElement, sMessage, t);
102 }
103
104 @Override
105 public String toString ()
106 {
107 return new ToStringGenerator (this).appendIfNotNull ("nestedErrorHandler", m_aNestedErrorHandler).getToString ();
108 }
109 }