/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 */

package org.biojava.bio.program.ssbind;

import org.biojava.bio.program.xff.ElementRecognizer;
import org.biojava.utils.stax.DelegationManager;
import org.biojava.utils.stax.StAXContentHandler;
import org.biojava.utils.stax.StAXContentHandlerBase;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

/**
 * <code>HeaderStAXHandler</code> handles the Header element of
 * BioJava BlastLike XML.
 *
 * @author Keith James
 * @author Matthew Pocock
 * @since 1.3
 */
public class HeaderStAXHandler extends SeqSimilarityStAXHandler
{
    public static final StAXHandlerFactory HEADER_HANDLER_FACTORY =
        new StAXHandlerFactory()
        {
            public StAXContentHandler getHandler(SeqSimilarityStAXAdapter ssContext)
            {
                return new HeaderStAXHandler(ssContext);
            }
        };

    /**
     * Creates a new instance which sends callbacks to the specified
     * <code>SeqSimilarityStAXAdapter</code>.
     *
     * @param ssContext a <code>SeqSimilarityStAXAdapter</code>.
     */
    HeaderStAXHandler(SeqSimilarityStAXAdapter ssContext)
    {
        super(ssContext);

        addHandler(new ElementRecognizer.ByNSName(SeqSimilarityStAXAdapter.NAMESPACE,
                                                  "QueryId"),
                   new StAXHandlerFactory()
                   {
                       public StAXContentHandler getHandler(SeqSimilarityStAXAdapter ssContext)
                       {
                           return new QueryIDStAXHandler();
                       }
                   });

        addHandler(new ElementRecognizer.ByNSName(SeqSimilarityStAXAdapter.NAMESPACE,
                                                  "DatabaseId"),
                   new StAXHandlerFactory()
                   {
                       public StAXContentHandler getHandler(SeqSimilarityStAXAdapter ssContext)
                       {
                           return new DatabaseIDStAXHandler();
                       }
                   });
    }

    /**
     * <code>QueryIDStAXHandler</code> handles the query sequence ID.
     */
    private class QueryIDStAXHandler extends StAXContentHandlerBase
    {
        public void startElement(String            uri,
                                 String            localName,
                                 String            qName,
                                 Attributes        attr,
                                 DelegationManager dm)
        throws SAXException
        {
            ssContext.getSearchContentHandler().setQueryID(attr.getValue("id"));
        }
    }

    /**
     * <code>DatabaseIDStAXHandler</code> handles the database ID.
     */
    private class DatabaseIDStAXHandler extends StAXContentHandlerBase
    {
        public void startElement(String            uri,
                                 String            localName,
                                 String            qName,
                                 Attributes        attr,
                                 DelegationManager dm)
        throws SAXException
        {
            ssContext.getSearchContentHandler().setDatabaseID(attr.getValue("id"));
        }
    }
}

@@ -841,16 +841,72 @@
 erBase;%0A
+import org.biojava.utils.stax.StringElementHandlerBase;%0A
 import o
@@ -928,16 +928,16 @@
 ibutes;%0A
-
 import o
@@ -2218,24 +2218,485 @@
        %7D);%0A%0A
+        addHandler(new ElementRecognizer.ByNSName(SeqSimilarityStAXAdapter.NAMESPACE,%0A                                                  %22QueryDescription%22),%0A                   new StAXHandlerFactory()%0A                   %7B%0A                       public StAXContentHandler getHandler(SeqSimilarityStAXAdapter ssContext)%0A                       %7B%0A                           return new QueryDescriptionStAXHandler();%0A                       %7D%0A                   %7D);%0A%0A
         addH
@@ -3616,32 +3616,32 @@
 ption%0A        %7B%0A
-
             ssCo
@@ -3714,32 +3714,379 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * %3Ccode%3EQueryDescriptionStAXHandler%3C/code%3E handles the hit%0A     * description.%0A     */%0A    private class QueryDescriptionStAXHandler extends StringElementHandlerBase%0A    %7B%0A        protected void setStringValue(String s)%0A        %7B%0A            ssContext.getSearchContentHandler().addHitProperty(%22queryDescription%22, s);%0A        %7D%0A    %7D%0A%0A
     /**%0A     * %3C

add support for a query description element