View Javadoc
1   package org.opentrafficsim.road.network.factory.opendrive;
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: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, 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 ControllerTag implements Serializable
20  {
21  
22      /** */
23      private static final long serialVersionUID = 20150723L;
24  
25      /** Id of the lane. */
26      @SuppressWarnings("checkstyle:visibilitymodifier")
27      String id = null;
28  
29      /** Type. */
30      @SuppressWarnings("checkstyle:visibilitymodifier")
31      String type = null;
32  
33      /** Name. */
34      @SuppressWarnings("checkstyle:visibilitymodifier")
35      String name = null;
36  
37      /** Sequence. */
38      @SuppressWarnings("checkstyle:visibilitymodifier")
39      Integer sequence = null;
40  
41      /** Id of the control signal. */
42      @SuppressWarnings("checkstyle:visibilitymodifier")
43      String controlSignalID = null;
44  
45      /** Control type */
46      @SuppressWarnings("checkstyle:visibilitymodifier")
47      String controlType = null;
48  
49      /**
50       * Parse the attributes of the road tag. The sub-elements are parsed in separate classes.
51       * @param node Node; the top-level road node
52       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
53       * @return the generated RoadTag for further reference
54       * @throws SAXException when parsing of the tag fails
55       * @throws NetworkException when parsing of the tag fails
56       */
57      @SuppressWarnings("checkstyle:needbraces")
58      static ControllerTag parseController(final Node node, final OpenDriveNetworkLaneParser parser)
59              throws SAXException, NetworkException
60      {
61          NamedNodeMap attributes = node.getAttributes();
62          ControllerTag controllerTag = new ControllerTag();
63  
64          Node id = attributes.getNamedItem("id");
65          if (id == null)
66              throw new SAXException("LANE: missing attribute id");
67          controllerTag.id = id.getNodeValue().trim();
68  
69          Node type = attributes.getNamedItem("type");
70          if (type != null)
71              controllerTag.type = type.getNodeValue().trim();
72  
73          Node name = attributes.getNamedItem("name");
74          if (name != null)
75              controllerTag.name = name.getNodeValue().trim();
76  
77          Node sequence = attributes.getNamedItem("sequence");
78          if (sequence == null)
79              throw new SAXException("LANE: missing attribute sequence");
80          controllerTag.sequence = Integer.parseInt(sequence.getNodeValue().trim());
81  
82          for (Node control : XMLParser.getNodes(node.getChildNodes(), "control"))
83          {
84              NamedNodeMap attributes1 = control.getAttributes();
85  
86              Node signalId = attributes1.getNamedItem("signalId");
87              controllerTag.controlSignalID = signalId.getNodeValue().trim();
88  
89              Node controlType = attributes1.getNamedItem("type");
90              controllerTag.controlType = controlType.getNodeValue().trim();
91          }
92  
93          return controllerTag;
94      }
95  
96      /** {@inheritDoc} */
97      @Override
98      public final String toString()
99      {
100         return "ControllerTag [id=" + this.id + ", type=" + this.type + ", name=" + this.name + ", sequence=" + this.sequence
101                 + ", controlSignalID=" + this.controlSignalID + ", controlType=" + this.controlType + "]";
102     }
103 }