1 package org.opentrafficsim.road.network.factory.vissim;
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 class RouteMixTag implements Serializable
23 {
24
25 private static final long serialVersionUID = 20150723L;
26
27
28 @SuppressWarnings("checkstyle:visibilitymodifier")
29 String name = null;
30
31
32 @SuppressWarnings("checkstyle:visibilitymodifier")
33 List<RouteTag> routes = new ArrayList<RouteTag>();
34
35
36 @SuppressWarnings("checkstyle:visibilitymodifier")
37 List<Double> weights = new ArrayList<Double>();
38
39
40
41
42
43
44
45
46 @SuppressWarnings("checkstyle:needbraces")
47 static void parseRouteMix(final NodeList nodeList, final VissimNetworkLaneParser parser)
48 throws SAXException, NetworkException
49 {
50 for (Node node : XMLParser.getNodes(nodeList, "ROUTEMIX"))
51 {
52 NamedNodeMap attributes = node.getAttributes();
53 RouteMixTag routeMixTag = new RouteMixTag();
54
55 if (attributes.getNamedItem("NAME") == null)
56 {
57 throw new SAXException("ROUTEMIX: missing attribute NAME");
58 }
59 routeMixTag.name = attributes.getNamedItem("NAME").getNodeValue().trim();
60 if (parser.getRouteTags().keySet().contains(routeMixTag.name))
61 {
62 throw new SAXException("ROUTEMIX: NAME " + routeMixTag.name + " defined twice");
63 }
64
65 List<Node> routeList = XMLParser.getNodes(node.getChildNodes(), "ROUTE");
66 if (routeList.size() == 0)
67 {
68 throw new SAXException("ROUTEMIX: missing tag ROUTE");
69 }
70 for (Node routeNode : routeList)
71 {
72 parseRouteMixRouteTag(routeNode, parser, routeMixTag);
73 }
74
75 parser.getRouteMixTags().put(routeMixTag.name, routeMixTag);
76 }
77 }
78
79
80
81
82
83
84
85
86
87 @SuppressWarnings("checkstyle:needbraces")
88 private static void parseRouteMixRouteTag(final Node routeNode, final VissimNetworkLaneParser parser,
89 final RouteMixTag routeMixTag) throws NetworkException, SAXException
90 {
91 NamedNodeMap attributes = routeNode.getAttributes();
92
93 Node routeName = attributes.getNamedItem("NAME");
94 if (routeName == null)
95 {
96 throw new NetworkException("ROUTEMIX: No ROUTE NAME defined");
97 }
98 if (!parser.getRouteTags().containsKey(routeName.getNodeValue().trim()))
99 {
100 throw new NetworkException(
101 "ROUTEMIX: " + routeMixTag.name + " ROUTE " + routeName.getNodeValue().trim() + " not defined");
102 }
103 routeMixTag.routes.add(parser.getRouteTags().get(routeName.getNodeValue().trim()));
104
105 Node weight = attributes.getNamedItem("WEIGHT");
106 if (weight == null)
107 {
108 throw new NetworkException(
109 "ROUTEMIX: " + routeMixTag.name + " ROUTE " + routeName.getNodeValue().trim() + ": weight not defined");
110 }
111 routeMixTag.weights.add(Double.parseDouble(weight.getNodeValue()));
112 }
113
114
115 @Override
116 public final String toString()
117 {
118 return "RouteMixTag [name=" + this.name + ", routes=" + this.routes + ", weights=" + this.weights + "]";
119 }
120
121 }