View Javadoc
1   package org.opentrafficsim.road.network.factory.xml.old;
2   
3   import java.io.Serializable;
4   
5   import org.opentrafficsim.core.gtu.GTUException;
6   import org.opentrafficsim.core.gtu.GTUType;
7   import org.opentrafficsim.core.network.NetworkException;
8   import org.w3c.dom.NamedNodeMap;
9   import org.w3c.dom.Node;
10  import org.w3c.dom.NodeList;
11  import org.xml.sax.SAXException;
12  
13  /**
14   * The XML tag for the GTUType.
15   * 
16   * <pre>
17   * {@code
18    <xsd:element name="GTUTYPE">
19      <xsd:complexType>
20        <xsd:attribute name="NAME" type="xsd:string" use="required" />
21        <xsd:attribute ref="xml:base" />
22      </xsd:complexType>
23    </xsd:element>
24   * }
25   * </pre>
26   * <p>
27   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
28   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
29   * <p>
30   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
31   * initial version Jul 23, 2015 <br>
32   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
33   */
34  class GTUTypeTag implements Serializable
35  {
36      /** */
37      private static final long serialVersionUID = 20160925L;
38  
39      /** Name. */
40      @SuppressWarnings("checkstyle:visibilitymodifier")
41      String name = null;
42  
43      /**
44       * @param nodeList NodeList; nodeList the top-level nodes of the XML-file
45       * @param parser XmlNetworkLaneParserOld; the parser with the lists of information
46       * @throws SAXException when parsing of GTU tag fails
47       * @throws NetworkException when parsing of GTU tag fails
48       * @throws GTUException if GTUType defined twice
49       */
50      @SuppressWarnings("checkstyle:needbraces")
51      static void parseGTUTypes(final NodeList nodeList, final XmlNetworkLaneParserOld parser)
52              throws SAXException, NetworkException, GTUException
53      {
54          for (Node node : XMLParser.getNodes(nodeList, "GTUTYPE"))
55          {
56              NamedNodeMap attributes = node.getAttributes();
57              GTUTypeTag gtuTypeTag = new GTUTypeTag();
58  
59              Node name = attributes.getNamedItem("NAME");
60              if (name == null)
61                  throw new SAXException("GTUTYPE: missing attribute NAME");
62              gtuTypeTag.name = name.getNodeValue().trim();
63              if (parser.gtuTypes.keySet().contains(gtuTypeTag.name))
64                  throw new SAXException("GTUTYPE: NAME " + gtuTypeTag.name + " defined twice");
65              // TODO super type (car, bus, truck) in xml definition
66              GTUType gtuType = new GTUType(gtuTypeTag.name, parser.network.getGtuType(GTUType.DEFAULTS.VEHICLE));
67              parser.gtuTypes.put(gtuTypeTag.name, gtuType);
68          }
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public final String toString()
74      {
75          return "GTUTypeTag [name=" + this.name + "]";
76      }
77  
78  }