1 package org.opentrafficsim.road.network.factory.xml;
2
3 import static org.opentrafficsim.core.gtu.GTUType.VEHICLE;
4
5 import java.io.Serializable;
6
7 import org.opentrafficsim.core.gtu.GTUException;
8 import org.opentrafficsim.core.gtu.GTUType;
9 import org.opentrafficsim.core.network.NetworkException;
10 import org.w3c.dom.NamedNodeMap;
11 import org.w3c.dom.Node;
12 import org.w3c.dom.NodeList;
13 import org.xml.sax.SAXException;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 class GTUTypeTag implements Serializable
37 {
38
39 private static final long serialVersionUID = 20160925L;
40
41
42 @SuppressWarnings("checkstyle:visibilitymodifier")
43 String name = null;
44
45
46
47
48
49
50
51
52 @SuppressWarnings("checkstyle:needbraces")
53 static void parseGTUTypes(final NodeList nodeList, final XmlNetworkLaneParser parser)
54 throws SAXException, NetworkException, GTUException
55 {
56 for (Node node : XMLParser.getNodes(nodeList, "GTUTYPE"))
57 {
58 NamedNodeMap attributes = node.getAttributes();
59 GTUTypeTag gtuTypeTag = new GTUTypeTag();
60
61 Node name = attributes.getNamedItem("NAME");
62 if (name == null)
63 throw new SAXException("GTUTYPE: missing attribute NAME");
64 gtuTypeTag.name = name.getNodeValue().trim();
65 if (parser.gtuTypes.keySet().contains(gtuTypeTag.name))
66 throw new SAXException("GTUTYPE: NAME " + gtuTypeTag.name + " defined twice");
67
68 GTUType gtuType = new GTUType(gtuTypeTag.name, VEHICLE);
69 parser.gtuTypes.put(gtuTypeTag.name, gtuType);
70 }
71 }
72
73
74 @Override
75 public final String toString()
76 {
77 return "GTUTypeTag [name=" + this.name + "]";
78 }
79
80 }