1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.helger.schematron.svrl;
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.concurrent.locks.ReadWriteLock;
22 import java.util.concurrent.locks.ReentrantReadWriteLock;
23
24 import javax.annotation.Nonnull;
25 import javax.annotation.concurrent.ThreadSafe;
26
27 import org.oclc.purl.dsdl.svrl.FailedAssert;
28 import org.oclc.purl.dsdl.svrl.SchematronOutputType;
29 import org.oclc.purl.dsdl.svrl.SuccessfulReport;
30
31 import com.helger.commons.ValueEnforcer;
32 import com.helger.commons.annotation.PresentForCodeCoverage;
33 import com.helger.commons.annotation.ReturnsMutableCopy;
34 import com.helger.commons.error.IErrorLevel;
35
36
37
38
39
40
41 @ThreadSafe
42 public final class SVRLHelper
43 {
44 private static final ReadWriteLock s_aRWLock = new ReentrantReadWriteLock ();
45
46 private static ISVRLErrorLevelDeterminator s_aELD = new DefaultSVRLErrorLevelDeterminator ();
47
48 @PresentForCodeCoverage
49 private static final SVRLHelper s_aInstance = new SVRLHelper ();
50
51 private SVRLHelper ()
52 {}
53
54
55
56
57
58
59
60
61 @Nonnull
62 @ReturnsMutableCopy
63 public static List <SVRLFailedAssert> getAllFailedAssertions (@Nonnull final SchematronOutputType aSchematronOutput)
64 {
65 final List <SVRLFailedAssert> ret = new ArrayList <SVRLFailedAssert> ();
66 for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
67 if (aObj instanceof FailedAssert)
68 ret.add (new SVRLFailedAssert ((FailedAssert) aObj));
69 return ret;
70 }
71
72
73
74
75
76
77
78
79
80
81
82 @Nonnull
83 @ReturnsMutableCopy
84 public static List <SVRLFailedAssert> getAllFailedAssertionsMoreOrEqualSevereThan (@Nonnull final SchematronOutputType aSchematronOutput,
85 @Nonnull final IErrorLevel aErrorLevel)
86 {
87 final List <SVRLFailedAssert> ret = new ArrayList <SVRLFailedAssert> ();
88 for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
89 if (aObj instanceof FailedAssert)
90 {
91 final SVRLFailedAssert aFA = new SVRLFailedAssert ((FailedAssert) aObj);
92 if (aFA.getFlag ().isMoreOrEqualSevereThan (aErrorLevel))
93 ret.add (aFA);
94 }
95 return ret;
96 }
97
98
99
100
101
102
103
104
105 @Nonnull
106 @ReturnsMutableCopy
107 public static List <SVRLSuccessfulReport> getAllSuccessfulReports (@Nonnull final SchematronOutputType aSchematronOutput)
108 {
109 final List <SVRLSuccessfulReport> ret = new ArrayList <SVRLSuccessfulReport> ();
110 for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
111 if (aObj instanceof SuccessfulReport)
112 ret.add (new SVRLSuccessfulReport ((SuccessfulReport) aObj));
113 return ret;
114 }
115
116
117
118
119
120
121
122
123
124
125
126 @Nonnull
127 @ReturnsMutableCopy
128 public static List <SVRLSuccessfulReport> getAllSuccessfulReportsMoreOrEqualSevereThan (@Nonnull final SchematronOutputType aSchematronOutput,
129 @Nonnull final IErrorLevel aErrorLevel)
130 {
131 final List <SVRLSuccessfulReport> ret = new ArrayList <SVRLSuccessfulReport> ();
132 for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
133 if (aObj instanceof SuccessfulReport)
134 {
135 final SVRLSuccessfulReport aFA = new SVRLSuccessfulReport ((SuccessfulReport) aObj);
136 if (aFA.getFlag ().isMoreOrEqualSevereThan (aErrorLevel))
137 ret.add (aFA);
138 }
139 return ret;
140 }
141
142
143
144
145
146
147
148
149 @Nonnull
150 public static IErrorLevel getErrorLevelFromFailedAssert (@Nonnull final FailedAssert aFailedAssert)
151 {
152 return getErrorLevelDeterminator ().getErrorLevelFromFailedAssert (aFailedAssert);
153 }
154
155
156
157
158
159
160
161
162 @Nonnull
163 public static IErrorLevel getErrorLevelFromSuccessfulReport (@Nonnull final SuccessfulReport aSuccessfulReport)
164 {
165 return getErrorLevelDeterminator ().getErrorLevelFromSuccessfulReport (aSuccessfulReport);
166 }
167
168 @Nonnull
169 public static ISVRLErrorLevelDeterminator getErrorLevelDeterminator ()
170 {
171 s_aRWLock.readLock ().lock ();
172 try
173 {
174 return s_aELD;
175 }
176 finally
177 {
178 s_aRWLock.readLock ().unlock ();
179 }
180 }
181
182 public static void setErrorLevelDeterminator (@Nonnull final ISVRLErrorLevelDeterminator aELD)
183 {
184 ValueEnforcer.notNull (aELD, "ErrorLevelDeterminator");
185
186 s_aRWLock.readLock ().lock ();
187 try
188 {
189 s_aELD = aELD;
190 }
191 finally
192 {
193 s_aRWLock.readLock ().unlock ();
194 }
195 }
196 }