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 */ 021package org.biojava.bio.seq.io.agave; 022import java.util.ListIterator; 023 024import org.xml.sax.Attributes; 025import org.xml.sax.SAXException; 026 027/** 028 * 029 * 030 */ 031public class AGAVERelatedAnnotPropHandler extends StAXPropertyHandler implements AGAVEEvidenceCallbackItf{ 032 033 034 public static final StAXHandlerFactory AGAVE_RELATED_ANNOT_PROP_HANDLER_FACTORY 035 = new StAXHandlerFactory() { 036 public StAXContentHandler getHandler(StAXFeatureHandler staxenv) { 037 return new AGAVERelatedAnnotPropHandler(staxenv); 038 } 039 }; 040 private AGAVERelatedAnnot related_annot ; 041 AGAVERelatedAnnotPropHandler(StAXFeatureHandler staxenv) { 042 // execute superclass method to setup environment 043 super(staxenv); 044 setHandlerCharacteristics("related_annot", true); 045 046 super.addHandler(new ElementRecognizer.ByLocalName("element_id"), 047 AGAVEElementIdPropHandler.AGAVE_ELEMENT_ID_PROP_HANDLER_FACTORY); 048 super.addHandler(new ElementRecognizer.ByLocalName("sci_property"), 049 AGAVESciPropertyPropHandler.AGAVE_SCI_PROPERTY_PROP_HANDLER_FACTORY); 050 related_annot = new AGAVERelatedAnnot() ; 051 } 052 public void addElementId(String id) 053 { 054 related_annot.addElementId(id) ; 055 } 056 public void addProperty(AGAVEProperty prop) 057 { 058 related_annot.addProp( prop ) ; 059 } 060 public void startElementHandler( 061 String nsURI, 062 String localName, 063 String qName, 064 Attributes attrs) 065 throws SAXException 066 { 067 related_annot.setScore(attrs.getValue( "score" ) ); 068 related_annot.setRel( attrs.getValue( "rel" ) ) ; 069 } 070 071 072 public void endElementHandler( 073 String nsURI, 074 String localName, 075 String qName, 076 StAXContentHandler handler) 077 throws SAXException 078 { 079 int currLevel = staxenv.getLevel(); 080 if (currLevel >=1) { 081 ListIterator li = staxenv.getHandlerStackIterator(currLevel); 082 while( li.hasPrevious() ) 083 { 084 Object ob = li.previous() ; 085 if( ( ob instanceof AGAVECompResultHandler ) || 086 ( ob instanceof AGAVESeqFeatureHandler ) ) 087 { 088 ( (AGAVECompResultHandler) ob ).addRelatedAnnot( related_annot ) ; 089 return ; 090 } 091 } 092 } 093 094 } 095 096 097}