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.stax.DelegationManager;
025import org.biojava.utils.stax.StAXContentHandler;
026import org.biojava.utils.stax.StringElementHandlerBase;
027import org.xml.sax.Attributes;
028import org.xml.sax.SAXException;
029
030/**
031 * StAX handler for GAME <type> elements.
032 * derived from Thomas Down's PropDetailHandler
033 *
034 * @author David Huen
035 * @author Thomas Down
036 * @since 1.8
037 */
038public class GAMETypePropHandler extends StringElementHandlerBase {
039  // The <type> handler is context sensitive as the meaning of type depends on
040  // the element in which it is nested.
041  public static final StAXHandlerFactory GAME_TYPE_PROP_HANDLER_FACTORY = new StAXHandlerFactory() {
042          public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
043                 return new GAMETypePropHandler(staxenv);
044          }
045            } ;
046
047  private StAXFeatureHandler staxenv;
048
049  public GAMETypePropHandler(StAXFeatureHandler staxenv) {
050    super();
051    this.staxenv = staxenv;
052  }
053
054  public void startElement(String nsURI,
055                                    String localName,
056                                    String qName,
057                                    Attributes attrs,
058                                    DelegationManager dm)
059                     throws SAXException
060  {
061
062    super.startElement(nsURI, localName, qName, attrs, dm);
063  }
064
065  protected void setStringValue(String s)
066        throws SAXException
067  {
068      // if this is <feature_span, the string will decide the type of feature to create
069      String trimmed = s.trim();
070
071      if (trimmed.equals("translate offset")) {
072        // create a start codon annotation
073//        System.out.println("setting ATG");
074        staxenv.featureTemplate.type = "ATG";
075      }
076      else if (trimmed.equals("exon")) {
077        //  feature is an exon
078//        System.out.println("Setting exon");
079        staxenv.featureTemplate.type = "exon";
080      }
081   }
082}