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: www.phylosoft.org/forester
27 package org.forester.phylogeny.factories;
29 import java.io.IOException;
30 import java.util.List;
32 import org.forester.io.parsers.PhylogenyParser;
33 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
34 import org.forester.phylogeny.Phylogeny;
35 import org.forester.util.ForesterUtil;
37 public class ParserBasedPhylogenyFactory extends BasicPhylogenyFactory {
39 private final static PhylogenyFactory _instance;
42 _instance = new ParserBasedPhylogenyFactory();
44 catch ( final Throwable e ) {
45 throw new RuntimeException( e.getMessage() );
49 private ParserBasedPhylogenyFactory() {
50 // Private constructor.
54 public Object clone() throws CloneNotSupportedException {
55 throw new CloneNotSupportedException();
59 public synchronized Phylogeny[] create( final Object source, final Object parser, final List<Object> parameters )
61 if ( !( parser instanceof PhylogenyParser ) ) {
62 throw new IllegalArgumentException( "attempt to use object of type other than PhylogenyParser as creator for ParserBasedPhylogenyFactory" );
64 final PhylogenyParser my_parser = ( PhylogenyParser ) parser;
65 my_parser.setSource( source );
66 return my_parser.parse();
69 public synchronized Phylogeny[] create( final Object source,
71 final String schema_location,
72 final List<Object> parameters ) throws IOException {
73 if ( !( parser instanceof PhylogenyParser ) ) {
74 throw new IllegalArgumentException( "attempt to use object of type other than PhylogenyParser as creator for ParserBasedPhylogenyFactory." );
76 if ( !( parser instanceof PhyloXmlParser ) ) {
77 throw new IllegalArgumentException( "attempt to use schema location with other than phyloXML parser" );
79 final PhyloXmlParser xml_parser = ( PhyloXmlParser ) parser;
80 if ( !ForesterUtil.isEmpty( schema_location ) ) {
81 xml_parser.setValidateAgainstSchema( schema_location );
83 xml_parser.setSource( source );
84 return xml_parser.parse();
87 public static PhylogenyFactory getInstance() {