Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Jan 11 2007 09:03:50 CET
file stats: LOC: 153   Methods: 8
NCLOC: 44   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractSimpleHandler.java 50% 85,7% 87,5% 83,3%
coverage coverage
 1    /* $Id: AbstractSimpleHandler.java,v 1.5 2006/10/20 20:23:04 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2006, Michael Meyling <mime@qedeq.org>.
 6    *
 7    * "Hilbert II" is free software; you can redistribute
 8    * it and/or modify it under the terms of the GNU General Public
 9    * License as published by the Free Software Foundation; either
 10    * version 2 of the License, or (at your option) any later version.
 11    *
 12    * This program is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15    * GNU General Public License for more details.
 16    */
 17   
 18    package org.qedeq.kernel.xml.parser;
 19   
 20   
 21    /**
 22    * Simple handler that gets SAX parser events. These events were received by the
 23    * {@link org.qedeq.kernel.xml.parser.SaxDefaultHandler} and are delegated to the
 24    * current {@link AbstractSimpleHandler}.
 25    *
 26    * @version $Revision: 1.5 $
 27    * @author Michael Meyling
 28    */
 29    public abstract class AbstractSimpleHandler {
 30   
 31    /** This handler gets the original SAX events. */
 32    private final SaxDefaultHandler defaultHandler;
 33   
 34    /** Start tag for this handler .*/
 35    private final String startTag;
 36   
 37    /**
 38    * Constructor.
 39    *
 40    * @param defaultHandler Original SAX event handler.
 41    * @param startTag Start tag for this handler.
 42    */
 43  110 public AbstractSimpleHandler(final SaxDefaultHandler defaultHandler, final String startTag) {
 44  110 this.defaultHandler = defaultHandler;
 45  110 this.startTag = startTag;
 46    }
 47   
 48    /**
 49    * Constructor.
 50    *
 51    * @param defaultHandler Original SAX event handler.
 52    */
 53  140 public AbstractSimpleHandler(final SaxDefaultHandler defaultHandler) {
 54  140 this.defaultHandler = defaultHandler;
 55  140 this.startTag = null;
 56    }
 57   
 58    /**
 59    * Constructor, should be used for creating handlers within handlers.
 60    *
 61    * @param handler Already existing simple handler.
 62    * @param startTag Start tag for this handler.
 63    */
 64  1323 public AbstractSimpleHandler(final AbstractSimpleHandler handler, final String startTag) {
 65  1323 this.defaultHandler = handler.defaultHandler;
 66  1323 this.startTag = startTag;
 67    }
 68   
 69    /**
 70    * Constructor, should be used for creating handlers within handlers.
 71    *
 72    * @param handler Already existing simple handler.
 73    */
 74  162 public AbstractSimpleHandler(final AbstractSimpleHandler handler) {
 75  162 this.defaultHandler = handler.defaultHandler;
 76  162 this.startTag = null;
 77    }
 78   
 79    /**
 80    * Must be called before a handler should parse a new section.
 81    */
 82    public abstract void init();
 83   
 84    /**
 85    * Called at begin of element <code>elementName</code>. Must be overwritten.
 86    *
 87    * @param elementName Tag name.
 88    * @param attributes Tag attributes.
 89    * @throws SyntaxException There is a semantic error in this event occurrence.
 90    */
 91    public abstract void startElement(final String elementName, final SimpleAttributes attributes)
 92    throws SyntaxException;
 93   
 94    /**
 95    * Called at end of element <code>elementName</code>. Must be overwritten.
 96    *
 97    * @param elementName Tag name.
 98    * @throws SyntaxException There is a semantic error in this event occurrence.
 99    */
 100    public abstract void endElement(final String elementName) throws SyntaxException;
 101   
 102    /**
 103    * Called at end of element <code>elementName</code>. Must be overwritten if you expect
 104    * character data.
 105    *
 106    * @param elementName Tag name.
 107    * @param value String value.
 108    * @throws SyntaxException There is a semantic error in this event occurrence.
 109    */
 110  0 public void characters(final String elementName, final String value) throws SyntaxException {
 111    // default implementation
 112  0 throw SyntaxException.createUnexpectedTextDataException(elementName, value);
 113    }
 114   
 115    /**
 116    * Change current handler to new one. The new handler gets automatically a
 117    * <code>beginElement</code> event.
 118    *
 119    * @param newHandler Handler that gets all the events now.
 120    * @param elementName Current element name.
 121    * @param attributes Current element attributes.
 122    * @throws SyntaxException New handler detected semantical problems.
 123    */
 124  3666 public final void changeHandler(final AbstractSimpleHandler newHandler,
 125    final String elementName, final SimpleAttributes attributes)
 126    throws SyntaxException {
 127  3666 if (newHandler.getStartTag() != null && !newHandler.getStartTag().equals(elementName)) {
 128  0 throw new RuntimeException(newHandler.getClass().getName() + " has start tag \""
 129    + newHandler.getStartTag() + "\", but should start with tag \""
 130    + elementName + "\"");
 131    }
 132  3666 defaultHandler.changeHandler(newHandler, elementName, attributes);
 133    }
 134   
 135    /**
 136    * Get current tag level.
 137    *
 138    * @return Current level.
 139    */
 140  942 public final int getLevel() {
 141  942 return defaultHandler.getLevel();
 142    }
 143   
 144    /**
 145    * Get start tag for this handler. Could be <code>null</code> if there is no specific start tag.
 146    *
 147    * @return Start tag.
 148    */
 149  43772 public final String getStartTag() {
 150  43772 return startTag;
 151    }
 152   
 153    }