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