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.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 SignalReferenceTag implements Serializable
22  {
23      /** */
24      private static final long serialVersionUID = 20150723L;
25  
26      /** Parameter s. */
27      @SuppressWarnings("checkstyle:visibilitymodifier")
28      Length s = null;
29  
30      /** Parameter t. */
31      @SuppressWarnings("checkstyle:visibilitymodifier")
32      Length t = null;
33  
34      /** Id. */
35      @SuppressWarnings("checkstyle:visibilitymodifier")
36      String id = null;
37  
38      /** Orientation. */
39      @SuppressWarnings("checkstyle:visibilitymodifier")
40      String orientation = null;
41  
42      /**
43       * Parse the attributes of the road.type tag. The sub-elements are parsed in separate classes.
44       * @param node Node; the node with signal information
45       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
46       * @return the constructed SignalTag
47       * @throws SAXException when parsing of the tag fails
48       * @throws NetworkException when parsing of the tag fails
49       */
50      @SuppressWarnings("checkstyle:needbraces")
51      static SignalReferenceTag parseSignalReference(final Node node, final OpenDriveNetworkLaneParser parser)
52              throws SAXException, NetworkException
53      {
54          SignalReferenceTag signaReferencelTag = new SignalReferenceTag();
55          NamedNodeMap attributes = node.getAttributes();
56  
57          Node s = attributes.getNamedItem("s");
58          if (s != null)
59              signaReferencelTag.s = new Length(Double.parseDouble(s.getNodeValue().trim()), LengthUnit.METER);
60  
61          Node t = attributes.getNamedItem("t");
62          if (t != null)
63              signaReferencelTag.t = new Length(Double.parseDouble(t.getNodeValue().trim()), LengthUnit.METER);
64  
65          Node id = attributes.getNamedItem("id");
66          if (id != null)
67              signaReferencelTag.id = id.getNodeValue().trim();
68  
69          Node orientation = attributes.getNamedItem("orientation");
70          if (orientation != null)
71              signaReferencelTag.orientation = orientation.getNodeValue().trim();
72  
73          return signaReferencelTag;
74  
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public final String toString()
80      {
81          return "SignalReferenceTag [s=" + this.s + ", t=" + this.t + ", id=" + this.id + ", orientation=" + this.orientation
82                  + "]";
83      }
84  }