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.Date;
34 import org.forester.phylogeny.data.PhylogenyData;
35 import org.forester.util.ForesterUtil;
37 public class DateParser implements PhylogenyDataPhyloXmlParser {
39 private static final PhylogenyDataPhyloXmlParser _instance;
42 _instance = new DateParser();
44 catch ( final Throwable e ) {
45 throw new RuntimeException( e.getMessage() );
49 private DateParser() {
53 public PhylogenyData parse( final XmlElement element ) throws PhylogenyParserException {
55 if ( element.isHasAttribute( PhyloXmlMapping.CLADE_DATE_UNIT ) ) {
56 unit = element.getAttribute( PhyloXmlMapping.CLADE_DATE_UNIT );
62 for( int j = 0; j < element.getNumberOfChildElements(); ++j ) {
63 final XmlElement e = element.getChildElement( j );
64 if ( e.getQualifiedName().equals( PhyloXmlMapping.CLADE_DATE_VALUE ) ) {
65 val = e.getValueAsString();
67 else if ( e.getQualifiedName().equals( PhyloXmlMapping.CLADE_DATE_MIN ) ) {
68 min = e.getValueAsString();
70 else if ( e.getQualifiedName().equals( PhyloXmlMapping.CLADE_DATE_MAX ) ) {
71 max = e.getValueAsString();
73 else if ( e.getQualifiedName().equals( PhyloXmlMapping.CLADE_DATE_DESC ) ) {
74 desc = e.getValueAsString();
77 BigDecimal val_bd = null;
78 BigDecimal min_bd = null;
79 BigDecimal max_bd = null;
80 if ( !ForesterUtil.isEmpty( val ) ) {
81 val_bd = new BigDecimal( val );
83 if ( !ForesterUtil.isEmpty( min ) ) {
84 min_bd = new BigDecimal( min );
86 if ( !ForesterUtil.isEmpty( max ) ) {
87 max_bd = new BigDecimal( max );
89 return new Date( desc, val_bd, min_bd, max_bd, unit );
92 public static PhylogenyDataPhyloXmlParser getInstance() {