View Javadoc
1   package org.opentrafficsim.road.network.factory.opendrive;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.unit.AngleUnit;
6   import org.djunits.unit.LengthUnit;
7   import org.djunits.value.vdouble.scalar.Angle;
8   import org.djunits.value.vdouble.scalar.Length;
9   import org.opentrafficsim.core.network.NetworkException;
10  import org.w3c.dom.NamedNodeMap;
11  import org.w3c.dom.Node;
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  public class HeaderTag implements Serializable
24  {
25      /** */
26      private static final long serialVersionUID = 20150723L;
27  
28      /** Name of the map. */
29      @SuppressWarnings("checkstyle:visibilitymodifier")
30      String name = null;
31  
32      /** Major revision. */
33      @SuppressWarnings("checkstyle:visibilitymodifier")
34      int revMajor = 0;
35  
36      /** Minor revision. */
37      @SuppressWarnings("checkstyle:visibilitymodifier")
38      int revMinor = 0;
39  
40      /** Version of the map. */
41      @SuppressWarnings("checkstyle:visibilitymodifier")
42      String version = null;
43  
44      /** Date of the map. */
45      @SuppressWarnings("checkstyle:visibilitymodifier")
46      String date = null;
47  
48      /** Range of the map in the north */
49      @SuppressWarnings("checkstyle:visibilitymodifier")
50      Length north = null;
51  
52      /** Range of the map in the south */
53      @SuppressWarnings("checkstyle:visibilitymodifier")
54      Length south = null;
55  
56      /** Range of the map in the east */
57      @SuppressWarnings("checkstyle:visibilitymodifier")
58      Length east = null;
59  
60      /** Range of the map in the west */
61      @SuppressWarnings("checkstyle:visibilitymodifier")
62      Length west = null;
63  
64      /** Vendor of the map. */
65      @SuppressWarnings("checkstyle:visibilitymodifier")
66      String vendor = null;
67  
68      /** Origin latitude of the map */
69      @SuppressWarnings("checkstyle:visibilitymodifier")
70      Length originLat = null;
71  
72      /** Origin longitude of the map */
73      @SuppressWarnings("checkstyle:visibilitymodifier")
74      Length originLong = null;
75  
76      /** Origin Hdg of the map */
77      @SuppressWarnings("checkstyle:visibilitymodifier")
78      Angle originHdg = null;
79  
80      /**
81       * Parse the attributes of the junction tag. The sub-elements are parsed in separate classes.
82       * @param node Node; the junction node to parse
83       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
84       * @throws SAXException when parsing of the tag fails
85       * @throws NetworkException when parsing of the tag fails
86       */
87      @SuppressWarnings("checkstyle:needbraces")
88      static void parseHeader(final Node node, final OpenDriveNetworkLaneParser parser) throws SAXException, NetworkException
89      {
90          NamedNodeMap attributes = node.getAttributes();
91          HeaderTag headerTag = new HeaderTag();
92  
93          Node name = attributes.getNamedItem("name");
94          if (name == null)
95              throw new SAXException("Header: missing attribute name");
96          headerTag.name = name.getNodeValue().trim();
97  
98          Node revMajor = attributes.getNamedItem("revMajor");
99          if (revMajor == null)
100             throw new SAXException("Header: missing attribute revMajor");
101         headerTag.revMajor = Integer.parseInt(revMajor.getNodeValue().trim());
102 
103         Node revMinor = attributes.getNamedItem("revMinor");
104         if (revMinor == null)
105             throw new SAXException("Header: missing attribute revMinor");
106         headerTag.revMinor = Integer.parseInt(revMinor.getNodeValue().trim());
107 
108         Node version = attributes.getNamedItem("version");
109         if (version == null)
110             throw new SAXException("Header: missing attribute version");
111         headerTag.version = version.getNodeValue().trim();
112 
113         Node date = attributes.getNamedItem("date");
114         if (date == null)
115             throw new SAXException("Header: missing attribute date");
116         headerTag.date = date.getNodeValue().trim();
117 
118         Node vendor = attributes.getNamedItem("vendor");
119         if (vendor == null)
120             throw new SAXException("Header: missing attribute vendor");
121         headerTag.vendor = vendor.getNodeValue().trim();
122 
123         Node north = attributes.getNamedItem("north");
124         if (north == null)
125             throw new SAXException("Header: missing attribute north");
126         headerTag.north = new Length(Double.parseDouble(north.getNodeValue().trim()), LengthUnit.METER);
127 
128         Node south = attributes.getNamedItem("south");
129         if (south == null)
130             throw new SAXException("Header: missing attribute south");
131         headerTag.south = new Length(Double.parseDouble(south.getNodeValue().trim()), LengthUnit.METER);
132 
133         Node east = attributes.getNamedItem("east");
134         if (east == null)
135             throw new SAXException("Header: missing attribute east");
136         headerTag.east = new Length(Double.parseDouble(east.getNodeValue().trim()), LengthUnit.METER);
137 
138         Node west = attributes.getNamedItem("west");
139         if (west == null)
140             throw new SAXException("Header: missing attribute west");
141         headerTag.west = new Length(Double.parseDouble(west.getNodeValue().trim()), LengthUnit.METER);
142 
143         Node originLat = attributes.getNamedItem("originLat");
144         if (originLat == null)
145             throw new SAXException("Header: missing attribute originLat");
146         headerTag.originLat = new Length(Double.parseDouble(originLat.getNodeValue().trim()), LengthUnit.METER);
147 
148         Node originLong = attributes.getNamedItem("originLong");
149         if (originLong == null)
150             throw new SAXException("Header: missing attribute originLong");
151         headerTag.originLong = new Length(Double.parseDouble(originLong.getNodeValue().trim()), LengthUnit.METER);
152 
153         Node originHdg = attributes.getNamedItem("originHdg");
154         if (originHdg == null)
155             throw new SAXException("Header: missing attribute originHdg");
156         headerTag.originHdg = new Angle(Double.parseDouble(originHdg.getNodeValue().trim()), AngleUnit.DEGREE);
157 
158         parser.headerTag = headerTag;
159     }
160 
161     /**
162      * @return originLat
163      */
164     public Length getOriginLat()
165     {
166         return this.originLat;
167     }
168 
169     /**
170      * @return originLong
171      */
172     public Length getOriginLong()
173     {
174         return this.originLong;
175     }
176 
177     /** {@inheritDoc} */
178     @Override
179     public final String toString()
180     {
181         return "HeaderTag [name=" + this.name + ", revMajor=" + this.revMajor + ", revMinor=" + this.revMinor + ", version="
182                 + this.version + ", date=" + this.date + ", north=" + this.north + ", south=" + this.south + ", east="
183                 + this.east + ", west=" + this.west + ", vendor=" + this.vendor + ", originLat=" + this.originLat
184                 + ", originLong=" + this.originLong + ", originHdg=" + this.originHdg + "]";
185     }
186 }