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 SignalTag 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      /** Name. */
39      @SuppressWarnings("checkstyle:visibilitymodifier")
40      String name = null;
41  
42      /** Dynamic. */
43      @SuppressWarnings("checkstyle:visibilitymodifier")
44      String dynamic = null;
45  
46      /** Orientation. */
47      @SuppressWarnings("checkstyle:visibilitymodifier")
48      String orientation = null;
49  
50      /** The zOffset. */
51      @SuppressWarnings("checkstyle:visibilitymodifier")
52      Length zOffset = null;
53  
54      /** Country. */
55      @SuppressWarnings("checkstyle:visibilitymodifier")
56      String country = null;
57  
58      /** Type. */
59      @SuppressWarnings("checkstyle:visibilitymodifier")
60      String type = null;
61  
62      /** Sub type. */
63      @SuppressWarnings("checkstyle:visibilitymodifier")
64      String subtype = null;
65  
66      /** Value. */
67      @SuppressWarnings("checkstyle:visibilitymodifier")
68      String value = null;
69  
70      /**
71       * Parse the attributes of the road.type tag. The sub-elements are parsed in separate classes.
72       * @param node Node; the node with signal information
73       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
74       * @return the constructed SignalTag
75       * @throws SAXException when parsing of the tag fails
76       * @throws NetworkException when parsing of the tag fails
77       */
78      @SuppressWarnings("checkstyle:needbraces")
79      static SignalTag parseSignal(final Node node, final OpenDriveNetworkLaneParser parser) throws SAXException, NetworkException
80      {
81          SignalTag signalTag = new SignalTag();
82          NamedNodeMap attributes = node.getAttributes();
83  
84          Node s = attributes.getNamedItem("s");
85          if (s != null)
86              signalTag.s = new Length(Double.parseDouble(s.getNodeValue().trim()), LengthUnit.METER);
87  
88          Node t = attributes.getNamedItem("t");
89          if (t != null)
90              signalTag.t = new Length(Double.parseDouble(t.getNodeValue().trim()), LengthUnit.METER);
91  
92          Node id = attributes.getNamedItem("id");
93          if (id != null)
94              signalTag.id = id.getNodeValue().trim();
95  
96          Node name = attributes.getNamedItem("name");
97          if (name != null)
98              signalTag.name = name.getNodeValue().trim();
99  
100         Node dynamic = attributes.getNamedItem("dynamic");
101         if (dynamic != null)
102             signalTag.dynamic = dynamic.getNodeValue().trim();
103 
104         Node orientation = attributes.getNamedItem("orientation");
105         if (orientation != null)
106             signalTag.orientation = orientation.getNodeValue().trim();
107 
108         Node zOffset = attributes.getNamedItem("zOffset");
109         if (zOffset != null)
110             signalTag.zOffset = new Length(Double.parseDouble(zOffset.getNodeValue().trim()), LengthUnit.METER);
111 
112         Node country = attributes.getNamedItem("country");
113         if (country != null)
114             signalTag.country = country.getNodeValue().trim();
115 
116         Node type = attributes.getNamedItem("type");
117         if (type != null)
118             signalTag.type = type.getNodeValue().trim();
119 
120         Node subtype = attributes.getNamedItem("subtype");
121         if (subtype != null)
122             signalTag.subtype = subtype.getNodeValue().trim();
123 
124         Node value = attributes.getNamedItem("value");
125         if (value != null)
126             signalTag.value = value.getNodeValue().trim();
127 
128         return signalTag;
129 
130     }
131 
132     /** {@inheritDoc} */
133     @Override
134     public final String toString()
135     {
136         return "SignalTag [s=" + this.s + ", t=" + this.t + ", id=" + this.id + ", name=" + this.name + ", dynamic="
137                 + this.dynamic + ", orientation=" + this.orientation + ", zOffset=" + this.zOffset + ", country=" + this.country
138                 + ", type=" + this.type + ", subtype=" + this.subtype + ", value=" + this.value + "]";
139     }
140 }