View Javadoc
1   package org.opentrafficsim.road.network.factory.opendrive;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.unit.LengthUnit;
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.djunits.value.vdouble.scalar.Speed;
8   import org.opentrafficsim.core.network.NetworkException;
9   import org.w3c.dom.NamedNodeMap;
10  import org.w3c.dom.Node;
11  import org.w3c.dom.NodeList;
12  import org.xml.sax.SAXException;
13  
14  /**
15   * <p>
16   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
18   * <p>
19   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
20   * initial version Jul 23, 2015 <br>
21   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   */
23  class TypeTag implements Serializable
24  {
25      /** */
26      private static final long serialVersionUID = 20150723L;
27  
28      /** Start position (s-coordinate). */
29      @SuppressWarnings("checkstyle:visibilitymodifier")
30      Length s = null;
31  
32      /** Road type. */
33      @SuppressWarnings("checkstyle:visibilitymodifier")
34      String type = null;
35  
36      /** Maximum allowed speed. */
37      @SuppressWarnings("checkstyle:visibilitymodifier")
38      Speed maxSpeed = null;
39  
40      /**
41       * Parse the attributes of the road.type tag. The sub-elements are parsed in separate classes.
42       * @param nodeList NodeList; the list of subnodes of the road node
43       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
44       * @param roadTag RoadTag; the RoadTag to which this element belongs
45       * @throws SAXException when parsing of the tag fails
46       * @throws NetworkException when parsing of the tag fails
47       */
48      @SuppressWarnings("checkstyle:needbraces")
49      static void parseType(final NodeList nodeList, final OpenDriveNetworkLaneParser parser, final RoadTag roadTag)
50              throws SAXException, NetworkException
51      {
52          int typeCount = 0;
53          for (Node node : XMLParser.getNodes(nodeList, "type"))
54          {
55              typeCount++;
56              TypeTag typeTag = new TypeTag();
57              NamedNodeMap attributes = node.getAttributes();
58  
59              Node s = attributes.getNamedItem("s");
60              if (s == null)
61                  throw new SAXException("ROAD.TYPE: missing attribute s for ROAD.ID=" + roadTag.id);
62              typeTag.s = new Length(Double.parseDouble(s.getNodeValue().trim()), LengthUnit.METER);
63  
64              Node type = attributes.getNamedItem("type");
65              if (type == null)
66                  throw new SAXException("ROAD.TYPE: missing attribute type for ROAD.ID=" + roadTag.id);
67              typeTag.type = type.getNodeValue().trim();
68  
69              roadTag.typeTag = typeTag;
70          }
71  
72          if (typeCount > 1)
73              throw new SAXException("ROAD: more than one TYPE tag for road id=" + roadTag.id);
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public final String toString()
79      {
80          return "TypeTag [s=" + this.s + ", type=" + this.type + ", maxSpeed=" + this.maxSpeed + "]";
81      }
82  }