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.biojava.utils.ChangeVetoException;
026
027/**
028 * Deals with alternate sequence IDs
029 * 
030 * @author Hanning Ni     Doubletwist Inc
031 */
032public class AGAVEAltIdsPropHandler
033               extends StAXPropertyHandler implements AGAVEDbIdCallbackItf
034{
035  // set up factory method
036  public static final StAXHandlerFactory AGAVE_ALT_IDS_PROP_HANDLER_FACTORY
037    = new StAXHandlerFactory() {
038    public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
039      return new AGAVEAltIdsPropHandler(staxenv);
040    }
041  };
042
043
044  AGAVEAltIdsPropHandler(StAXFeatureHandler staxenv) {
045    // execute superclass method to setup environment
046    super(staxenv);
047
048    setHandlerCharacteristics("alt_ids", true);
049
050    super.addHandler(new ElementRecognizer.ByLocalName("db_id"),
051         AGAVEDbIdPropHandler.AGAVE_DBID_PROP_HANDLER_FACTORY);
052
053  }
054
055   public void addDbId(AGAVEDbId db_id)
056   {
057      try{
058         Object ob = UtilHelper.getProperty( staxenv.featureTemplate.annotation, "alt_ids");
059         if( ob != null )
060             ((List)ob).add( db_id ) ;
061         else
062         {
063             List kws = new ArrayList(1) ;
064             kws.add( db_id ) ;
065             staxenv.featureTemplate.annotation.setProperty("alt_ids", kws);
066         }
067      }catch (ChangeVetoException cve) {
068        cve.printStackTrace();
069      }
070   }
071}
072