1 package org.opentrafficsim.road.network.factory.xml.old;
2
3 import java.io.Serializable;
4
5 import org.opentrafficsim.core.network.Link;
6 import org.opentrafficsim.core.network.NetworkException;
7 import org.w3c.dom.NamedNodeMap;
8 import org.w3c.dom.Node;
9 import org.w3c.dom.NodeList;
10 import org.xml.sax.SAXException;
11
12
13
14
15
16
17
18
19
20
21
22
23 public class ConnectorTag implements Serializable
24 {
25
26
27 private static final long serialVersionUID = 20180816L;
28
29
30 String name = null;
31
32
33 NodeTag nodeStartTag = null;
34
35
36 NodeTag nodeEndTag = null;
37
38
39 Double demandWeight = null;
40
41
42 Link connector;
43
44
45
46
47
48
49
50
51 @SuppressWarnings("checkstyle:needbraces")
52 static void parseConnectors(final NodeList nodeList, final XmlNetworkLaneParserOld parser)
53 throws SAXException, NetworkException
54 {
55 for (Node node : XMLParser.getNodes(nodeList, "CONNECTOR"))
56 {
57 NamedNodeMap attributes = node.getAttributes();
58 ConnectorTag connectorTag = new ConnectorTag();
59
60 if (attributes.getNamedItem("NAME") == null)
61 throw new SAXException("CONNECTOR: missing attribute NAME");
62 connectorTag.name = attributes.getNamedItem("NAME").getNodeValue().trim();
63 if (parser.connectorTags.keySet().contains(connectorTag.name)
64 || parser.linkTags.keySet().contains(connectorTag.name))
65 throw new SAXException("CONNECTOR: NAME " + connectorTag.name + " defined twice");
66
67 if (attributes.getNamedItem("NODESTART") == null)
68 throw new SAXException("CONNECTOR: missing attribute NODESTART for connector " + connectorTag.name);
69 String fromNodeStr = attributes.getNamedItem("NODESTART").getNodeValue().trim();
70 connectorTag.nodeStartTag = parser.nodeTags.get(fromNodeStr);
71 if (connectorTag.nodeStartTag == null)
72 throw new SAXException(
73 "CONNECTOR: NODESTART node " + fromNodeStr + " for link " + connectorTag.name + " not defined");
74
75 if (attributes.getNamedItem("NODEEND") == null)
76 throw new SAXException("CONNECTOR: missing attribute NODEEND for link " + connectorTag.name);
77 String toNodeStr = attributes.getNamedItem("NODEEND").getNodeValue().trim();
78 connectorTag.nodeEndTag = parser.nodeTags.get(toNodeStr);
79 if (connectorTag.nodeEndTag == null)
80 throw new SAXException(
81 "CONNECTOR: NODEEND node " + toNodeStr + " for connector " + connectorTag.name + " not defined");
82
83 if (attributes.getNamedItem("DEMANDWEIGHT") != null)
84 connectorTag.demandWeight = Double.valueOf(attributes.getNamedItem("DEMANDWEIGHT").getNodeValue());
85
86 parser.connectorTags.put(connectorTag.name, connectorTag);
87 }
88 }
89
90 }