Debian Codegraph @

src/dr/evoxml/TaxaParser.java

raw symbols SCIP
1 /*
2 * TaxaParser.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evoxml;
27
28 import dr.evolution.util.Taxa;
29 import dr.evolution.util.Taxon;
30 import dr.evolution.util.TaxonList;
31 import dr.xml.*;
32
33 /**
34 * @author Alexei Drummond
35 * @author Andrew Rambaut
36 *
37 * @version $Id: TaxaParser.java,v 1.2 2005/05/24 20:25:59 rambaut Exp $
38 */
39 public class TaxaParser extends AbstractXMLObjectParser {
40
41 public static final String TAXA = "taxa";
42 public static final String EXCLUDE = "exclude";
43
44 public String getParserName() { return TAXA; }
45
46 public String getExample() {
47 return "<!-- A list of six taxa -->\n"+
48 "<taxa id=\"greatApes\">\n"+
49 " <taxon id=\"human\"/>\n"+
50 " <taxon id=\"chimp\"/>\n"+
51 " <taxon id=\"bonobo\"/>\n"+
52 " <taxon id=\"gorilla\"/>\n"+
53 " <taxon id=\"orangutan\"/>\n"+
54 " <taxon id=\"siamang\"/>\n"+
55 "</taxa>\n" +
56 "\n" +
57 "<!-- A list of three taxa by references to above taxon objects -->\n"+
58 "<taxa id=\"humanAndChimps\">\n"+
59 " <taxon idref=\"human\"/>\n"+
60 " <taxon idref=\"chimp\"/>\n"+
61 " <taxon idref=\"bonobo\"/>\n"+
62 "</taxa>\n";
63 }
64
65 /** @return an instance of Node created from a DOM element */
66 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
67
68 Taxa taxonList = new Taxa();
69
70 for (Taxon taxon : xo.getAllChildren(Taxon.class)) {
71 taxonList.addTaxon(taxon);
72 }
73
74 for (Taxa taxa : xo.getAllChildren(Taxa.class)) {
75 taxonList.addTaxa(taxa);
76 }
77
78 for (XMLObject cxo : xo.getAllChildren(EXCLUDE)) {
79 for (Taxa exclude : cxo.getAllChildren(Taxa.class)) {
80 taxonList.removeTaxa(exclude);
81 }
82 }
83
84 return taxonList;
85 }
86
87 public XMLSyntaxRule[] getSyntaxRules() { return rules; }
88
89 private final XMLSyntaxRule[] rules = {
90 new OrRule(
91 new ElementRule(Taxa.class, 1, Integer.MAX_VALUE),
92 new ElementRule(Taxon.class, 1, Integer.MAX_VALUE)
93 ),
94 new ElementRule("exclude", Taxa.class, "taxa to exclude", 0, Integer.MAX_VALUE)
95 };
96
97 public String getParserDescription() {
98 return "Defines a set of taxon objects.";
99 }
100
101 public Class getReturnType() { return Taxa.class; }
102 }
103
104