1 package org.opentrafficsim.road.network.factory.opendrive;
2
3 import java.io.Serializable;
4
5 import org.djunits.unit.LengthUnit;
6 import org.djunits.value.vdouble.scalar.Length;
7 import org.djunits.value.vdouble.scalar.Speed;
8 import org.opentrafficsim.core.network.NetworkException;
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 TypeTag implements Serializable
24 {
25
26 private static final long serialVersionUID = 20150723L;
27
28
29 @SuppressWarnings("checkstyle:visibilitymodifier")
30 Length s = null;
31
32
33 @SuppressWarnings("checkstyle:visibilitymodifier")
34 String type = null;
35
36
37 @SuppressWarnings("checkstyle:visibilitymodifier")
38 Speed maxSpeed = null;
39
40
41
42
43
44
45
46
47
48 @SuppressWarnings("checkstyle:needbraces")
49 static void parseType(final NodeList nodeList, final OpenDriveNetworkLaneParser parser, final RoadTag roadTag)
50 throws SAXException, NetworkException
51 {
52 int typeCount = 0;
53 for (Node node : XMLParser.getNodes(nodeList, "type"))
54 {
55 typeCount++;
56 TypeTag typeTag = new TypeTag();
57 NamedNodeMap attributes = node.getAttributes();
58
59 Node s = attributes.getNamedItem("s");
60 if (s == null)
61 throw new SAXException("ROAD.TYPE: missing attribute s for ROAD.ID=" + roadTag.id);
62 typeTag.s = new Length(Double.parseDouble(s.getNodeValue().trim()), LengthUnit.METER);
63
64 Node type = attributes.getNamedItem("type");
65 if (type == null)
66 throw new SAXException("ROAD.TYPE: missing attribute type for ROAD.ID=" + roadTag.id);
67 typeTag.type = type.getNodeValue().trim();
68
69 roadTag.typeTag = typeTag;
70 }
71
72 if (typeCount > 1)
73 throw new SAXException("ROAD: more than one TYPE tag for road id=" + roadTag.id);
74 }
75
76
77 @Override
78 public final String toString()
79 {
80 return "TypeTag [s=" + this.s + ", type=" + this.type + ", maxSpeed=" + this.maxSpeed + "]";
81 }
82 }