View Javadoc
1   package org.opentrafficsim.road.network.factory.opendrive;
2   
3   import java.io.Serializable;
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   import org.opentrafficsim.core.network.NetworkException;
8   import org.w3c.dom.NamedNodeMap;
9   import org.w3c.dom.Node;
10  import org.xml.sax.SAXException;
11  
12  /**
13   * <p>
14   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * <p>
17   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
18   * initial version Jul 23, 2015 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  class LaneTag implements Serializable
22  {
23  
24      /** */
25      private static final long serialVersionUID = 20150723L;
26  
27      /** Id of the lane. */
28      @SuppressWarnings("checkstyle:visibilitymodifier")
29      Integer id = null;
30  
31      /** Type */
32      @SuppressWarnings("checkstyle:visibilitymodifier")
33      String type = null;
34  
35      /** Level */
36      @SuppressWarnings("checkstyle:visibilitymodifier")
37      String level = null;
38  
39      /** Successor lane Id. */
40      @SuppressWarnings("checkstyle:visibilitymodifier")
41      String successorId = null;
42  
43      /** Predecessor lane Id. */
44      @SuppressWarnings("checkstyle:visibilitymodifier")
45      String predecessorId = null;
46  
47      /** Width Tag */
48      @SuppressWarnings("checkstyle:visibilitymodifier")
49      List<WidthTag> widthTags = new ArrayList<>();
50  
51      /** RoadMark Tag */
52      @SuppressWarnings("checkstyle:visibilitymodifier")
53      List<RoadMarkTag> roadMarkTags = new ArrayList<>();
54  
55      /** Speed Tag */
56      @SuppressWarnings("checkstyle:visibilitymodifier")
57      List<SpeedTag> speedTags = new ArrayList<>();
58  
59      /** Height Tag */
60      @SuppressWarnings("checkstyle:visibilitymodifier")
61      HeightTag heightTag = null;
62  
63      /**
64       * Parse the attributes of the road tag. The sub-elements are parsed in separate classes.
65       * @param node Node; the top-level road node
66       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
67       * @return the generated RoadTag for further reference
68       * @throws SAXException when parsing of the tag fails
69       * @throws NetworkException when parsing of the tag fails
70       */
71      @SuppressWarnings("checkstyle:needbraces")
72      static LaneTag parseLane(final Node node, final OpenDriveNetworkLaneParser parser) throws SAXException, NetworkException
73      {
74          NamedNodeMap attributes = node.getAttributes();
75          LaneTag laneTag = new LaneTag();
76  
77          Node id = attributes.getNamedItem("id");
78          if (id == null)
79              throw new SAXException("LANE: missing attribute id");
80          laneTag.id = Integer.parseInt(id.getNodeValue().trim());
81  
82          Node type = attributes.getNamedItem("type");
83          if (type == null)
84              throw new SAXException("LANE: missing attribute type");
85          laneTag.type = type.getNodeValue().trim();
86  
87          Node level = attributes.getNamedItem("level");
88          if (level == null)
89              throw new SAXException("LANE: missing attribute level");
90          laneTag.level = level.getNodeValue().trim();
91  
92          for (Node link : XMLParser.getNodes(node.getChildNodes(), "link"))
93          {
94              NamedNodeMap attributes1 = link.getAttributes();
95  
96              for (Node successor : XMLParser.getNodes(link.getChildNodes(), "successor"))
97              {
98                  NamedNodeMap attributes2 = successor.getAttributes();
99                  Node successorId = attributes2.getNamedItem("id");
100                 laneTag.successorId = successorId.getNodeValue().trim();
101             }
102 
103             for (Node predecessor : XMLParser.getNodes(link.getChildNodes(), "predecessor"))
104             {
105                 NamedNodeMap attributes2 = predecessor.getAttributes();
106                 Node predecessorId = attributes2.getNamedItem("id");
107                 laneTag.predecessorId = predecessorId.getNodeValue().trim();
108             }
109         }
110 
111         WidthTag.parseWidth(node.getChildNodes(), parser, laneTag);
112         RoadMarkTag.parseRoadMark(node.getChildNodes(), parser, laneTag);
113         SpeedTag.parseSpeed(node.getChildNodes(), parser, laneTag);
114         HeightTag.parseHeight(node.getChildNodes(), parser, laneTag);
115 
116         return laneTag;
117     }
118 
119     /** {@inheritDoc} */
120     @Override
121     public final String toString()
122     {
123         return "LaneTag [id=" + this.id + ", type=" + this.type + ", level=" + this.level + ", successorId=" + this.successorId
124                 + ", predecessorId=" + this.predecessorId + ", widthTags=" + this.widthTags + ", roadMarkTags="
125                 + this.roadMarkTags + ", speedTags=" + this.speedTags + ", heightTag=" + this.heightTag + "]";
126     }
127 }