001/**
002 *  BioJava development code This code may be freely distributed and modified
003 *  under the terms of the GNU Lesser General Public Licence. This should be
004 *  distributed with the code. If you do not have a copy, see:
005 *  http://www.gnu.org/copyleft/lesser.html Copyright for this code is held
006 *  jointly by the individual authors. These should be listed in
007 *
008 *@author    doc comments. For more information on the BioJava project and its
009 *      aims, or to join the biojava-l mailing list, visit the home page at:
010 *      http://www.biojava.org/
011 */
012
013package org.biojava.bio.seq.io.game12;
014
015import org.biojava.bio.seq.io.game.ElementRecognizer;
016import org.biojava.utils.stax.StAXContentHandler;
017import org.biojava.utils.stax.StringElementHandlerBase;
018import org.xml.sax.SAXException;
019
020/**
021 *  Handles the GAME <dbxref> element
022 *
023 * @author     David Huen
024 * @since      1.2
025 */
026public class GAMEDbxrefHandler
027         extends StAXFeatureHandler {
028    // <dbxref> is a container for external database references.
029    // it is possible that non-unique <dbxref> occur.
030
031    // temporary cache
032    String db_xref_db;
033    String db_xref_id;
034
035    // set up factory method
036    /**
037     *  Description of the Field
038     */
039    public final static StAXHandlerFactory GAME_DBXREF_HANDLER_FACTORY
040             =
041        new StAXHandlerFactory() {
042            public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
043                return new GAMEDbxrefHandler(staxenv);
044            }
045        };
046
047
048    /**
049     *  Constructor for the GAMEDbxrefHandler object
050     *
051     *@param  staxenv   Description of the Parameter
052     *@param  parentID  Description of the Parameter
053     */
054    GAMEDbxrefHandler(StAXFeatureHandler staxenv) {
055        // setup environment
056        super(staxenv);
057
058        // setup handlers
059        // <xref_db> : external database name
060        super.addHandler(new ElementRecognizer.ByLocalName("xref_db"),
061            new StAXHandlerFactory() {
062                public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
063                    return new XrefDbHandler();
064                }
065            }
066                );
067        // <db_xref_id> : external database id
068        super.addHandler(new ElementRecognizer.ByLocalName("db_xref_id"),
069            new StAXHandlerFactory() {
070                public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
071                    return new DbXrefIdHandler();
072                }
073            }
074                );
075    }
076
077    /**
078     *  retrieves the &lt;xref_db&gt; field.
079     */
080    private class XrefDbHandler extends StringElementHandlerBase {
081        protected void setStringValue(String s) {
082            db_xref_db = s.trim();
083        }
084    }
085
086    /**
087     *  retrieves the &lt;db_xref_id&gt; field.
088     */
089    private class DbXrefIdHandler extends StringElementHandlerBase {
090        protected void setStringValue(String s) {
091            db_xref_id = s.trim();
092        }
093    }
094
095    // does not have its own returnData() as it does not expect
096    // to have any returned to it.
097
098    public void endElementHandler(
099            String nsURI,
100            String localName,
101            String qName,
102            StAXContentHandler contentHandler) 
103        throws SAXException 
104    {
105        // validate before going further
106        if ((db_xref_db == null) || (db_xref_id == null)) {
107            return;
108        }
109    }
110}