3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library 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 GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
27 package org.forester.phylogeny.factories;
29 import java.io.IOException;
31 import org.forester.io.parsers.PhylogenyParser;
32 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
33 import org.forester.phylogeny.Phylogeny;
34 import org.forester.util.ForesterUtil;
36 public class ParserBasedPhylogenyFactory implements PhylogenyFactory {
38 private final static PhylogenyFactory _instance;
41 _instance = new ParserBasedPhylogenyFactory();
43 catch ( final Throwable e ) {
44 throw new RuntimeException( e.getMessage() );
48 private ParserBasedPhylogenyFactory() {
49 // Private constructor.
53 public Object clone() throws CloneNotSupportedException {
54 throw new CloneNotSupportedException();
58 public synchronized Phylogeny[] create( final Object source, final Object parser ) throws IOException {
59 if ( !( parser instanceof PhylogenyParser ) ) {
60 throw new IllegalArgumentException( "attempt to use object of type other than PhylogenyParser as creator for ParserBasedPhylogenyFactory" );
62 final PhylogenyParser my_parser = ( PhylogenyParser ) parser;
63 my_parser.setSource( source );
64 return my_parser.parse();
67 public synchronized Phylogeny[] create( final Object source, final Object parser, final String schema_location )
69 if ( !( parser instanceof PhylogenyParser ) ) {
70 throw new IllegalArgumentException( "attempt to use object of type other than PhylogenyParser as creator for ParserBasedPhylogenyFactory." );
72 if ( !( parser instanceof PhyloXmlParser ) ) {
73 throw new IllegalArgumentException( "attempt to use schema location with other than phyloXML parser" );
75 final PhyloXmlParser xml_parser = ( PhyloXmlParser ) parser;
76 if ( !ForesterUtil.isEmpty( schema_location ) ) {
77 xml_parser.setValidateAgainstSchema( schema_location );
79 xml_parser.setSource( source );
80 return xml_parser.parse();
83 public static PhylogenyFactory getInstance() {