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