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.program.ssbind; 023 024import org.biojava.bio.search.SearchContentHandler; 025import org.biojava.utils.stax.SAX2StAXAdaptor; 026import org.xml.sax.Attributes; 027import org.xml.sax.ContentHandler; 028import org.xml.sax.Locator; 029import org.xml.sax.SAXException; 030 031/** 032 * A <code>SeqSimilarityAdapter</code> converts SAX events into method 033 * calls on a <code>SearchContentHandler</code> implementation. The 034 * SAX events should describe elements conforming to the BioJava 035 * BlastLikeDataSetCollection DTD. A 036 * <code>BlastLikeSearchBuilder</code> is supplied, implementing the 037 * <code>SearchContentHandler</code> interface, which will create 038 * <code>SeqSimilaritySearchResult</code>s from the stream. 039 * 040 * @author Keith James 041 * @since 1.2 042 */ 043public class SeqSimilarityAdapter implements ContentHandler 044{ 045 private SeqSimilarityStAXAdapter staxHandler; 046 private ContentHandler contentHandler; 047 048 public SeqSimilarityAdapter() 049 { 050 staxHandler = new SeqSimilarityStAXAdapter(); 051 contentHandler = new SAX2StAXAdaptor(staxHandler); 052 } 053 054 /** 055 * <code>getSearchContentHandler</code> gets the handler which 056 * will recieve the method calls generated by the adapter. 057 * 058 * @return a <code>SearchContentHandler</code>. 059 */ 060 public SearchContentHandler getSearchContentHandler() 061 { 062 return staxHandler.getSearchContentHandler(); 063 } 064 065 /** 066 * <code>setSearchContentHandler</code> sets the handler which 067 * will recieve the method calls generated by the adapter. 068 * 069 * @param scHandler a <code>SearchContentHandler</code>. 070 */ 071 public void setSearchContentHandler(SearchContentHandler scHandler) 072 { 073 staxHandler.setSearchContentHandler(scHandler); 074 } 075 076 public void startDocument() throws SAXException 077 { 078 contentHandler.startDocument(); 079 } 080 081 public void endDocument() throws SAXException 082 { 083 contentHandler.endDocument(); 084 } 085 086 public void characters(char[] ch, int start, int end) throws SAXException 087 { 088 contentHandler.characters(ch, start, end); 089 } 090 091 public void ignorableWhitespace(char[] ch, int start, int end) 092 throws SAXException 093 { 094 contentHandler.ignorableWhitespace(ch, start, end); 095 } 096 097 public void startPrefixMapping(String prefix, String uri) 098 throws SAXException 099 { 100 contentHandler.startPrefixMapping(prefix, uri); 101 } 102 103 public void endPrefixMapping(String prefix) throws SAXException 104 { 105 contentHandler.endPrefixMapping(prefix); 106 } 107 108 public void processingInstruction(String target, String data) 109 throws SAXException 110 { 111 contentHandler.processingInstruction(target, data); 112 } 113 114 public void setDocumentLocator(Locator locator) 115 { 116 contentHandler.setDocumentLocator(locator); 117 } 118 119 public void skippedEntity(String name) throws SAXException 120 { 121 contentHandler.skippedEntity(name); 122 } 123 124 public void startElement(String nsURI, 125 String localName, 126 String qName, 127 Attributes attrs) 128 throws SAXException 129 { 130 contentHandler.startElement(nsURI, localName, qName, attrs); 131 } 132 133 public void endElement(String nsURI, String localName, String qName) 134 throws SAXException 135 { 136 contentHandler.endElement(nsURI, localName, qName); 137 } 138 139 /** 140 * <code>getProgram</code> returns the program type which 141 * generated the results. 142 * 143 * @return a <code>String</code> indicating the progam 144 * name. 145 */ 146 String getProgram() 147 { 148 return staxHandler.getProgram(); 149 } 150 151 /** 152 * <code>setProgram</code> informs the adapter which program type 153 * it is working on. 154 * 155 * @param program a <code>String</code> indicating the progam 156 * name. 157 */ 158 void setProgram(String program) 159 { 160 staxHandler.setProgram(program); 161 } 162}