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.program.xff.ElementRecognizer; 025import org.biojava.utils.stax.StAXContentHandler; 026import org.xml.sax.Attributes; 027import org.xml.sax.SAXException; 028 029/** 030 * <code>HSPStAXHandler</code> handles the HSP element of BioJava 031 * BlastLike XML. 032 * 033 * @author Keith James 034 * @since 1.3 035 */ 036public class HSPStAXHandler extends SeqSimilarityStAXHandler 037{ 038 public static final StAXHandlerFactory HSP_HANDLER_FACTORY = 039 new StAXHandlerFactory() 040 { 041 public StAXContentHandler getHandler(SeqSimilarityStAXAdapter ssContext) 042 { 043 return new HSPStAXHandler(ssContext); 044 } 045 }; 046 047 /** 048 * Creates a new instance which sends callbacks to the specified 049 * <code>SeqSimilarityStAXAdapter</code>. 050 * 051 * @param ssContext a <code>SeqSimilarityStAXAdapter</code>. 052 */ 053 HSPStAXHandler(SeqSimilarityStAXAdapter ssContext) 054 { 055 super(ssContext); 056 addHandler(new ElementRecognizer.ByNSName(SeqSimilarityStAXAdapter.NAMESPACE, 057 "HSPSummary"), 058 HSPSummaryStAXHandler.HSPSUMMARY_HANDLER_FACTORY); 059 060 addHandler(new ElementRecognizer.ByNSName(SeqSimilarityStAXAdapter.NAMESPACE, 061 "BlastLikeAlignment"), 062 AlignmentStAXHandler.ALIGNMENT_HANDLER_FACTORY); 063 } 064 065 protected void handleStartElement(String nsURI, 066 String localName, 067 String qName, 068 Attributes attrs) 069 throws SAXException 070 { 071 ssContext.getSearchContentHandler().startSubHit(); 072 } 073 074 protected void handleEndElement(String nsURI, 075 String localName, 076 String qName) 077 throws SAXException 078 { 079 ssContext.getSearchContentHandler().endSubHit(); 080 } 081}