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.seq.io;
023
024import java.io.BufferedInputStream;
025import java.io.IOException;
026import java.io.InputStream;
027
028import org.biojava.bio.seq.Feature.Template;
029import org.biojava.bio.seq.io.ParseException;
030import org.biojava.bio.symbol.Alphabet;
031import org.biojava.bio.symbol.IllegalAlphabetException;
032import org.biojava.bio.symbol.Symbol;
033import org.biojavax.Namespace;
034import org.biojavax.RankedCrossRef;
035import org.biojavax.RankedDocRef;
036import org.biojavax.bio.BioEntryRelationship;
037import org.biojavax.bio.seq.RichFeature;
038import org.biojavax.bio.taxa.NCBITaxon;
039
040/**
041 * This is purely for debugging purposes. Use it to wrap an input stream
042 * then pass it as a parameter to some format to listen for
043 * sequence generation events. It will dump out char-by-char what it reads,
044 * followed event-by-event the events it receives from the format.
045 * @author Richard Holland
046 * @author Mark Schreiber
047 * @author Michael Heuer
048 * @since 1.5
049 */
050public class DebuggingRichSeqIOListener extends BufferedInputStream implements
051                RichSeqIOListener {
052
053        private RichFeature currentFeature;
054        
055        public DebuggingRichSeqIOListener(InputStream inputStream) {
056                super(inputStream);
057                this.message("Beginning debug session.");
058        }
059        
060        /**
061         * {@inheritDoc}
062         * <p>
063         * Echoes everything that is read to stdout.
064         */
065        public int read() throws IOException {
066                int ch = super.read();
067                System.out.print(ch);
068                return ch;
069        }
070
071        public void setAccession(String accession) throws ParseException {
072                this.message("setAccession: "+accession);
073        }
074
075        public void setIdentifier(String identifier) throws ParseException {
076                this.message("setIdentifier: "+identifier);
077        }
078
079        public void setDivision(String division) throws ParseException {
080                this.message("setDivision: "+division);
081        }
082
083        public void setDescription(String description) throws ParseException {
084                this.message("setDescription: "+description);
085        }
086
087        public void setVersion(int version) throws ParseException {
088                this.message("setVersion: "+version);
089        }
090
091        public void setSeqVersion(String version) throws ParseException {
092                this.message("setSeqVersion: "+version);
093        }
094
095        public void setComment(String comment) throws ParseException {
096                this.message("setComment: "+comment);
097        }
098
099        public void setRankedDocRef(RankedDocRef ref) throws ParseException {
100                this.message("setRankedDocRef: "+ref);
101        }
102
103        public void setTaxon(NCBITaxon taxon) throws ParseException {
104                this.message("setTaxon: "+taxon);
105        }
106
107        public void setNamespace(Namespace namespace) throws ParseException {
108                this.message("setNamespace: "+namespace);
109        }
110
111        public void setRelationship(BioEntryRelationship relationship)
112                        throws ParseException {
113                this.message("setRelationship: "+relationship);
114        }
115
116        public void setRankedCrossRef(RankedCrossRef crossRef)
117                        throws ParseException {
118                this.message("setRankedCrossRef: "+crossRef);
119        }
120
121        public void setURI(String uri) throws ParseException {
122                this.message("setURI: "+uri);
123        }
124
125        public RichFeature getCurrentFeature() throws ParseException {
126                this.message("Current feature requested.");
127                return this.currentFeature;
128        }
129
130        public void setCircular(boolean circular) throws ParseException {
131                this.message("setCircular: "+circular);
132        }
133
134        public void startSequence() throws ParseException {
135                this.message("startSequence");
136        }
137
138        public void endSequence() throws ParseException {
139                this.message("endSequence");
140        }
141
142        public void setName(String name) throws ParseException {
143                this.message("setName: "+name);
144        }
145
146        public void addSymbols(Alphabet alpha, Symbol[] syms, int start, int length)
147                        throws IllegalAlphabetException {
148                this.message("addSymbols: (alpha) "+alpha
149                                +" (syms) "+syms
150                                +" (start) "+start
151                                +" (length) "+length);
152        }
153
154        public void addSequenceProperty(Object key, Object value)
155                        throws ParseException {
156                this.message("addSequenceProperty: (key) "+key+" (value) "+value);
157        }
158
159        public void startFeature(Template templ) throws ParseException {
160                this.message("startFeature: (templ) "+templ);
161                this.currentFeature = RichFeature.Tools.makeEmptyFeature();
162        }
163
164        public void endFeature() throws ParseException {
165                this.message("endFeature");
166        }
167
168        public void addFeatureProperty(Object key, Object value)
169                        throws ParseException {
170                this.message("addFeatureProperty: (key) "+key+" (value) "+value);
171        }
172        
173        private void message(String message) {
174                System.out.println("\n\n#####\n"+message+"\n#####\n\n");
175                System.out.println("##### READING... #####\n\n");
176        }
177}