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.ArrayList; 023import java.util.List; 024 025import org.xml.sax.Attributes; 026import org.xml.sax.SAXException; 027 028/** 029 * 030 * @author Hanning Ni Doubletwist Inc 031 */ 032public class AGAVEClassificationHandler 033 extends StAXFeatureHandler 034 implements AGAVEIdAliasCallbackItf 035{ 036 public static final StAXHandlerFactory AGAVE_CLASSIFICATION_HANDLER_FACTORY 037 = new StAXHandlerFactory() { 038 public StAXContentHandler getHandler(StAXFeatureHandler staxenv) { 039 return new AGAVEClassificationHandler(staxenv); 040 } 041 }; 042 043 private List idAliases ; 044 AGAVEClassificationHandler(StAXFeatureHandler staxenv) { 045 // setup up environment stuff 046 super( staxenv ); 047 featureListener = staxenv.featureListener; 048 setHandlerCharacteristics("classification", true); 049 050 // setup handlers 051 // 052 super.addHandler(new ElementRecognizer.ByLocalName("description"), 053 AGAVEDescPropHandler.AGAVE_DESC_PROP_HANDLER_FACTORY); 054 // 055 super.addHandler(new ElementRecognizer.ByLocalName("id_alias"), 056 AGAVEIdAliasPropHandler.AGAVE_ID_ALIAS_PROP_HANDLER_FACTORY); 057 058 super.addHandler(new ElementRecognizer.ByLocalName("evidence"), 059 AGAVEEvidenceHandler.AGAVE_EVIDENCE_HANDLER_FACTORY); 060 061 062 } 063 064 public void startElementHandler( 065 String nsURI, 066 String localName, 067 String qName, 068 Attributes attrs) 069 throws SAXException 070 { 071 try{ 072 featureListener.startFeature( featureTemplate ); 073 boolean forFeature = true ; 074 setProperty( "system", attrs.getValue("system"), forFeature ) ; 075 setProperty( "id", attrs.getValue("id"), forFeature ) ; 076 setProperty( "type", attrs.getValue("type") , forFeature) ; 077 setProperty( "assigned_by", attrs.getValue("assigned_by"), forFeature ) ; 078 }catch(Exception e){ 079 throw new SAXException( e.getMessage() ) ; 080 } 081 } 082 083 084 public void addIdAlias(AGAVEIdAlias id) 085 { 086 if( idAliases == null ) 087 idAliases = new ArrayList(1) ; 088 idAliases.add( id ) ; 089 } 090 /* 091 protected Feature.Template createTemplate() { 092 // create Gene Template for this 093 StrandedFeature.Template st = new StrandedFeature.Template(); 094 095 // assume feature set to describe a transcript 096 st.type = "classification"; 097 st.strand = StrandedFeature.UNKNOWN; 098 // set up annotation bundle 099 st.annotation = annot; 100 st.location = new Location.EmptyLocation(); 101 if( staxenv != null ) 102 staxenv. subFeatures .add( this ) ; 103 104 return st; 105 }*/ 106 107 public void endElementHandler( 108 String nsURI, 109 String localName, 110 String qName, 111 StAXContentHandler handler) 112 throws SAXException 113 { 114 try{ 115 if( idAliases != null ) 116 annot.setProperty("id_alias", idAliases) ; 117 }catch(Exception e){ 118 throw new SAXException( e.getMessage() ) ; 119 } 120 } 121 122 123}