Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Okt 21 2006 08:24:31 CEST
file stats: LOC: 143   Methods: 7
NCLOC: 40   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractSimpleHandler.java 50% 83,3% 85,7% 81%
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  108 public AbstractSimpleHandler(final SaxDefaultHandler defaultHandler, final String startTag) {
 44  108 this.defaultHandler = defaultHandler;
 45  108 this.startTag = startTag;
 46    }
 47   
 48    /**
 49    * Constructor, should be used for creating handlers within handlers.
 50    *
 51    * @param handler Already existing simple handler.
 52    * @param startTag Start tag for this handler.
 53    */
 54  1225 public AbstractSimpleHandler(final AbstractSimpleHandler handler, final String startTag) {
 55  1225 this.defaultHandler = handler.defaultHandler;
 56  1225 this.startTag = startTag;
 57    }
 58   
 59    /**
 60    * Constructor, should be used for creating handlers within handlers.
 61    *
 62    * @param handler Already existing simple handler.
 63    */
 64  150 public AbstractSimpleHandler(final AbstractSimpleHandler handler) {
 65  150 this.defaultHandler = handler.defaultHandler;
 66  150 this.startTag = null;
 67    }
 68   
 69    /**
 70    * Must be called before a handler should parse a new section.
 71    */
 72    public abstract void init();
 73   
 74    /**
 75    * Called at begin of element <code>elementName</code>. Must be overwritten.
 76    *
 77    * @param elementName Tag name.
 78    * @param attributes Tag attributes.
 79    * @throws SyntaxException There is a semantic error in this event occurrence.
 80    */
 81    public abstract void startElement(final String elementName, final SimpleAttributes attributes)
 82    throws SyntaxException;
 83   
 84    /**
 85    * Called at end of element <code>elementName</code>. Must be overwritten.
 86    *
 87    * @param elementName Tag name.
 88    * @throws SyntaxException There is a semantic error in this event occurrence.
 89    */
 90    public abstract void endElement(final String elementName) throws SyntaxException;
 91   
 92    /**
 93    * Called at end of element <code>elementName</code>. Must be overwritten if you expect
 94    * character data.
 95    *
 96    * @param elementName Tag name.
 97    * @param value String value.
 98    * @throws SyntaxException There is a semantic error in this event occurrence.
 99    */
 100  0 public void characters(final String elementName, final String value) throws SyntaxException {
 101    // default implementation
 102  0 throw SyntaxException.createUnexpectedTextDataException(elementName, value);
 103    }
 104   
 105    /**
 106    * Change current handler to new one. The new handler gets automatically a
 107    * <code>beginElement</code> event.
 108    *
 109    * @param newHandler Handler that gets all the events now.
 110    * @param elementName Current element name.
 111    * @param attributes Current element attributes.
 112    * @throws SyntaxException New handler detected semantical problems.
 113    */
 114  3552 public final void changeHandler(final AbstractSimpleHandler newHandler,
 115    final String elementName, final SimpleAttributes attributes)
 116    throws SyntaxException {
 117  3552 if (newHandler.getStartTag() != null && !newHandler.getStartTag().equals(elementName)) {
 118  0 throw new RuntimeException(newHandler.getClass().getName() + " has start tag \""
 119    + newHandler.getStartTag() + "\", but should start with tag \""
 120    + elementName + "\"");
 121    }
 122  3552 defaultHandler.changeHandler(newHandler, elementName, attributes);
 123    }
 124   
 125    /**
 126    * Get current tag level.
 127    *
 128    * @return Current level.
 129    */
 130  942 public final int getLevel() {
 131  942 return defaultHandler.getLevel();
 132    }
 133   
 134    /**
 135    * Get start tag for this handler. Could be <code>null</code> if there is no specific start tag.
 136    *
 137    * @return Start tag.
 138    */
 139  42597 public final String getStartTag() {
 140  42597 return startTag;
 141    }
 142   
 143    }