1 package org.opentrafficsim.road.network.factory.xml.old;
2
3 import java.io.Serializable;
4 import java.net.URI;
5 import java.net.URISyntaxException;
6
7 import org.djunits.unit.SpeedUnit;
8 import org.djunits.value.vdouble.scalar.Speed;
9 import org.opentrafficsim.core.network.NetworkException;
10 import org.opentrafficsim.core.network.factory.xml.units.Distributions;
11 import org.opentrafficsim.core.units.distributions.ContinuousDistDoubleScalar;
12 import org.opentrafficsim.road.network.factory.xml.old.CrossSectionElementTag.ElementType;
13 import org.w3c.dom.NamedNodeMap;
14 import org.w3c.dom.Node;
15 import org.xml.sax.SAXException;
16
17
18
19
20
21
22
23
24
25
26 class ListGeneratorTag implements Serializable
27 {
28
29 private static final long serialVersionUID = 20150723L;
30
31
32 @SuppressWarnings("checkstyle:visibilitymodifier")
33 URI uri = null;
34
35
36 @SuppressWarnings("checkstyle:visibilitymodifier")
37 String positionStr = null;
38
39
40 @SuppressWarnings("checkstyle:visibilitymodifier")
41 GTUTag gtuTag = null;
42
43
44 @SuppressWarnings("checkstyle:visibilitymodifier")
45 GTUMixTag gtuMixTag = null;
46
47
48 @SuppressWarnings("checkstyle:visibilitymodifier")
49 ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> initialSpeedDist = null;
50
51
52 @SuppressWarnings("checkstyle:visibilitymodifier")
53 String gtuColorer;
54
55
56
57
58
59
60
61
62
63 @SuppressWarnings("checkstyle:needbraces")
64 static void parseListGenerator(final Node node, final XmlNetworkLaneParserOld parser, final LinkTag linkTag)
65 throws SAXException, NetworkException
66 {
67 NamedNodeMap attributes = node.getAttributes();
68 ListGeneratorTag listGeneratorTag = new ListGeneratorTag();
69
70 if (attributes.getNamedItem("URI") == null)
71 throw new SAXException("LISTGENERATOR: missing attribute URI" + " for link " + linkTag.name);
72 String uriStr = attributes.getNamedItem("URI").getNodeValue().trim();
73 try
74 {
75 listGeneratorTag.uri = new URI(uriStr);
76 }
77 catch (URISyntaxException exception)
78 {
79 throw new NetworkException("LISTGENERATOR: URI " + uriStr + " is not valid", exception);
80 }
81
82 if (attributes.getNamedItem("LANE") == null)
83 throw new SAXException("LISTGENERATOR: missing attribute LANE" + " for link " + linkTag.name);
84 String laneName = attributes.getNamedItem("LANE").getNodeValue().trim();
85 if (linkTag.roadLayoutTag == null)
86 throw new NetworkException("LISTGENERATOR: LANE " + laneName + " no ROADTYPE for link " + linkTag.name);
87 CrossSectionElementTag cseTag = linkTag.roadLayoutTag.cseTags.get(laneName);
88 if (cseTag == null)
89 throw new NetworkException("LISTGENERATOR: LANE " + laneName + " not found in elements of link " + linkTag.name
90 + " - roadtype " + linkTag.roadLayoutTag.name);
91 if (cseTag.elementType != ElementType.LANE)
92 throw new NetworkException("LISTGENERATOR: LANE " + laneName + " not a real GTU lane for link " + linkTag.name
93 + " - roadtype " + linkTag.roadLayoutTag.name);
94 if (linkTag.generatorTags.containsKey(laneName))
95 throw new SAXException("LISTGENERATOR for LANE with NAME " + laneName + " defined twice");
96
97 Node position = attributes.getNamedItem("POSITION");
98 if (position == null)
99 throw new NetworkException("LISTGENERATOR: POSITION element not found in elements of link " + linkTag.name
100 + " - roadtype " + linkTag.roadLayoutTag.name);
101 listGeneratorTag.positionStr = position.getNodeValue().trim();
102
103 if (attributes.getNamedItem("GTU") != null)
104 {
105 String gtuName = attributes.getNamedItem("GTU").getNodeValue().trim();
106 if (!parser.gtuTags.containsKey(gtuName))
107 throw new NetworkException(
108 "LISTGENERATOR: LANE " + laneName + " GTU " + gtuName + " in link " + linkTag.name + " not defined");
109 listGeneratorTag.gtuTag = parser.gtuTags.get(gtuName);
110 }
111
112 if (attributes.getNamedItem("GTUMIX") != null)
113 {
114 String gtuMixName = attributes.getNamedItem("GTUMIX").getNodeValue().trim();
115 if (!parser.gtuMixTags.containsKey(gtuMixName))
116 throw new NetworkException("LISTGENERATOR: LANE " + laneName + " GTUMIX " + gtuMixName + " in link "
117 + linkTag.name + " not defined");
118 listGeneratorTag.gtuMixTag = parser.gtuMixTags.get(gtuMixName);
119 }
120
121 if (listGeneratorTag.gtuTag == null && listGeneratorTag.gtuMixTag == null)
122 throw new SAXException("LISTGENERATOR: missing attribute GTU or GTUMIX for Lane with NAME " + laneName + " of link "
123 + linkTag.name);
124
125 if (listGeneratorTag.gtuTag != null && listGeneratorTag.gtuMixTag != null)
126 throw new SAXException("LISTGENERATOR: both attribute GTU and GTUMIX defined for Lane with NAME " + laneName
127 + " of link " + linkTag.name);
128
129 Node initialSpeed = attributes.getNamedItem("INITIALSPEED");
130 if (initialSpeed == null)
131 throw new SAXException("LISTGENERATOR: missing attribute INITIALSPEED");
132 listGeneratorTag.initialSpeedDist = Distributions.parseSpeedDist(initialSpeed.getNodeValue());
133
134
135
136 linkTag.listGeneratorTags.put(laneName, listGeneratorTag);
137 }
138
139
140 @Override
141 public final String toString()
142 {
143 return "ListGeneratorTag [uri=" + this.uri + ", positionStr=" + this.positionStr + ", gtuTag=" + this.gtuTag
144 + ", gtuMixTag=" + this.gtuMixTag + ", initialSpeedDist=" + this.initialSpeedDist + ", gtuColorer="
145 + this.gtuColorer + "]";
146 }
147 }