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