View Javadoc

1   /*
2    * @(#)DistributionParser.java Jun 25, 2004 Copyright (c) 2002-2005, 2004 Delft
3    * University of Technology Jaffalaan 5, 2628 BX Delft, the Netherlands. All
4    * rights reserved. This software is proprietary information of Delft University
5    * of Technology The code is published under the Lesser General Public License
6    */
7   
8   package nl.tudelft.simulation.xml.language;
9   
10  import java.io.IOException;
11  import java.net.URL;
12  
13  import nl.tudelft.simulation.language.d3.DirectedPoint;
14  
15  import org.jdom.Element;
16  
17  /***
18   * <br>
19   * (c) copyright 2002-2005-2004 <a href="http://www.simulation.tudelft.nl">Delft
20   * University of Technology </a>, the Netherlands. <br>
21   * See for project information <a href="http://www.simulation.tudelft.nl">
22   * www.simulation.tudelft.nl </a> <br>
23   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
24   * General Public License (LGPL) </a>, no warranty.
25   * 
26   * @version Jun 25, 2004 <br>
27   * @author <a
28   *         href="mailto:a.verbraeck@tbm.tudelft.nl">Alexander
29   *         Verbraeck </a>
30   */
31  public final class LocationParser
32  {
33      /*** the default schema file */
34      public static final URL LOCATIONFILE_SCHEMA = LocationParser.class
35              .getResource("/xsd/location.xsd");
36  
37      /***
38       * constructs a new LocationParser
39       */
40      private LocationParser()
41      {
42          super();
43          // unreachable code
44      }
45  
46      /***
47       * parses a xml-element representing a DirectedPoint
48       * 
49       * @param element The j-dom element
50       * @return DirectedPoint of element
51       * @throws IOException on IOfailure
52       */
53      public static DirectedPoint parseLocation(final Element element)
54              throws IOException
55      {
56          try
57          {
58              double x = new Double(element.getAttributeValue("x")).doubleValue();
59              double y = new Double(element.getAttributeValue("y")).doubleValue();
60              double z = 0.0;
61              if (element.getAttributeValue("z") != null)
62              {
63                  z = new Double(element.getAttributeValue("z")).doubleValue();
64              }
65              double phi = 0.0;
66              if (element.getAttributeValue("phi") != null)
67              {
68                  phi = new Double(element.getAttributeValue("phi"))
69                          .doubleValue();
70              }
71              double rho = 0.0;
72              if (element.getAttributeValue("rho") != null)
73              {
74                  rho = new Double(element.getAttributeValue("rho"))
75                          .doubleValue();
76              }
77              double theta = 0.0;
78              if (element.getAttributeValue("theta") != null)
79              {
80                  theta = new Double(element.getAttributeValue("theta"))
81                          .doubleValue();
82              }
83              return new DirectedPoint(x, y, z, phi, rho, theta);
84          } catch (Exception exception)
85          {
86              throw new IOException("element: " + element + "\nattributes: "
87                      + element.getAttributes() + "\nchaildren: "
88                      + element.getChildren() + "\nmessage: "
89                      + exception.getMessage());
90          }
91      }
92  }