1 /**
2 * Copyright (C) 2014-2018 Philip Helger (www.helger.com)
3 * philip[at]helger[dot]com
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package com.helger.schematron.svrl;
18
19 import java.io.Serializable;
20
21 import javax.annotation.Nonnull;
22 import javax.annotation.Nullable;
23
24 import org.oclc.purl.dsdl.svrl.FailedAssert;
25 import org.oclc.purl.dsdl.svrl.SuccessfulReport;
26
27 import com.helger.commons.ValueEnforcer;
28 import com.helger.commons.annotation.DevelopersNote;
29 import com.helger.commons.error.level.IErrorLevel;
30 import com.helger.commons.string.StringHelper;
31
32 /**
33 * Interface that helps in determining an error level from SVRL elements.
34 *
35 * @author Philip Helger
36 */
37 @FunctionalInterface
38 public interface ISVRLErrorLevelDeterminator extends Serializable
39 {
40 /**
41 * Get the error level associated with a single failed assertion/successful
42 * report.
43 *
44 * @param sFlag
45 * The flag to be queried. May be <code>null</code>.
46 * @return The error level and never <code>null</code>.
47 */
48 @Nonnull
49 @Deprecated
50 @DevelopersNote ("Use getErrorLevelFromString instead")
51 default IErrorLevel getErrorLevelFromFlag (@Nullable final String sFlag)
52 {
53 return getErrorLevelFromString (sFlag);
54 }
55
56 /**
57 * Get the error level associated with a single failed assertion/successful
58 * report.
59 *
60 * @param sValue
61 * The value to be queried. May be <code>null</code>.
62 * @return The error level and never <code>null</code>.
63 * @since 5.0.2
64 */
65 @Nonnull
66 IErrorLevel getErrorLevelFromString (@Nullable String sValue);
67
68 /**
69 * Get the error level associated with a single failed assertion.
70 *
71 * @param aFailedAssert
72 * The failed assert to be queried. May not be <code>null</code>.
73 * @return The error level and never <code>null</code>.
74 */
75 @Nonnull
76 default IErrorLevel getErrorLevelFromFailedAssert (@Nonnull final FailedAssert aFailedAssert)
77 {
78 ValueEnforcer.notNull (aFailedAssert, "FailedAssert");
79
80 // First try "flag" (for backwards compatibility)
81 String sValue = aFailedAssert.getFlag ();
82 if (StringHelper.hasNoText (sValue))
83 {
84 // Fall back to "role"
85 sValue = aFailedAssert.getRole ();
86 }
87 return getErrorLevelFromString (sValue);
88 }
89
90 /**
91 * Get the error level associated with a single successful report.
92 *
93 * @param aSuccessfulReport
94 * The failed assert to be queried. May not be <code>null</code>.
95 * @return The error level and never <code>null</code>.
96 */
97 @Nonnull
98 default IErrorLevel getErrorLevelFromSuccessfulReport (@Nonnull final SuccessfulReport aSuccessfulReport)
99 {
100 ValueEnforcer.notNull (aSuccessfulReport, "SuccessfulReport");
101
102 // First try "flag" (for backwards compatibility)
103 String sValue = aSuccessfulReport.getFlag ();
104 if (StringHelper.hasNoText (sValue))
105 {
106 // Fall back to "role"
107 sValue = aSuccessfulReport.getRole ();
108 }
109 return getErrorLevelFromString (sValue);
110 }
111 }