View Javadoc
1   package org.opentrafficsim.road.network.factory.vissim;
2   
3   import java.io.Serializable;
4   
5   import org.opentrafficsim.core.network.NetworkException;
6   import org.w3c.dom.NamedNodeMap;
7   import org.w3c.dom.Node;
8   import org.xml.sax.SAXException;
9   
10  /**
11   * <p>
12   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14   * <p>
15   * $LastChangedDate: 2019-01-06 01:39:32 +0100 (Sun, 06 Jan 2019) $, @version $Revision: 4833 $, by $Author: averbraeck $,
16   * initial version Jul 23, 2015 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   */
19  class SinkTag implements Serializable
20  {
21      /** */
22      private static final long serialVersionUID = 20150723L;
23  
24      /** Position of the sink on the link, relative to the design line, stored as a string to parse when the length is known. */
25      @SuppressWarnings("checkstyle:visibilitymodifier")
26      String positionStr = null;
27  
28      /**
29       * Parse the SINK tag.
30       * @param node Node; the SINK node to parse
31       * @param parser VissimNetworkLaneParser; the parser with the lists of information
32       * @param linkTag LinkTag; the parent LINK tag
33       * @throws SAXException when parsing of the tag fails
34       * @throws NetworkException when parsing of the tag fails
35       */
36      @SuppressWarnings("checkstyle:needbraces")
37      static void parseSink(final Node node, final VissimNetworkLaneParser parser, final LinkTag linkTag)
38              throws SAXException, NetworkException
39      {
40          NamedNodeMap attributes = node.getAttributes();
41          SinkTag sinkTag = new SinkTag();
42  
43          if (attributes.getNamedItem("LANE") == null)
44          {
45              throw new SAXException("SINK: missing attribute LANE" + " for link " + linkTag.name);
46          }
47          String laneName = attributes.getNamedItem("LANE").getNodeValue().trim();
48          if (linkTag.roadLayoutTag == null)
49          {
50              throw new NetworkException("SINK: LANE " + laneName + " no ROADTYPE for link " + linkTag.name);
51          }
52          CrossSectionElementTag cseTag = linkTag.roadLayoutTag.cseTags.get(laneName);
53          if (cseTag == null)
54          {
55              throw new NetworkException("SINK: LANE " + laneName + " not found in elements of link " + linkTag.name
56                      + " - roadtype " + linkTag.roadLayoutTag.name);
57          }
58          if (cseTag.elementType != org.opentrafficsim.road.network.factory.vissim.CrossSectionElementTag.ElementType.LANE)
59          {
60              throw new NetworkException("SINK: LANE " + laneName + " not a real GTU lane for link " + linkTag.name
61                      + " - roadtype " + linkTag.roadLayoutTag.name);
62          }
63          if (linkTag.generatorTags.containsKey(laneName))
64          {
65              throw new SAXException("SINK for LANE with NAME " + laneName + " defined twice");
66          }
67  
68          Node position = attributes.getNamedItem("POSITION");
69          if (position == null)
70          {
71              throw new NetworkException("SINK: POSITION element not found in elements of link " + linkTag.name + " - roadtype "
72                      + linkTag.roadLayoutTag.name);
73          }
74          sinkTag.positionStr = position.getNodeValue().trim();
75  
76          linkTag.sinkTags.put(laneName, sinkTag);
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public final String toString()
82      {
83          return "SinkTag [positionStr=" + this.positionStr + "]";
84      }
85  }