1 package org.opentrafficsim.road.network.factory.xml.old;
2
3 import java.io.Serializable;
4 import java.util.LinkedHashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.djunits.value.vdouble.scalar.Length;
9 import org.djunits.value.vdouble.scalar.Speed;
10 import org.opentrafficsim.core.gtu.GTUType;
11 import org.opentrafficsim.core.network.NetworkException;
12 import org.opentrafficsim.core.network.factory.xml.units.LengthUnits;
13 import org.opentrafficsim.core.network.factory.xml.units.SpeedUnits;
14 import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
15 import org.w3c.dom.NamedNodeMap;
16 import org.w3c.dom.Node;
17 import org.w3c.dom.NodeList;
18 import org.xml.sax.SAXException;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 class LaneTypeTag implements Serializable
52 {
53
54 private static final long serialVersionUID = 20150723L;
55
56
57 @SuppressWarnings("checkstyle:visibilitymodifier")
58 String name = null;
59
60
61 @SuppressWarnings("checkstyle:visibilitymodifier")
62 Map<GTUType, Speed> legalSpeedLimits = new LinkedHashMap<>();
63
64
65 @SuppressWarnings("checkstyle:visibilitymodifier")
66 Length defaultLaneWidth = null;
67
68
69 @SuppressWarnings("checkstyle:visibilitymodifier")
70 LaneKeepingPolicy defaultLaneKeepingPolicy = null;
71
72
73
74
75
76
77
78
79 @SuppressWarnings("checkstyle:needbraces")
80 static void parseLaneTypes(final NodeList nodeList, final XmlNetworkLaneParserOld parser)
81 throws SAXException, NetworkException
82 {
83 for (Node node : XMLParser.getNodes(nodeList, "LANETYPE"))
84 {
85 NamedNodeMap attributes = node.getAttributes();
86 LaneTypeTag laneTypeTag = new LaneTypeTag();
87
88 Node name = attributes.getNamedItem("NAME");
89 if (name == null)
90 throw new SAXException("LANETYPE: missing attribute NAME");
91 laneTypeTag.name = name.getNodeValue().trim();
92 if (parser.laneTypeTags.keySet().contains(laneTypeTag.name))
93 throw new SAXException("LANETYPE: NAME " + laneTypeTag.name + " defined twice");
94
95 Node width = attributes.getNamedItem("DEFAULTLANEWIDTH");
96 if (width != null)
97 laneTypeTag.defaultLaneWidth = LengthUnits.parseLength(width.getNodeValue());
98
99 Node lkp = attributes.getNamedItem("DEFAULTLANEKEEPING");
100 if (lkp != null)
101 laneTypeTag.defaultLaneKeepingPolicy = LaneAttributes.parseLaneKeepingPolicy(lkp.getNodeValue().trim());
102
103 List<Node> speedLimitList = XMLParser.getNodes(node.getChildNodes(), "SPEEDLIMIT");
104 if (speedLimitList.size() == 0)
105 throw new SAXException("LANETYPE: missing tag SPEEDLIMIT");
106 for (Node speedLimitNode : speedLimitList)
107 {
108 NamedNodeMap speedLimitAttributes = speedLimitNode.getAttributes();
109
110 Node gtuTypeName = speedLimitAttributes.getNamedItem("GTUTYPE");
111 if (gtuTypeName == null)
112 throw new NetworkException("LANETYPE: No GTUTYPE defined");
113 if (!parser.gtuTypes.containsKey(gtuTypeName.getNodeValue().trim()))
114 throw new NetworkException(
115 "LANETYPE: " + laneTypeTag.name + " GTUTYPE " + gtuTypeName.getNodeValue().trim() + " not defined");
116 GTUType gtuType = parser.gtuTypes.get(gtuTypeName.getNodeValue().trim());
117
118 Node speedNode = speedLimitAttributes.getNamedItem("LEGALSPEEDLIMIT");
119 if (speedNode == null)
120 throw new NetworkException(
121 "LANETYPE: " + laneTypeTag.name + " GTUTYPE " + gtuType.getId() + ": LEGALSPEEDLIMIT not defined");
122 Speed speed = SpeedUnits.parseSpeed(speedNode.getNodeValue().trim());
123
124 laneTypeTag.legalSpeedLimits.put(gtuType, speed);
125 }
126 parser.laneTypeTags.put(laneTypeTag.name, laneTypeTag);
127 }
128 }
129
130 }