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 java.util.Map;
20
21 import javax.annotation.Nonnull;
22 import javax.annotation.Nullable;
23 import javax.annotation.concurrent.NotThreadSafe;
24
25 import com.helger.commons.ValueEnforcer;
26 import com.helger.commons.annotation.ReturnsMutableCopy;
27 import com.helger.commons.collection.CollectionHelper;
28 import com.helger.commons.collection.ext.CommonsLinkedHashMap;
29 import com.helger.commons.collection.ext.ICommonsOrderedMap;
30 import com.helger.commons.string.StringHelper;
31 import com.helger.commons.string.ToStringGenerator;
32 import com.helger.schematron.CSchematron;
33 import com.helger.schematron.CSchematronXML;
34 import com.helger.schematron.pure.errorhandler.IPSErrorHandler;
35 import com.helger.xml.microdom.IMicroElement;
36 import com.helger.xml.microdom.MicroElement;
37
38
39
40
41
42
43
44
45
46
47
48
49
50 @NotThreadSafe
51 public class PSValueOf implements IPSClonableElement <PSValueOf>, IPSHasForeignAttributes
52 {
53 private String m_sSelect;
54 private ICommonsOrderedMap <String, String> m_aForeignAttrs;
55
56 public PSValueOf ()
57 {}
58
59 public boolean isValid (@Nonnull final IPSErrorHandler aErrorHandler)
60 {
61 if (StringHelper.hasNoText (m_sSelect))
62 {
63 aErrorHandler.error (this, "<value-of> has no 'select'");
64 return false;
65 }
66 return true;
67 }
68
69 public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
70 {
71 if (StringHelper.hasNoText (m_sSelect))
72 aErrorHandler.error (this, "<value-of> has no 'select'");
73 }
74
75 public boolean isMinimal ()
76 {
77 return true;
78 }
79
80 public void addForeignAttribute (@Nonnull final String sAttrName, @Nonnull final String sAttrValue)
81 {
82 ValueEnforcer.notNull (sAttrName, "AttrName");
83 ValueEnforcer.notNull (sAttrValue, "AttrValue");
84 if (m_aForeignAttrs == null)
85 m_aForeignAttrs = new CommonsLinkedHashMap <> ();
86 m_aForeignAttrs.put (sAttrName, sAttrValue);
87 }
88
89 public boolean hasForeignAttributes ()
90 {
91 return m_aForeignAttrs != null && m_aForeignAttrs.isNotEmpty ();
92 }
93
94 @Nonnull
95 @ReturnsMutableCopy
96 public ICommonsOrderedMap <String, String> getAllForeignAttributes ()
97 {
98 return new CommonsLinkedHashMap <> (m_aForeignAttrs);
99 }
100
101
102
103
104
105
106
107 public void setSelect (@Nullable final String sSelect)
108 {
109 m_sSelect = sSelect;
110 }
111
112
113
114
115 @Nullable
116 public String getSelect ()
117 {
118 return m_sSelect;
119 }
120
121 @Nonnull
122 public IMicroElement getAsMicroElement ()
123 {
124 final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_VALUE_OF);
125 ret.setAttribute (CSchematronXML.ATTR_SELECT, m_sSelect);
126 if (m_aForeignAttrs != null)
127 for (final Map.Entry <String, String> aEntry : m_aForeignAttrs.entrySet ())
128 ret.setAttribute (aEntry.getKey (), aEntry.getValue ());
129 return ret;
130 }
131
132 @Nonnull
133 public PSValueOf getClone ()
134 {
135 final PSValueOf ret = new PSValueOf ();
136 ret.setSelect (m_sSelect);
137 if (hasForeignAttributes ())
138 ret.addForeignAttributes (m_aForeignAttrs);
139 return ret;
140 }
141
142 @Override
143 public String toString ()
144 {
145 return new ToStringGenerator (this).appendIfNotNull ("select", m_sSelect)
146 .appendIf ("foreignAttrs", m_aForeignAttrs, CollectionHelper::isNotEmpty)
147 .getToString ();
148 }
149 }