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.djunits.value.vdouble.scalar.Frequency;
8 import org.djunits.value.vdouble.scalar.LinearDensity;
9 import org.opentrafficsim.core.network.NetworkException;
10 import org.opentrafficsim.core.network.factory.xml.units.DurationUnits;
11 import org.opentrafficsim.core.network.factory.xml.units.LengthUnits;
12 import org.w3c.dom.NamedNodeMap;
13 import org.w3c.dom.Node;
14 import org.w3c.dom.NodeList;
15 import org.xml.sax.SAXException;
16
17
18
19
20
21
22
23
24
25
26 class ShortestRouteTag implements Serializable
27 {
28
29 private static final long serialVersionUID = 20150723L;
30
31
32 @SuppressWarnings("checkstyle:visibilitymodifier")
33 String name = null;
34
35
36 @SuppressWarnings("checkstyle:visibilitymodifier")
37 NodeTag from = null;
38
39
40 @SuppressWarnings("checkstyle:visibilitymodifier")
41 List<NodeTag> via = new ArrayList<NodeTag>();
42
43
44 @SuppressWarnings("checkstyle:visibilitymodifier")
45 NodeTag to = null;
46
47
48 @SuppressWarnings("checkstyle:visibilitymodifier")
49 Frequency costPerTime = null;
50
51
52 @SuppressWarnings("checkstyle:visibilitymodifier")
53 LinearDensity costPerDistance = null;
54
55
56
57
58
59
60
61
62 @SuppressWarnings("checkstyle:needbraces")
63 static void parseShortestRoutes(final NodeList nodeList, final VissimNetworkLaneParser parser)
64 throws SAXException, NetworkException
65 {
66 for (Node node : XMLParser.getNodes(nodeList, "SHORTESTROUTE"))
67 {
68 NamedNodeMap attributes = node.getAttributes();
69 ShortestRouteTag shortestRouteTag = new ShortestRouteTag();
70
71 if (attributes.getNamedItem("NAME") == null)
72 {
73 throw new SAXException("SHORTESTROUTE: missing attribute NAME");
74 }
75 shortestRouteTag.name = attributes.getNamedItem("NAME").getNodeValue().trim();
76 if (parser.getRouteTags().keySet().contains(shortestRouteTag.name))
77 {
78 throw new SAXException("SHORTESTROUTE: NAME " + shortestRouteTag.name + " defined twice");
79 }
80
81 if (attributes.getNamedItem("FROM") == null)
82 {
83 throw new SAXException("SHORTESTROUTE: missing attribute FROM");
84 }
85 String fromNode = attributes.getNamedItem("FROM").getNodeValue().trim();
86 if (!parser.getNodeTags().containsKey(fromNode))
87 {
88 throw new SAXException("SHORTESTROUTE " + shortestRouteTag.name + ": FROM node " + fromNode + " not found");
89 }
90 shortestRouteTag.from = parser.getNodeTags().get(fromNode);
91
92 if (attributes.getNamedItem("NODELIST") != null)
93 {
94 String viaNodes = attributes.getNamedItem("NODELIST").getNodeValue().trim();
95 shortestRouteTag.via = NodeTag.parseNodeList(viaNodes, parser);
96 }
97
98 if (attributes.getNamedItem("TO") == null)
99 {
100 throw new SAXException("SHORTESTROUTE: missing attribute TO");
101 }
102 String toNode = attributes.getNamedItem("TO").getNodeValue().trim();
103 if (!parser.getNodeTags().containsKey(toNode.trim()))
104 {
105 throw new SAXException("SHORTESTROUTE " + shortestRouteTag.name + ": TO node " + toNode + " not found");
106 }
107 shortestRouteTag.to = parser.getNodeTags().get(toNode);
108
109 Node distanceCost = attributes.getNamedItem("DISTANCECOST");
110 if (distanceCost == null)
111 {
112 throw new SAXException("SHORTESTROUTE: missing attribute DISTANCECOST");
113 }
114 shortestRouteTag.costPerDistance = LengthUnits.parseLinearDensity(distanceCost.getNodeValue().trim());
115
116 Node timeCost = attributes.getNamedItem("TIMECOST");
117 if (timeCost == null)
118 {
119 throw new SAXException("SHORTESTROUTE: missing attribute TIMECOST");
120 }
121 shortestRouteTag.costPerTime = DurationUnits.parseFrequency(timeCost.getNodeValue().trim());
122
123 parser.getShortestRouteTags().put(shortestRouteTag.name.trim(), shortestRouteTag);
124 }
125 }
126
127
128 @Override
129 public final String toString()
130 {
131 return "ShortestRouteTag [name=" + this.name + ", from=" + this.from + ", via=" + this.via + ", to=" + this.to
132 + ", costPerTime=" + this.costPerTime + ", costPerDistance=" + this.costPerDistance + "]";
133 }
134 }