View Javadoc
1   package org.opentrafficsim.core.network.factory;
2   
3   import java.io.IOException;
4   import java.net.URL;
5   import java.rmi.RemoteException;
6   
7   import javax.xml.parsers.ParserConfigurationException;
8   
9   import nl.tudelft.simulation.dsol.SimRuntimeException;
10  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
11  import nl.tudelft.simulation.language.io.URLResource;
12  
13  import org.opentrafficsim.core.dsol.OTSAnimatorInterface;
14  import org.opentrafficsim.core.dsol.OTSModelInterface;
15  import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
16  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
17  import org.opentrafficsim.core.network.Network;
18  import org.opentrafficsim.core.network.NetworkException;
19  import org.opentrafficsim.core.network.geotools.LinkGeotools;
20  import org.opentrafficsim.core.network.geotools.NodeGeotools;
21  import org.opentrafficsim.core.unit.TimeUnit;
22  import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar.Abs;
23  import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar.Rel;
24  import org.xml.sax.SAXException;
25  
26  import com.vividsolutions.jts.geom.Coordinate;
27  
28  /**
29   * <p>
30   * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
31   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
32   * <p>
33   * @version Oct 17, 2014 <br>
34   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
35   */
36  /** */
37  public class TestXMLModel implements OTSModelInterface
38  {
39      /** */
40      private static final long serialVersionUID = 1L;
41  
42      /** simulator. */
43      private OTSSimulatorInterface simulator;
44  
45      /** {@inheritDoc} */
46      @Override
47      public final void constructModel(final SimulatorInterface<Abs<TimeUnit>, Rel<TimeUnit>, OTSSimTimeDouble> pSimulator)
48              throws SimRuntimeException, RemoteException
49      {
50          this.simulator = (OTSSimulatorInterface) pSimulator;
51          URL url = URLResource.getResource("/circular-road-gtu-example.xml");
52          XmlNetworkLaneParser nlp =
53              new XmlNetworkLaneParser(String.class, NodeGeotools.class, String.class, Coordinate.class, LinkGeotools.class,
54                  String.class, this.simulator);
55          try
56          {
57              Network n = nlp.build(url.openStream());
58          }
59          catch (NetworkException | ParserConfigurationException | SAXException | IOException exception1)
60          {
61              exception1.printStackTrace();
62          }
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public final SimulatorInterface<Abs<TimeUnit>, Rel<TimeUnit>, OTSSimTimeDouble> getSimulator()
68              throws RemoteException
69      {
70          return this.simulator;
71      }
72  }