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 java.util.List;
20
21 import javax.annotation.Nonnull;
22 import javax.annotation.Nullable;
23
24 import com.helger.commons.annotation.ReturnsMutableCopy;
25 import com.helger.commons.error.IErrorLevel;
26 import com.helger.commons.error.IResourceError;
27 import com.helger.commons.error.IResourceErrorGroup;
28 import com.helger.commons.error.ResourceError;
29 import com.helger.commons.error.ResourceErrorGroup;
30 import com.helger.commons.error.ResourceLocation;
31 import com.helger.commons.io.resource.IReadableResource;
32 import com.helger.commons.lang.ClassHelper;
33 import com.helger.commons.state.EChange;
34 import com.helger.commons.string.ToStringGenerator;
35 import com.helger.schematron.pure.model.IPSElement;
36 import com.helger.schematron.pure.model.IPSHasID;
37
38
39
40
41
42
43
44 public class CollectingPSErrorHandler extends AbstractPSErrorHandler
45 {
46 private final ResourceErrorGroup m_aErrors = new ResourceErrorGroup ();
47
48 public CollectingPSErrorHandler ()
49 {
50 super ();
51 }
52
53 public CollectingPSErrorHandler (@Nullable final IPSErrorHandler aNestedErrorHandler)
54 {
55 super (aNestedErrorHandler);
56 }
57
58 @Override
59 protected void handle (@Nullable final IReadableResource aRes,
60 @Nonnull final IErrorLevel aErrorLevel,
61 @Nullable final IPSElement aSourceElement,
62 @Nonnull final String sMessage,
63 @Nullable final Throwable t)
64 {
65 String sField = "";
66 if (aSourceElement != null)
67 {
68 sField += ClassHelper.getClassLocalName (aSourceElement);
69 if (aSourceElement instanceof IPSHasID && ((IPSHasID) aSourceElement).hasID ())
70 sField += " [ID=" + ((IPSHasID) aSourceElement).getID () + "]";
71 }
72 final ResourceLocation aLocation = new ResourceLocation (aRes == null ? null : aRes.getResourceID (), sField);
73 m_aErrors.addResourceError (new ResourceError (aLocation, aErrorLevel, sMessage, t));
74 }
75
76 @Nonnull
77 @ReturnsMutableCopy
78 public IResourceErrorGroup getResourceErrors ()
79 {
80 return m_aErrors.getClone ();
81 }
82
83 @Nonnull
84 public List <IResourceError> getAllResourceErrors ()
85 {
86 return m_aErrors.getAllResourceErrors ();
87 }
88
89 @Nonnull
90 @ReturnsMutableCopy
91 public IResourceErrorGroup getAllFailures ()
92 {
93 return m_aErrors.getAllFailures ();
94 }
95
96 @Nonnull
97 @ReturnsMutableCopy
98 public IResourceErrorGroup getAllErrors ()
99 {
100 return m_aErrors.getAllErrors ();
101 }
102
103
104
105
106
107
108
109 @Nonnull
110 public EChange clearResourceErrors ()
111 {
112 return m_aErrors.clear ();
113 }
114
115
116
117
118
119 public boolean isEmpty ()
120 {
121 return m_aErrors.isEmpty ();
122 }
123
124 @Override
125 public String toString ()
126 {
127 return ToStringGenerator.getDerived (super.toString ()).appendIfNotNull ("errors", m_aErrors).toString ();
128 }
129 }