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.EErrorLevel;
23 import com.helger.commons.error.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 @Nullable
48 public IPSErrorHandler getNestedErrorHandler ()
49 {
50 return m_aNestedErrorHandler;
51 }
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 protected abstract void handle (@Nullable IReadableResource aRes,
70 @Nonnull IErrorLevel aErrorLevel,
71 @Nullable IPSElement aSourceElement,
72 @Nonnull String sMessage,
73 @Nullable Throwable t);
74
75 public final void warn (@Nullable final IReadableResource aRes,
76 @Nullable final IPSElement aSourceElement,
77 @Nonnull final String sMessage)
78 {
79 handle (aRes, EErrorLevel.WARN, aSourceElement, sMessage, (Throwable) null);
80
81
82 final IPSErrorHandler aNestedErrorHandler = getNestedErrorHandler ();
83 if (aNestedErrorHandler != null)
84 aNestedErrorHandler.warn (aRes, aSourceElement, sMessage);
85 }
86
87 public final void error (@Nullable final IPSElement aSourceElement, @Nonnull final String sMessage)
88 {
89 error ((IReadableResource) null, aSourceElement, sMessage, (Throwable) null);
90 }
91
92 public final void error (@Nullable final IReadableResource aRes,
93 @Nullable final IPSElement aSourceElement,
94 @Nonnull final String sMessage,
95 @Nullable final Throwable t)
96 {
97 handle (aRes, EErrorLevel.ERROR, aSourceElement, sMessage, t);
98
99
100 final IPSErrorHandler aNestedErrorHandler = getNestedErrorHandler ();
101 if (aNestedErrorHandler != null)
102 aNestedErrorHandler.error (aRes, aSourceElement, sMessage, t);
103 }
104
105 @Override
106 public String toString ()
107 {
108 return new ToStringGenerator (this).appendIfNotNull ("nestedErrorHandler", m_aNestedErrorHandler).toString ();
109 }
110 }