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.SAXException;
026
027 /**
028  *
029  * @author Hanning Ni    Doubletwist Inc
030  */
031public class AGAVEEvidenceHandler
032               extends StAXFeatureHandler implements AGAVEEvidenceCallbackItf
033
034{
035  public static final StAXHandlerFactory AGAVE_EVIDENCE_HANDLER_FACTORY
036    = new StAXHandlerFactory() {
037    public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
038      return new AGAVEEvidenceHandler(staxenv);
039    }
040  };
041 private List element_ids ;
042
043 AGAVEEvidenceHandler(StAXFeatureHandler staxenv) {
044    // setup up environment stuff
045    super( staxenv );
046    featureListener = staxenv.featureListener;
047    setHandlerCharacteristics("evidence", true);
048
049    // setup handlers
050       //
051       super.addHandler(new ElementRecognizer.ByLocalName("element_id"),
052         AGAVEElementIdPropHandler.AGAVE_ELEMENT_ID_PROP_HANDLER_FACTORY);
053       super.addHandler(new ElementRecognizer.ByLocalName("comp_result"),
054         AGAVECompResultHandler.AGAVE_COMP_RESULT_HANDLER_FACTORY);
055
056  }
057
058  public void addElementId(String id)
059  {
060      if( element_ids == null )
061         element_ids = new ArrayList(1) ;
062      element_ids.add( id ) ;
063  }
064  /*
065  protected Feature.Template createTemplate() {
066    Feature.Template st = new Feature.Template();
067    st.type = "evidence";
068    st.annotation = annot;
069    if( staxenv != null )
070        staxenv. subFeatures .add( this ) ;
071
072    return st;
073  } */
074  public void endElementHandler(
075                String nsURI,
076                String localName,
077                String qName,
078                StAXContentHandler handler)
079              throws SAXException
080  {
081      try{
082          if( element_ids != null )
083              annot.setProperty("element_ids", element_ids ) ;
084      }catch(Exception e){
085          throw new SAXException( e.getMessage() ) ;
086      }
087  }
088}
089