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.xml.sax.Attributes;
026import org.xml.sax.SAXException;
027
028/**
029 * Handles the root GAME element
030 *
031 * @author David Huen
032 * @since 1.8
033 */
034public class GAMEHandler extends StAXFeatureHandler {
035  // there is only one GAME element encompassing the entire file
036  // in Gadfly GAME files.  We create a single feature template
037  // collect all its info into one annotation bundle.
038
039  public GAMEHandler() {
040    // set up environment
041    setHandlerCharacteristics("game", true);
042
043    // setup handlers
044       // <seq>
045       super.addHandler(new ElementRecognizer.ByLocalName("seq"), 
046         GAMESeqPropHandler.GAME_SEQ_PROP_HANDLER_FACTORY); 
047       // <map_position>
048       super.addHandler(new ElementRecognizer.ByLocalName("map_position"), 
049         GAMEMapPosPropHandler.GAME_MAP_POS_PROP_HANDLER_FACTORY); 
050       // <annotation>
051       super.addHandler(new ElementRecognizer.ByLocalName("annotation"), 
052         GAMEAnnotationHandler.GAME_ANNOTATION_HANDLER_FACTORY); 
053  }
054
055  public void startElementHandler(
056                String nsURI,
057                String localName,
058                String qName,
059                Attributes attrs,
060                DelegationManager dm)
061         throws SAXException
062  {
063    // check the element type
064    if (!(localName.equals( "game")) )
065      throw new SAXException("first element of file is not a game element");
066
067    // check file version
068    String version = attrs.getValue("version");
069    if (!(version.equals("1.001")) )
070      throw new SAXException("GAME version is not 1.001");
071
072//    System.out.println("GAMEHandler startElementHandler called, localName: " + localName);
073  }
074}
075