1 package jalview.ext.forester.io;
3 import jalview.ext.archaeopteryx.Tree;
4 import jalview.ext.treeviewer.TreeI;
5 import jalview.ext.treeviewer.TreeParserI;
8 import java.io.IOException;
10 import org.forester.io.parsers.PhylogenyParser;
11 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
12 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
13 import org.forester.io.parsers.util.PhylogenyParserException;
14 import org.forester.phylogeny.Phylogeny;
16 public class ForesterParser
17 implements TreeParserI
19 private final PhylogenyParser parser;
21 private TreeI[] parsedTrees;
23 protected ForesterParser(PhylogenyParser foresterParser, File file)
24 throws PhylogenyParserException, IOException
26 parser = foresterParser;
27 parser.setSource(file);
30 public static ForesterParser createNexusParser(File file)
31 throws PhylogenyParserException, IOException
33 return new ForesterParser(new NexusPhylogeniesParser(), file);
36 public static ForesterParser createPhyloXmlParser(File file)
37 throws PhylogenyParserException, IOException
39 // support non-xsd validating?
40 return new ForesterParser(
41 PhyloXmlParser.createPhyloXmlParserXsdValidating(), file);
44 // ParserBasedPhylogenyFactory.getInstance().create(foresterParser, source)
46 public TreeI[] parse() throws IOException
48 Phylogeny[] foresterTrees = parser.parse();
49 parsedTrees = new TreeI[foresterTrees.length];
51 for (int i = 0; i < foresterTrees.length; i++)
53 parsedTrees[i] = new Tree(foresterTrees[i]);
60 public void setSource(Object source) throws IOException
62 parser.setSource(source);
67 public String getName()
69 return parser.getName();
74 public TreeI[] getParsedTrees()