View Javadoc
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   * Connector.
14   * <p>
15   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 16 aug. 2018 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
22   */
23  public class ConnectorTag implements Serializable
24  {
25  
26      /** */
27      private static final long serialVersionUID = 20180816L;
28  
29      /** Name. */
30      String name = null;
31  
32      /** From node tag. */
33      NodeTag nodeStartTag = null;
34  
35      /** To node tag. */
36      NodeTag nodeEndTag = null;
37  
38      /** Demand weight. */
39      Double demandWeight = null;
40  
41      /** Resulting connector link. */
42      Link connector;
43  
44      /**
45       * Parse the CONNECTOR tags.
46       * @param nodeList NodeList; nodeList the top-level nodes of the XML-file
47       * @param parser XmlNetworkLaneParserOld; the parser with the lists of information
48       * @throws SAXException when parsing of the tag fails
49       * @throws NetworkException when parsing of the tag fails
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  }