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.io; 023 024import java.io.BufferedReader; 025import java.io.IOException; 026import java.io.PrintStream; 027 028import javax.xml.parsers.SAXParserFactory; 029 030import org.biojava.bio.seq.Sequence; 031import org.biojava.bio.seq.io.game12.GAMEHandler; 032import org.biojava.utils.stax.SAX2StAXAdaptor; 033import org.xml.sax.InputSource; 034import org.xml.sax.SAXException; 035import org.xml.sax.XMLReader; 036 037/** 038 * A rudimentary read-only GAME 1.2 Format object. 039 * 040 * @author David Huen 041 */ 042public class GAMEFormat implements SequenceFormat 043{ 044 public static final String DEFAULT = "GAME1.2"; 045 046 /** 047 * this version only reads annotations (no symbols) 048 */ 049 public boolean readSequence(BufferedReader reader, SymbolTokenization symParser, SeqIOListener listener) 050 throws IOException 051 { 052 try { 053 // set up processing pipeline 054 InputSource is = new InputSource(reader); 055 056 GAMEHandler handler = new GAMEHandler(listener); 057 058 XMLReader parser; 059 try { 060 SAXParserFactory spf = SAXParserFactory.newInstance(); 061 spf.setValidating(false); 062 spf.setNamespaceAware(true); 063 parser = spf.newSAXParser().getXMLReader(); 064 } catch (Exception ex) { 065 throw new IOException("Error creating SAX parser"); 066 } 067 parser.setContentHandler(new SAX2StAXAdaptor(handler)); 068 069 parser.parse(is); 070 071 return false; 072 } 073 catch (SAXException se) { 074 se.printStackTrace(); 075 throw new IOException("SAXException encountered during parsing"); 076 } 077 } 078 079 public void writeSequence(Sequence seq, PrintStream os) 080 { 081 082 } 083 084 public void writeSequence(Sequence seq, String format, PrintStream os) 085 { 086 087 } 088 089 /** 090 * <code>getDefaultFormat</code> returns the String identifier for 091 * the default format. 092 * 093 * @return a <code>String</code>. 094 * @deprecated 095 */ 096 public String getDefaultFormat() 097 { 098 return DEFAULT; 099 } 100} 101