View Javadoc
1   package org.opentrafficsim.road.network.factory.xml.old;
2   
3   import java.io.Serializable;
4   import java.util.List;
5   
6   import org.djunits.value.vdouble.scalar.Acceleration;
7   import org.djunits.value.vdouble.scalar.Length;
8   import org.djunits.value.vdouble.scalar.Speed;
9   import org.opentrafficsim.core.network.NetworkException;
10  import org.opentrafficsim.core.network.factory.xml.units.AccelerationUnits;
11  import org.opentrafficsim.core.network.factory.xml.units.LengthUnits;
12  import org.opentrafficsim.core.network.factory.xml.units.SpeedUnits;
13  import org.w3c.dom.NamedNodeMap;
14  import org.w3c.dom.Node;
15  import org.w3c.dom.NodeList;
16  import org.xml.sax.SAXException;
17  
18  /**
19   * GlobalTag parser.
20   * 
21   * <pre>
22   * {@code
23    <xsd:element name="GLOBAL">
24      <xsd:complexType>
25        <xsd:sequence>
26          <xsd:element name="SPEEDGTUCOLORER" minOccurs="0" maxOccurs="1">
27            <xsd:complexType>
28              <xsd:attribute name="MAXSPEED" type="SPEEDTYPE" use="required" />
29            </xsd:complexType>
30          </xsd:element>
31          <xsd:element name="ACCELERATIONGTUCOLORER" minOccurs="0" maxOccurs="1">
32            <xsd:complexType>
33              <xsd:attribute name="MAXDECELERATION" type="ACCELERATIONTYPE" use="required" />
34              <xsd:attribute name="MAXACCELERATION" type="ACCELERATIONTYPE" use="required" />
35            </xsd:complexType>
36          </xsd:element>
37          <xsd:element name="LANECHANGEURGEGTUCOLORER" minOccurs="0" maxOccurs="1">
38            <xsd:complexType>
39              <xsd:attribute name="MINLANECHANGEDISTANCE" type="LENGTHTYPE" use="required" />
40              <xsd:attribute name="HORIZON" type="LENGTHTYPE" use="required" />
41            </xsd:complexType>
42          </xsd:element>
43        </xsd:sequence>
44        <xsd:attribute ref="xml:base" />
45      </xsd:complexType>
46    </xsd:element>
47   * }
48   * </pre>
49   * <p>
50   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
51   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
52   * <p>
53   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
54   * initial version Jul 23, 2015 <br>
55   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
56   */
57  class GlobalTag implements Serializable
58  {
59      /** */
60      private static final long serialVersionUID = 20150723L;
61  
62      /** Default SpeedGTUColorer.maxSpeed. */
63      @SuppressWarnings("checkstyle:visibilitymodifier")
64      Speed speedGTUColorerMaxSpeed = null;
65  
66      /** Default AccelerationGTUColorer.maxDeceleration. */
67      @SuppressWarnings("checkstyle:visibilitymodifier")
68      Acceleration accelerationGTUColorerMaxDeceleration = null;
69  
70      /** Default AccelerationGTUColorer.maxAcceleration. */
71      @SuppressWarnings("checkstyle:visibilitymodifier")
72      Acceleration accelerationGTUColorerMaxAcceleration = null;
73  
74      /** Default LaneChangeUrgeGTUColorer.minLaneChangeDistance. */
75      @SuppressWarnings("checkstyle:visibilitymodifier")
76      Length laneChangeUrgeGTUColorerMinLaneChangeDistance = null;
77  
78      /** Default LaneChangeUrgeGTUColorer.horizon. */
79      @SuppressWarnings("checkstyle:visibilitymodifier")
80      Length laneChangeUrgeGTUColorerHorizon = null;
81  
82      /**
83       * @param nodeList NodeList; nodeList the top-level nodes of the XML-file
84       * @param parser XmlNetworkLaneParserOld; the parser with the lists of information
85       * @throws NetworkException when parsing of units fails
86       * @throws SAXException when parsing of GLOBAL tag fails
87       */
88      @SuppressWarnings("checkstyle:needbraces")
89      static void parseGlobal(final NodeList nodeList, final XmlNetworkLaneParserOld parser) throws NetworkException, SAXException
90      {
91          List<Node> nodes = XMLParser.getNodes(nodeList, "GLOBAL");
92          if (nodes.size() > 1)
93              throw new SAXException("GLOBAL: More than one tag GLOBAL in the XML-file");
94          if (nodes.size() == 1)
95          {
96              Node node = nodes.get(0);
97  
98              parser.globalTag = new GlobalTag();
99  
100             // SPEEDGTUCOLORER attributes
101             List<Node> speedGTUColorerNodes = XMLParser.getNodes(node.getChildNodes(), "SPEEDGTUCOLORER");
102             if (speedGTUColorerNodes.size() > 1)
103                 throw new SAXException("GLOBAL: More than one tag SPEEDGTUCOLORER in the XML-file");
104             if (speedGTUColorerNodes.size() == 1)
105             {
106                 Node speedGTUColorerNode = nodes.get(0);
107                 NamedNodeMap speedGTUColorerAttributes = speedGTUColorerNode.getAttributes();
108                 if (speedGTUColorerAttributes.getNamedItem("MAXSPEED") == null)
109                     throw new SAXException("GLOBAL: No attribute MAXSPEED for the tag SPEEDGTUCOLORER");
110                 parser.globalTag.speedGTUColorerMaxSpeed =
111                         SpeedUnits.parseSpeed(speedGTUColorerAttributes.getNamedItem("MAXSPEED").getNodeValue());
112             }
113 
114             // ACCELERATIONGTUCOLORER attributes
115             List<Node> accelerationGTUColorerNodes = XMLParser.getNodes(node.getChildNodes(), "ACCELERATIONGTUCOLORER");
116             if (accelerationGTUColorerNodes.size() > 1)
117                 throw new SAXException("GLOBAL: More than one tag ACCELERATIONGTUCOLORER in the XML-file");
118             if (accelerationGTUColorerNodes.size() == 1)
119             {
120                 Node accelerationGTUColorerNode = nodes.get(0);
121                 NamedNodeMap accelerationGTUColorerAttributes = accelerationGTUColorerNode.getAttributes();
122                 if (accelerationGTUColorerAttributes.getNamedItem("MAXDECELERATION") == null)
123                     throw new SAXException("GLOBAL: No attribute MAXDECELERATION for the tag ACCELERATIONGTUCOLORER");
124                 parser.globalTag.accelerationGTUColorerMaxDeceleration = AccelerationUnits
125                         .parseAcceleration(accelerationGTUColorerAttributes.getNamedItem("MAXDECELERATION").getNodeValue());
126                 if (accelerationGTUColorerAttributes.getNamedItem("MAXACCELERATION") == null)
127                     throw new SAXException("GLOBAL: No attribute MAXACCELERATION for the tag ACCELERATIONGTUCOLORER");
128                 parser.globalTag.accelerationGTUColorerMaxAcceleration = AccelerationUnits
129                         .parseAcceleration(accelerationGTUColorerAttributes.getNamedItem("MAXACCELERATION").getNodeValue());
130             }
131 
132             // LANECHANGEURGEGTUCOLORER attributes
133             List<Node> lcuGTUColorerNodes = XMLParser.getNodes(node.getChildNodes(), "LANECHANGEURGEGTUCOLORER");
134             if (lcuGTUColorerNodes.size() > 1)
135                 throw new SAXException("GLOBAL: More than one tag LANECHANGEURGEGTUCOLORER in the XML-file");
136             if (lcuGTUColorerNodes.size() == 1)
137             {
138                 Node lcuGTUColorerNode = nodes.get(0);
139                 NamedNodeMap lcuGTUColorerAttributes = lcuGTUColorerNode.getAttributes();
140                 if (lcuGTUColorerAttributes.getNamedItem("MINLANECHANGEDISTANCE") == null)
141                     throw new SAXException("GLOBAL: No attribute MINLANECHANGEDISTANCE for the tag LANECHANGEURGEGTUCOLORER");
142                 parser.globalTag.laneChangeUrgeGTUColorerMinLaneChangeDistance =
143                         LengthUnits.parseLength(lcuGTUColorerAttributes.getNamedItem("MINLANECHANGEDISTANCE").getNodeValue());
144                 if (lcuGTUColorerAttributes.getNamedItem("HORIZON") == null)
145                     throw new SAXException("GLOBAL: No attribute HORIZON for the tag LANECHANGEURGEGTUCOLORER");
146                 parser.globalTag.laneChangeUrgeGTUColorerHorizon =
147                         LengthUnits.parseLength(lcuGTUColorerAttributes.getNamedItem("HORIZON").getNodeValue());
148             }
149         }
150     }
151 
152     /** {@inheritDoc} */
153     @Override
154     public String toString()
155     {
156         return "GlobalTag [speedGTUColorerMaxSpeed=" + this.speedGTUColorerMaxSpeed + ", accelerationGTUColorerMaxDeceleration="
157                 + this.accelerationGTUColorerMaxDeceleration + ", accelerationGTUColorerMaxAcceleration="
158                 + this.accelerationGTUColorerMaxAcceleration + ", laneChangeUrgeGTUColorerMinLaneChangeDistance="
159                 + this.laneChangeUrgeGTUColorerMinLaneChangeDistance + ", laneChangeUrgeGTUColorerHorizon="
160                 + this.laneChangeUrgeGTUColorerHorizon + "]";
161     }
162 
163 }