package nl.tudelft.simulation.xml.language; import java.io.IOException; import java.net.URL; import nl.tudelft.simulation.language.d3.DirectedPoint; import org.jdom2.Element; /** *
* (c) copyright 2002-2005-2004 Delft University of Technology , the * Netherlands.
* See for project information www.simulation.tudelft.nl
* License of use: Lesser General Public License (LGPL) , no * warranty. * @version Jun 25, 2004
* @author Alexander Verbraeck */ public final class LocationParser { /** the default schema file. */ public static final URL LOCATIONFILE_SCHEMA = LocationParser.class.getResource("/xsd/location.xsd"); /** * constructs a new LocationParser. */ private LocationParser() { super(); // unreachable code } /** * parses a xml-element representing a DirectedPoint * @param element The j-dom element * @return DirectedPoint of element * @throws IOException on IOfailure */ public static DirectedPoint parseLocation(final Element element) throws IOException { try { double x = new Double(element.getAttributeValue("x")).doubleValue(); double y = new Double(element.getAttributeValue("y")).doubleValue(); double z = 0.0; if (element.getAttributeValue("z") != null) { z = new Double(element.getAttributeValue("z")).doubleValue(); } double phi = 0.0; if (element.getAttributeValue("phi") != null) { phi = new Double(element.getAttributeValue("phi")).doubleValue(); } double rho = 0.0; if (element.getAttributeValue("rho") != null) { rho = new Double(element.getAttributeValue("rho")).doubleValue(); } double theta = 0.0; if (element.getAttributeValue("theta") != null) { theta = new Double(element.getAttributeValue("theta")).doubleValue(); } return new DirectedPoint(x, y, z, phi, rho, theta); } catch (Exception exception) { throw new IOException("element: " + element + "\nattributes: " + element.getAttributes() + "\nchaildren: " + element.getChildren() + "\nmessage: " + exception.getMessage()); } } }