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.opentrafficsim.core.network.route.Route;
9 import org.w3c.dom.NamedNodeMap;
10 import org.w3c.dom.Node;
11 import org.w3c.dom.NodeList;
12 import org.xml.sax.SAXException;
13
14
15
16
17
18
19
20
21
22
23 class RouteTag implements Serializable
24 {
25
26 private static final long serialVersionUID = 20150723L;
27
28
29 @SuppressWarnings("checkstyle:visibilitymodifier")
30 String name = null;
31
32
33 @SuppressWarnings("checkstyle:visibilitymodifier")
34 List<NodeTag> routeNodeTags = new ArrayList<NodeTag>();
35
36
37 @SuppressWarnings("checkstyle:visibilitymodifier")
38 Route route;
39
40
41
42
43
44
45
46
47 @SuppressWarnings("checkstyle:needbraces")
48 static void parseRoutes(final NodeList nodeList, final VissimNetworkLaneParser parser) throws SAXException, NetworkException
49 {
50 for (Node node : XMLParser.getNodes(nodeList, "ROUTE"))
51 {
52 NamedNodeMap attributes = node.getAttributes();
53 RouteTag routeTag = new RouteTag();
54
55 if (attributes.getNamedItem("NAME") == null)
56 {
57 throw new SAXException("ROUTE: missing attribute NAME");
58 }
59 routeTag.name = attributes.getNamedItem("NAME").getNodeValue().trim();
60 if (parser.getRouteTags().keySet().contains(routeTag.name))
61 {
62 throw new SAXException("ROUTE: NAME " + routeTag.name + " defined twice");
63 }
64
65 if (attributes.getNamedItem("NODELIST") == null)
66 {
67 throw new SAXException("ROUTE " + routeTag.name + ": missing attribute NODELIST");
68 }
69 String routeNodes = attributes.getNamedItem("NODELIST").getNodeValue().trim();
70 routeTag.routeNodeTags = NodeTag.parseNodeList(routeNodes, parser);
71
72 parser.getRouteTags().put(routeTag.name, routeTag);
73 }
74 }
75
76
77
78
79
80 void makeRoute() throws NetworkException
81 {
82 this.route = new Route(this.name);
83 for (NodeTag nodeTag : this.routeNodeTags)
84 {
85 this.route.addNode(nodeTag.node);
86 }
87 }
88
89
90 @Override
91 public final String toString()
92 {
93 return "RouteTag [name=" + this.name + ", routeNodeTags=" + this.routeNodeTags + ", route=" + this.route + "]";
94 }
95 }