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 * @author Hanning Ni    Doubletwist Inc
030 */
031public class AGAVEQualifierPropHandler extends StAXPropertyHandler {
032
033
034   public static final StAXHandlerFactory AGAVE_QUALIFIER_PROP_HANDLER_FACTORY
035    = new StAXHandlerFactory() {
036    public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
037      return new AGAVEQualifierPropHandler(staxenv);
038    }
039   };
040
041   private String prop_type;
042   private String data_type ;
043   private String value ;
044    AGAVEQualifierPropHandler(StAXFeatureHandler staxenv) {
045    // execute superclass method to setup environment
046    super(staxenv);
047    setHandlerCharacteristics("qualifier", true);
048  }
049
050  public void startElementHandler(
051                String nsURI,
052                String localName,
053                String qName,
054                Attributes attrs)
055         throws SAXException
056  {
057      prop_type = attrs.getValue( "qualifier_type" ) ;
058      data_type = attrs.getValue( "data_type" )  ;
059  }
060   public void characters(char[] ch, int start, int length)
061        throws SAXException
062  {
063      value = new String(ch, start, length) ;  // THOMASD was taking whole array!
064  }
065  public void endElementHandler(
066                String nsURI,
067                String localName,
068                String qName,
069                StAXContentHandler handler)
070                throws SAXException
071  {
072       int currLevel = staxenv.getLevel();
073       if (currLevel >=1) {
074           ListIterator li = staxenv.getHandlerStackIterator(currLevel);
075           while( li.hasPrevious() )
076          {
077              Object ob =   li.previous() ;
078              if( ob instanceof AGAVESeqFeatureHandler )
079              {
080                  ( (AGAVESeqFeatureHandler) ob ).addProperty(
081                      new AGAVEProperty(AGAVEProperty.QUALIFIER, prop_type, data_type, value)) ;
082                   return ;
083              }
084           }
085       }
086
087  }
088
089
090}