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 javax.annotation.Nonnull;
20 import javax.annotation.concurrent.ThreadSafe;
21
22 import org.oclc.purl.dsdl.svrl.FailedAssert;
23 import org.oclc.purl.dsdl.svrl.SchematronOutputType;
24 import org.oclc.purl.dsdl.svrl.SuccessfulReport;
25
26 import com.helger.commons.ValueEnforcer;
27 import com.helger.commons.annotation.PresentForCodeCoverage;
28 import com.helger.commons.annotation.ReturnsMutableCopy;
29 import com.helger.commons.collection.ext.CommonsArrayList;
30 import com.helger.commons.collection.ext.ICommonsList;
31 import com.helger.commons.concurrent.SimpleReadWriteLock;
32 import com.helger.commons.error.IErrorLevel;
33
34
35
36
37
38
39 @ThreadSafe
40 public final class SVRLHelper
41 {
42 private static final SimpleReadWriteLock s_aRWLock = new SimpleReadWriteLock ();
43
44 private static ISVRLErrorLevelDeterminator s_aELD = new DefaultSVRLErrorLevelDeterminator ();
45
46 @PresentForCodeCoverage
47 private static final SVRLHelper s_aInstance = new SVRLHelper ();
48
49 private SVRLHelper ()
50 {}
51
52
53
54
55
56
57
58
59 @Nonnull
60 @ReturnsMutableCopy
61 public static ICommonsList <SVRLFailedAssert> getAllFailedAssertions (@Nonnull final SchematronOutputType aSchematronOutput)
62 {
63 final ICommonsList <SVRLFailedAssert> ret = new CommonsArrayList <> ();
64 for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
65 if (aObj instanceof FailedAssert)
66 ret.add (new SVRLFailedAssert ((FailedAssert) aObj));
67 return ret;
68 }
69
70
71
72
73
74
75
76
77
78
79
80 @Nonnull
81 @ReturnsMutableCopy
82 public static ICommonsList <SVRLFailedAssert> getAllFailedAssertionsMoreOrEqualSevereThan (@Nonnull final SchematronOutputType aSchematronOutput,
83 @Nonnull final IErrorLevel aErrorLevel)
84 {
85 final ICommonsList <SVRLFailedAssert> ret = new CommonsArrayList <> ();
86 for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
87 if (aObj instanceof FailedAssert)
88 {
89 final SVRLFailedAssert aFA = new SVRLFailedAssert ((FailedAssert) aObj);
90 if (aFA.getFlag ().isMoreOrEqualSevereThan (aErrorLevel))
91 ret.add (aFA);
92 }
93 return ret;
94 }
95
96
97
98
99
100
101
102
103 @Nonnull
104 @ReturnsMutableCopy
105 public static ICommonsList <SVRLSuccessfulReport> getAllSuccessfulReports (@Nonnull final SchematronOutputType aSchematronOutput)
106 {
107 final ICommonsList <SVRLSuccessfulReport> ret = new CommonsArrayList <> ();
108 for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
109 if (aObj instanceof SuccessfulReport)
110 ret.add (new SVRLSuccessfulReport ((SuccessfulReport) aObj));
111 return ret;
112 }
113
114
115
116
117
118
119
120
121
122
123
124 @Nonnull
125 @ReturnsMutableCopy
126 public static ICommonsList <SVRLSuccessfulReport> getAllSuccessfulReportsMoreOrEqualSevereThan (@Nonnull final SchematronOutputType aSchematronOutput,
127 @Nonnull final IErrorLevel aErrorLevel)
128 {
129 final ICommonsList <SVRLSuccessfulReport> ret = new CommonsArrayList <> ();
130 for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
131 if (aObj instanceof SuccessfulReport)
132 {
133 final SVRLSuccessfulReport aFA = new SVRLSuccessfulReport ((SuccessfulReport) aObj);
134 if (aFA.getFlag ().isMoreOrEqualSevereThan (aErrorLevel))
135 ret.add (aFA);
136 }
137 return ret;
138 }
139
140
141
142
143
144
145
146
147 @Nonnull
148 public static IErrorLevel getErrorLevelFromFailedAssert (@Nonnull final FailedAssert aFailedAssert)
149 {
150 return getErrorLevelDeterminator ().getErrorLevelFromFailedAssert (aFailedAssert);
151 }
152
153
154
155
156
157
158
159
160 @Nonnull
161 public static IErrorLevel getErrorLevelFromSuccessfulReport (@Nonnull final SuccessfulReport aSuccessfulReport)
162 {
163 return getErrorLevelDeterminator ().getErrorLevelFromSuccessfulReport (aSuccessfulReport);
164 }
165
166 @Nonnull
167 public static ISVRLErrorLevelDeterminator getErrorLevelDeterminator ()
168 {
169 return s_aRWLock.readLocked ( () -> s_aELD);
170 }
171
172 public static void setErrorLevelDeterminator (@Nonnull final ISVRLErrorLevelDeterminator aELD)
173 {
174 ValueEnforcer.notNull (aELD, "ErrorLevelDeterminator");
175
176 s_aRWLock.readLocked ( () -> s_aELD = aELD);
177 }
178 }