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.biojavax.bio.db;
023
024import java.util.Iterator;
025
026import org.biojava.bio.BioException;
027import org.biojava.bio.seq.db.IllegalIDException;
028import org.biojava.utils.AbstractChangeable;
029import org.biojava.utils.ChangeVetoException;
030import org.biojavax.bio.BioEntry;
031import org.biojavax.bio.BioEntryIterator;
032
033/**
034 * An abstract implementation of BioEntryDB that provides the getBioEntryIterator
035 * method.
036 *
037 * @author Matthew Pocock
038 * @author Thomas Down
039 * @author Richard Holland
040 * @since 1.5
041 */
042public abstract class AbstractBioEntryDB extends AbstractChangeable implements BioEntryDB {
043    
044    public void addBioEntry(BioEntry seq) throws IllegalIDException, BioException, ChangeVetoException {
045        throw new ChangeVetoException("Cannot add BioEntrys to a read-only database");
046    }
047    
048    public void removeBioEntry(String id) throws IllegalIDException, BioException, ChangeVetoException {
049        throw new ChangeVetoException("Cannot remove BioEntrys from a read-only database");
050    }
051           
052    public BioEntryIterator getBioEntryIterator() {
053        return new BioEntryIterator() {
054            private Iterator pID = ids().iterator();
055            
056            public boolean hasNext() {
057                return pID.hasNext();
058            }
059            
060            public BioEntry nextBioEntry() throws BioException {
061                return getBioEntry((String)pID.next());
062            }
063        };
064    }
065}