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.io.Serializable;
20 import java.util.List;
21
22 import javax.annotation.Nonnull;
23 import javax.annotation.Nullable;
24
25 import org.oclc.purl.dsdl.svrl.DiagnosticReference;
26
27 import com.helger.commons.annotation.ReturnsMutableCopy;
28 import com.helger.commons.collection.impl.CommonsArrayList;
29 import com.helger.commons.collection.impl.ICommonsList;
30 import com.helger.commons.error.level.IErrorLevel;
31 import com.helger.commons.location.SimpleLocation;
32 import com.helger.commons.string.StringHelper;
33 import com.helger.commons.string.ToStringGenerator;
34 import com.helger.schematron.svrl.SVRLResourceError.SVRLErrorBuilder;
35
36
37
38
39
40
41
42 public abstract class AbstractSVRLMessage implements Serializable
43 {
44 protected ICommonsList <DiagnosticReference> m_aDiagnosticReferences;
45 protected String m_sText;
46 protected String m_sLocation;
47 protected String m_sTest;
48 protected String m_sRole;
49 protected IErrorLevel m_aFlag;
50
51 public AbstractSVRLMessage (@Nullable final List <DiagnosticReference> aDiagnosticReferences,
52 @Nullable final String sText,
53 @Nullable final String sLocation,
54 @Nullable final String sTest,
55 @Nullable final String sRole,
56 @Nullable final IErrorLevel aFlag)
57 {
58 m_aDiagnosticReferences = new CommonsArrayList <> (aDiagnosticReferences);
59 m_sText = StringHelper.trim (sText);
60 m_sLocation = sLocation;
61 m_sTest = sTest;
62 m_sRole = sRole;
63 m_aFlag = aFlag;
64 }
65
66 @Nonnull
67 @ReturnsMutableCopy
68 public ICommonsList <DiagnosticReference> getDiagnisticReferences ()
69 {
70 return m_aDiagnosticReferences.getClone ();
71 }
72
73 @Nullable
74 public String getText ()
75 {
76 return m_sText;
77 }
78
79 @Nullable
80 public String getLocation ()
81 {
82 return m_sLocation;
83 }
84
85 @Nullable
86 public String getTest ()
87 {
88 return m_sTest;
89 }
90
91 @Nullable
92 public String getRole ()
93 {
94 return m_sRole;
95 }
96
97 @Nonnull
98 public IErrorLevel getFlag ()
99 {
100 return m_aFlag;
101 }
102
103 @Nonnull
104 public SVRLResourceError getAsResourceError (@Nullable final String sResourceName)
105 {
106 return new SVRLErrorBuilder (m_sTest).setErrorLevel (m_aFlag)
107 .setErrorFieldName (m_sLocation)
108 .setErrorLocation (new SimpleLocation (sResourceName))
109 .setErrorText (m_sText)
110 .build ();
111 }
112
113 @Override
114 public String toString ()
115 {
116 return new ToStringGenerator (this).append ("diagnosticRefs", m_aDiagnosticReferences)
117 .append ("text", m_sText)
118 .append ("location", m_sLocation)
119 .append ("test", m_sTest)
120 .appendIfNotNull ("role", m_sRole)
121 .append ("flag", m_aFlag)
122 .getToString ();
123 }
124 }