001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package org.biojava.bio.seq.db.flat;
023
024import java.io.IOException;
025import java.util.Map;
026
027import org.biojava.bio.BioException;
028import org.biojava.bio.seq.db.SequenceDBLite;
029import org.biojava.directory.RegistryException;
030import org.biojava.directory.SequenceDBProvider;
031
032/**
033 * <code>FlatSequenceDBProvider</code> directory-services plugin for
034 * flatfile databases.
035 *
036 * This class is instantiated automatically by the
037 *                directory-services code, and is not of direct
038 *                interest to users.
039 *
040 * @author Keith James
041 */
042public class FlatSequenceDBProvider implements SequenceDBProvider
043{
044    public String getName()
045    {
046        return "flat";
047    }
048
049    public SequenceDBLite getSequenceDB(Map config)
050        throws RegistryException, BioException
051    {
052        String location = (String) config.get("location");
053        if (location == null)
054        {
055            throw new RegistryException("Flat provider requires a"
056                                        + " location parameter");
057        }
058
059        String dbName = (String) config.get("dbname");
060        if (dbName == null)
061        {
062            throw new RegistryException("Flat provider requires a"
063                                        + " dbname parameter");
064        }
065
066        try
067        {
068            return new FlatSequenceDB(location, dbName);
069        }
070        catch (IOException ioe)
071        {
072            throw new BioException("Flat provider failed to open index",ioe);
073        }
074    }
075}