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 */
021
022package org.biojava.bio.seq.io.game;
023
024import org.biojava.utils.ChangeVetoException;
025import org.biojava.utils.stax.StAXContentHandler;
026import org.xml.sax.Attributes;
027import org.xml.sax.SAXException;
028
029/**
030 * Handles the GAME <gene> element
031 *
032 * @author David Huen
033 * @since 1.8
034 */
035public class GAMEGenePropHandler 
036               extends StAXPropertyHandler
037               implements GAMENameCallbackItf {   
038  // this element provides basic identification of the gene
039  // as a homolog/paralog/maybe/is.
040  String association;
041  
042  // set up factory method
043  public static final StAXHandlerFactory GAME_GENE_PROP_HANDLER_FACTORY 
044    = new StAXHandlerFactory() {
045    public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
046      return new GAMEGenePropHandler(staxenv);
047    }
048  };
049
050  GAMEGenePropHandler(StAXFeatureHandler staxenv) {
051    // execute superclass method to setup environment
052    super(staxenv);
053    setHandlerCharacteristics("gene", true);
054
055    // setup handlers
056    super.addHandler(new ElementRecognizer.ByLocalName("name"),
057      GAMENamePropHandler.GAME_NAME_PROP_HANDLER_FACTORY);
058    // <dbxref>
059    super.addHandler(new ElementRecognizer.ByLocalName("dbxref"),
060      GAMEDbxrefPropHandler.GAME_DBXREF_PROP_HANDLER_FACTORY);
061  }
062
063  public void NameSetStringValue(String s) {
064//    System.out.println("GAMEGenePropHandler.NameSetStringValue: entering. ");
065    if (association.equals("IS")) {
066//       System.out.println("GAMEGenePropHandler.NameSetStringValue: assoc IS. ");
067      // set gene name
068      try {
069//       System.out.println("GAMEGenePropHandler setting id to " + s);
070       staxenv.featureTemplate.annotation.setProperty("id", s.trim());
071      }
072      catch (ChangeVetoException cve) {
073        // baulk and discard exception
074        System.err.println("GAMEGenPropHandler: change vetoed");
075      }
076    }
077  }
078
079  public void startElementHandler(
080                String nsURI,
081                String localName,
082                String qName,
083                Attributes attrs)
084         throws SAXException
085  {
086    // determine association type
087    association = attrs.getValue("association");
088//    System.out.println("GAMEGenePropHandler.startElementHandler: association is " + association);
089  }
090}
091