1 package org.opentrafficsim.road.network.factory.xml.old;
2
3 import java.io.Serializable;
4 import java.util.List;
5
6 import org.djunits.value.vdouble.scalar.Acceleration;
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.djunits.value.vdouble.scalar.Speed;
9 import org.opentrafficsim.core.network.NetworkException;
10 import org.opentrafficsim.core.network.factory.xml.units.AccelerationUnits;
11 import org.opentrafficsim.core.network.factory.xml.units.LengthUnits;
12 import org.opentrafficsim.core.network.factory.xml.units.SpeedUnits;
13 import org.w3c.dom.NamedNodeMap;
14 import org.w3c.dom.Node;
15 import org.w3c.dom.NodeList;
16 import org.xml.sax.SAXException;
17
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
45
46
47
48
49
50
51
52
53
54
55
56
57 class GlobalTag implements Serializable
58 {
59
60 private static final long serialVersionUID = 20150723L;
61
62
63 @SuppressWarnings("checkstyle:visibilitymodifier")
64 Speed speedGTUColorerMaxSpeed = null;
65
66
67 @SuppressWarnings("checkstyle:visibilitymodifier")
68 Acceleration accelerationGTUColorerMaxDeceleration = null;
69
70
71 @SuppressWarnings("checkstyle:visibilitymodifier")
72 Acceleration accelerationGTUColorerMaxAcceleration = null;
73
74
75 @SuppressWarnings("checkstyle:visibilitymodifier")
76 Length laneChangeUrgeGTUColorerMinLaneChangeDistance = null;
77
78
79 @SuppressWarnings("checkstyle:visibilitymodifier")
80 Length laneChangeUrgeGTUColorerHorizon = null;
81
82
83
84
85
86
87
88 @SuppressWarnings("checkstyle:needbraces")
89 static void parseGlobal(final NodeList nodeList, final XmlNetworkLaneParserOld parser) throws NetworkException, SAXException
90 {
91 List<Node> nodes = XMLParser.getNodes(nodeList, "GLOBAL");
92 if (nodes.size() > 1)
93 throw new SAXException("GLOBAL: More than one tag GLOBAL in the XML-file");
94 if (nodes.size() == 1)
95 {
96 Node node = nodes.get(0);
97
98 parser.globalTag = new GlobalTag();
99
100
101 List<Node> speedGTUColorerNodes = XMLParser.getNodes(node.getChildNodes(), "SPEEDGTUCOLORER");
102 if (speedGTUColorerNodes.size() > 1)
103 throw new SAXException("GLOBAL: More than one tag SPEEDGTUCOLORER in the XML-file");
104 if (speedGTUColorerNodes.size() == 1)
105 {
106 Node speedGTUColorerNode = nodes.get(0);
107 NamedNodeMap speedGTUColorerAttributes = speedGTUColorerNode.getAttributes();
108 if (speedGTUColorerAttributes.getNamedItem("MAXSPEED") == null)
109 throw new SAXException("GLOBAL: No attribute MAXSPEED for the tag SPEEDGTUCOLORER");
110 parser.globalTag.speedGTUColorerMaxSpeed =
111 SpeedUnits.parseSpeed(speedGTUColorerAttributes.getNamedItem("MAXSPEED").getNodeValue());
112 }
113
114
115 List<Node> accelerationGTUColorerNodes = XMLParser.getNodes(node.getChildNodes(), "ACCELERATIONGTUCOLORER");
116 if (accelerationGTUColorerNodes.size() > 1)
117 throw new SAXException("GLOBAL: More than one tag ACCELERATIONGTUCOLORER in the XML-file");
118 if (accelerationGTUColorerNodes.size() == 1)
119 {
120 Node accelerationGTUColorerNode = nodes.get(0);
121 NamedNodeMap accelerationGTUColorerAttributes = accelerationGTUColorerNode.getAttributes();
122 if (accelerationGTUColorerAttributes.getNamedItem("MAXDECELERATION") == null)
123 throw new SAXException("GLOBAL: No attribute MAXDECELERATION for the tag ACCELERATIONGTUCOLORER");
124 parser.globalTag.accelerationGTUColorerMaxDeceleration = AccelerationUnits
125 .parseAcceleration(accelerationGTUColorerAttributes.getNamedItem("MAXDECELERATION").getNodeValue());
126 if (accelerationGTUColorerAttributes.getNamedItem("MAXACCELERATION") == null)
127 throw new SAXException("GLOBAL: No attribute MAXACCELERATION for the tag ACCELERATIONGTUCOLORER");
128 parser.globalTag.accelerationGTUColorerMaxAcceleration = AccelerationUnits
129 .parseAcceleration(accelerationGTUColorerAttributes.getNamedItem("MAXACCELERATION").getNodeValue());
130 }
131
132
133 List<Node> lcuGTUColorerNodes = XMLParser.getNodes(node.getChildNodes(), "LANECHANGEURGEGTUCOLORER");
134 if (lcuGTUColorerNodes.size() > 1)
135 throw new SAXException("GLOBAL: More than one tag LANECHANGEURGEGTUCOLORER in the XML-file");
136 if (lcuGTUColorerNodes.size() == 1)
137 {
138 Node lcuGTUColorerNode = nodes.get(0);
139 NamedNodeMap lcuGTUColorerAttributes = lcuGTUColorerNode.getAttributes();
140 if (lcuGTUColorerAttributes.getNamedItem("MINLANECHANGEDISTANCE") == null)
141 throw new SAXException("GLOBAL: No attribute MINLANECHANGEDISTANCE for the tag LANECHANGEURGEGTUCOLORER");
142 parser.globalTag.laneChangeUrgeGTUColorerMinLaneChangeDistance =
143 LengthUnits.parseLength(lcuGTUColorerAttributes.getNamedItem("MINLANECHANGEDISTANCE").getNodeValue());
144 if (lcuGTUColorerAttributes.getNamedItem("HORIZON") == null)
145 throw new SAXException("GLOBAL: No attribute HORIZON for the tag LANECHANGEURGEGTUCOLORER");
146 parser.globalTag.laneChangeUrgeGTUColorerHorizon =
147 LengthUnits.parseLength(lcuGTUColorerAttributes.getNamedItem("HORIZON").getNodeValue());
148 }
149 }
150 }
151
152
153 @Override
154 public String toString()
155 {
156 return "GlobalTag [speedGTUColorerMaxSpeed=" + this.speedGTUColorerMaxSpeed + ", accelerationGTUColorerMaxDeceleration="
157 + this.accelerationGTUColorerMaxDeceleration + ", accelerationGTUColorerMaxAcceleration="
158 + this.accelerationGTUColorerMaxAcceleration + ", laneChangeUrgeGTUColorerMinLaneChangeDistance="
159 + this.laneChangeUrgeGTUColorerMinLaneChangeDistance + ", laneChangeUrgeGTUColorerHorizon="
160 + this.laneChangeUrgeGTUColorerHorizon + "]";
161 }
162
163 }