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.impl;
023
024import org.biojava.bio.BioError;
025import org.biojava.bio.BioException;
026import org.biojava.bio.molbio.RestrictionSite;
027import org.biojava.bio.seq.Feature;
028import org.biojava.bio.seq.FeatureRealizer;
029import org.biojava.bio.seq.FramedFeature;
030import org.biojava.bio.seq.RemoteFeature;
031import org.biojava.bio.seq.SimpleFeatureRealizer;
032import org.biojava.bio.seq.StrandedFeature;
033import org.biojava.bio.seq.homol.HomologyFeature;
034import org.biojava.bio.seq.homol.SimilarityPairFeature;
035import org.biojava.utils.StaticMemberPlaceHolder;
036
037/**
038 * Wrap up default sets of Feature implementations.
039 *
040 * @author Thomas Down
041 * @author Greg Cox
042 * @author Keith James
043 * @since 1.1
044 * @see org.biojavax.bio.seq.SimpleRichFeature
045 */
046
047public class FeatureImpl {
048    /**
049     * Default implementation of FeatureRealizer, which wraps simple
050     * implementations of Feature and StrandedFeature.  This is the
051     * default FeatureRealizer used by SimpleSequence and ViewSequence,
052     * and may also be used by others.  When building new FeatureRealizers,
053     * you may wish to use this as a `fallback' realizer, and benefit from
054     * the Feature and StrandedFeature implementations.
055     */
056
057    public final static FeatureRealizer DEFAULT;
058
059    static {
060        SimpleFeatureRealizer d  = new SimpleFeatureRealizer() {
061            public Object writeReplace() {
062                try {
063                    return new StaticMemberPlaceHolder(FeatureImpl.class.getField("DEFAULT"));
064                } catch (NoSuchFieldException ex) {
065                    throw new BioError(ex);
066                }
067            }
068        } ;
069
070        try {
071            d.addImplementation(Feature.Template.class,
072                                SimpleFeature.class);
073            d.addImplementation(StrandedFeature.Template.class,
074                                SimpleStrandedFeature.class);
075            d.addImplementation(HomologyFeature.Template.class,
076                                SimpleHomologyFeature.class);
077            d.addImplementation(SimilarityPairFeature.Template.class,
078                                SimpleSimilarityPairFeature.class);
079            d.addImplementation(RemoteFeature.Template.class,
080                                SimpleRemoteFeature.class);
081            d.addImplementation(FramedFeature.Template.class,
082                                SimpleFramedFeature.class);
083            d.addImplementation(RestrictionSite.Template.class,
084                                SimpleRestrictionSite.class);
085        } catch (BioException ex) {
086            throw new BioError("Couldn't initialize default FeatureRealizer", ex);
087        }
088
089        DEFAULT = d;
090    }
091}