1 package org.opentrafficsim.road.network.factory.xml.old;
2
3 import java.io.Serializable;
4
5 import org.djunits.unit.LengthUnit;
6 import org.djunits.unit.SpeedUnit;
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.djunits.value.vdouble.scalar.Speed;
9 import org.opentrafficsim.core.gtu.GTUException;
10 import org.opentrafficsim.core.gtu.GTUType;
11 import org.opentrafficsim.core.network.NetworkException;
12 import org.opentrafficsim.core.network.factory.xml.units.Distributions;
13 import org.opentrafficsim.core.units.distributions.ContinuousDistDoubleScalar;
14 import org.w3c.dom.NamedNodeMap;
15 import org.w3c.dom.Node;
16 import org.w3c.dom.NodeList;
17 import org.xml.sax.SAXException;
18
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 public class GTUTag implements Serializable
45 {
46
47 private static final long serialVersionUID = 20150723L;
48
49
50 @SuppressWarnings("checkstyle:visibilitymodifier")
51 String name = null;
52
53
54 @SuppressWarnings("checkstyle:visibilitymodifier")
55 GTUType gtuType = null;
56
57
58 @SuppressWarnings("checkstyle:visibilitymodifier")
59 ContinuousDistDoubleScalar.Rel<Length, LengthUnit> lengthDist = null;
60
61
62 @SuppressWarnings("checkstyle:visibilitymodifier")
63 ContinuousDistDoubleScalar.Rel<Length, LengthUnit> widthDist = null;
64
65
66 @SuppressWarnings("checkstyle:visibilitymodifier")
67 ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> maxSpeedDist = null;
68
69
70
71
72
73
74
75
76 @SuppressWarnings("checkstyle:needbraces")
77 static void parseGTUs(final NodeList nodeList, final XmlNetworkLaneParserOld parser)
78 throws SAXException, NetworkException, GTUException
79 {
80 for (Node node : XMLParser.getNodes(nodeList, "GTU"))
81 {
82 NamedNodeMap attributes = node.getAttributes();
83 GTUTag gtuTag = new GTUTag();
84
85 Node name = attributes.getNamedItem("NAME");
86 if (name == null)
87 throw new SAXException("GTU: missing attribute NAME");
88 gtuTag.name = name.getNodeValue().trim();
89 if (parser.gtuTags.keySet().contains(gtuTag.name))
90 throw new SAXException("GTU: NAME " + gtuTag.name + " defined twice");
91
92 Node gtuType = attributes.getNamedItem("GTUTYPE");
93 if (gtuType == null)
94 throw new SAXException("GTU: missing attribute GTUTYPE");
95 if (!parser.gtuTypes.containsKey(gtuType.getNodeValue().trim()))
96 throw new SAXException("GTU: GTUTYPE " + gtuType.getNodeValue().trim() + " not defined");
97 gtuTag.gtuType = parser.gtuTypes.get(gtuType.getNodeValue().trim());
98
99 Node length = attributes.getNamedItem("LENGTH");
100 if (length == null)
101 throw new SAXException("GTU: missing attribute LENGTH");
102 gtuTag.lengthDist = Distributions.parseLengthDist(length.getNodeValue());
103
104 Node width = attributes.getNamedItem("WIDTH");
105 if (width == null)
106 throw new SAXException("GTU: missing attribute WIDTH");
107 gtuTag.widthDist = Distributions.parseLengthDist(width.getNodeValue());
108
109 Node maxSpeed = attributes.getNamedItem("MAXSPEED");
110 if (maxSpeed == null)
111 throw new SAXException("GTU: missing attribute MAXSPEED");
112 gtuTag.maxSpeedDist = Distributions.parseSpeedDist(maxSpeed.getNodeValue());
113
114 parser.gtuTags.put(gtuTag.name, gtuTag);
115 }
116 }
117
118
119 @Override
120 public final String toString()
121 {
122 return "GTUTag [name=" + this.name + ", gtuType=" + this.gtuType + ", lengthDist=" + this.lengthDist + ", widthDist="
123 + this.widthDist + ", followingModel=" + ", maxSpeedDist=" + this.maxSpeedDist + "]";
124 }
125
126 }