1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.helger.schematron.pure.model;
18
19 import javax.annotation.Nonnull;
20 import javax.annotation.Nullable;
21 import javax.annotation.concurrent.NotThreadSafe;
22
23 import com.helger.commons.microdom.IMicroElement;
24 import com.helger.commons.microdom.MicroElement;
25 import com.helger.commons.string.StringHelper;
26 import com.helger.commons.string.ToStringGenerator;
27 import com.helger.schematron.CSchematron;
28 import com.helger.schematron.CSchematronXML;
29 import com.helger.schematron.pure.errorhandler.IPSErrorHandler;
30
31
32
33
34
35
36
37
38
39 @NotThreadSafe
40 public class PSParam implements IPSElement
41 {
42 private String m_sName;
43 private String m_sValue;
44
45 public PSParam ()
46 {}
47
48 public boolean isValid (@Nonnull final IPSErrorHandler aErrorHandler)
49 {
50 if (StringHelper.hasNoText (m_sName))
51 {
52 aErrorHandler.error (this, "<param> has no 'name'");
53 return false;
54 }
55 if (StringHelper.hasNoText (m_sValue))
56 {
57 aErrorHandler.error (this, "<param> has no 'value'");
58 return false;
59 }
60 return true;
61 }
62
63 public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
64 {
65 if (StringHelper.hasNoText (m_sName))
66 aErrorHandler.error (this, "<param> has no 'name'");
67 if (StringHelper.hasNoText (m_sValue))
68 aErrorHandler.error (this, "<param> has no 'value'");
69 }
70
71 public boolean isMinimal ()
72 {
73 return false;
74 }
75
76 public void setName (@Nullable final String sName)
77 {
78 m_sName = sName;
79 }
80
81 @Nullable
82 public String getName ()
83 {
84 return m_sName;
85 }
86
87 public void setValue (@Nullable final String sValue)
88 {
89 if (sValue != null && sValue.length () == 0)
90 throw new IllegalArgumentException ("value may not be empty!");
91 m_sValue = sValue;
92 }
93
94 @Nullable
95 public String getValue ()
96 {
97 return m_sValue;
98 }
99
100 @Nonnull
101 public IMicroElement getAsMicroElement ()
102 {
103 final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_PARAM);
104 ret.setAttribute (CSchematronXML.ATTR_NAME, m_sName);
105 ret.setAttribute (CSchematronXML.ATTR_VALUE, m_sValue);
106 return ret;
107 }
108
109 @Override
110 public String toString ()
111 {
112 return new ToStringGenerator (this).appendIfNotNull ("name", m_sName)
113 .appendIfNotNull ("value", m_sValue)
114 .toString ();
115 }
116 }