1 package org.opentrafficsim.road.network.factory.xml.old;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.opentrafficsim.core.network.NetworkException;
8 import org.w3c.dom.NamedNodeMap;
9 import org.w3c.dom.Node;
10 import org.w3c.dom.NodeList;
11 import org.xml.sax.SAXException;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 class GTUMixTag implements Serializable
43 {
44
45 private static final long serialVersionUID = 20150723L;
46
47
48 @SuppressWarnings("checkstyle:visibilitymodifier")
49 String name = null;
50
51
52 @SuppressWarnings("checkstyle:visibilitymodifier")
53 List<GTUTag> gtus = new ArrayList<GTUTag>();
54
55
56 @SuppressWarnings("checkstyle:visibilitymodifier")
57 List<Double> weights = new ArrayList<Double>();
58
59
60
61
62
63
64
65
66 @SuppressWarnings("checkstyle:needbraces")
67 static void parseGTUMix(final NodeList nodeList, final XmlNetworkLaneParserOld parser) throws SAXException, NetworkException
68 {
69 for (Node node : XMLParser.getNodes(nodeList, "GTUMIX"))
70 {
71 NamedNodeMap attributes = node.getAttributes();
72 GTUMixTag gtuMixTag = new GTUMixTag();
73
74 Node name = attributes.getNamedItem("NAME");
75 if (name == null)
76 throw new SAXException("GTUMIX: missing attribute NAME");
77 gtuMixTag.name = name.getNodeValue().trim();
78 if (parser.gtuMixTags.keySet().contains(gtuMixTag.name))
79 throw new SAXException("GTUMIX: NAME " + gtuMixTag.name + " defined twice");
80
81 List<Node> gtuList = XMLParser.getNodes(node.getChildNodes(), "GTU");
82 if (gtuList.size() == 0)
83 throw new SAXException("GTUMIX: missing tag GTU");
84 for (Node gtuNode : gtuList)
85 {
86 parseGTUMixGTUTag(gtuNode, parser, gtuMixTag);
87 }
88
89 parser.gtuMixTags.put(gtuMixTag.name, gtuMixTag);
90 }
91 }
92
93
94
95
96
97
98
99
100
101 @SuppressWarnings("checkstyle:needbraces")
102 private static void parseGTUMixGTUTag(final Node gtuNode, final XmlNetworkLaneParserOld parser, final GTUMixTag gtuMixTag)
103 throws NetworkException, SAXException
104 {
105 NamedNodeMap attributes = gtuNode.getAttributes();
106
107 Node gtuName = attributes.getNamedItem("NAME");
108 if (gtuName == null)
109 throw new NetworkException("GTUMIX: No GTU NAME defined");
110 if (!parser.gtuTags.containsKey(gtuName.getNodeValue().trim()))
111 throw new NetworkException("GTUMIX: " + gtuMixTag.name + " GTU " + gtuName.getNodeValue().trim() + " not defined");
112 gtuMixTag.gtus.add(parser.gtuTags.get(gtuName.getNodeValue().trim()));
113
114 Node weight = attributes.getNamedItem("WEIGHT");
115 if (weight == null)
116 throw new NetworkException(
117 "GTUMIX: " + gtuMixTag.name + " GTU " + gtuName.getNodeValue().trim() + ": weight not defined");
118 gtuMixTag.weights.add(Double.parseDouble(weight.getNodeValue()));
119 }
120
121
122 @Override
123 public final String toString()
124 {
125 return "GTUMixTag [name=" + this.name + ", gtus=" + this.gtus + ", weights=" + this.weights + "]";
126 }
127
128 }