2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.io.parsers.phyloxml.data;
28 import java.math.BigDecimal;
30 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
31 import org.forester.io.parsers.phyloxml.XmlElement;
32 import org.forester.io.parsers.util.PhylogenyParserException;
33 import org.forester.phylogeny.data.PhylogenyData;
34 import org.forester.phylogeny.data.Point;
35 import org.forester.util.ForesterUtil;
37 public class PointParser implements PhylogenyDataPhyloXmlParser {
39 private static final PhylogenyDataPhyloXmlParser _instance;
42 _instance = new PointParser();
44 catch ( final Throwable e ) {
45 throw new RuntimeException( e.getMessage() );
49 private PointParser() {
53 public PhylogenyData parse( final XmlElement element ) throws PhylogenyParserException {
55 String geo_datum = "";
56 if ( element.isHasAttribute( PhyloXmlMapping.POINT_ALTITUDE_UNIT_ATTR ) ) {
57 alt_unit = element.getAttribute( PhyloXmlMapping.POINT_ALTITUDE_UNIT_ATTR );
59 if ( element.isHasAttribute( PhyloXmlMapping.POINT_GEODETIC_DATUM ) ) {
60 geo_datum = element.getAttribute( PhyloXmlMapping.POINT_GEODETIC_DATUM );
62 String lat_str = null;
63 String lon_str = null;
64 String alt_str = null;
65 for( int j = 0; j < element.getNumberOfChildElements(); ++j ) {
66 final XmlElement e = element.getChildElement( j );
67 if ( e.getQualifiedName().equals( PhyloXmlMapping.POINT_LATITUDE ) ) {
68 lat_str = e.getValueAsString();
70 else if ( e.getQualifiedName().equals( PhyloXmlMapping.POINT_LONGITUDE ) ) {
71 lon_str = e.getValueAsString();
73 else if ( e.getQualifiedName().equals( PhyloXmlMapping.POINT_ALTITUDE ) ) {
74 alt_str = e.getValueAsString();
77 BigDecimal lat = null;
78 BigDecimal lon = null;
79 BigDecimal alt = null;
80 if ( !ForesterUtil.isEmpty( lat_str ) ) {
81 lat = new BigDecimal( lat_str );
83 if ( !ForesterUtil.isEmpty( lon_str ) ) {
84 lon = new BigDecimal( lon_str );
86 if ( !ForesterUtil.isEmpty( alt_str ) ) {
87 alt = new BigDecimal( alt_str );
89 return new Point( geo_datum, lat, lon, alt, alt_unit );
92 public static PhylogenyDataPhyloXmlParser getInstance() {