Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mai 10 2007 03:16:40 CEST
file stats: LOC: 155   Methods: 8
NCLOC: 45   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.8 2007/04/12 23:50:07 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, 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    import org.qedeq.kernel.common.SyntaxException;
 21   
 22   
 23    /**
 24    * Simple handler that gets SAX parser events. These events were received by the
 25    * {@link org.qedeq.kernel.xml.parser.SaxDefaultHandler} and are delegated to the
 26    * current {@link AbstractSimpleHandler}.
 27    *
 28    * @version $Revision: 1.8 $
 29    * @author Michael Meyling
 30    */
 31    public abstract class AbstractSimpleHandler {
 32   
 33    /** This handler gets the original SAX events. */
 34    private final SaxDefaultHandler defaultHandler;
 35   
 36    /** Start tag for this handler .*/
 37    private final String startTag;
 38   
 39    /**
 40    * Constructor.
 41    *
 42    * @param defaultHandler Original SAX event handler.
 43    * @param startTag Start tag for this handler.
 44    */
 45  130 public AbstractSimpleHandler(final SaxDefaultHandler defaultHandler, final String startTag) {
 46  130 this.defaultHandler = defaultHandler;
 47  130 this.startTag = startTag;
 48    }
 49   
 50    /**
 51    * Constructor.
 52    *
 53    * @param defaultHandler Original SAX event handler.
 54    */
 55  137 public AbstractSimpleHandler(final SaxDefaultHandler defaultHandler) {
 56  137 this.defaultHandler = defaultHandler;
 57  137 this.startTag = null;
 58    }
 59   
 60    /**
 61    * Constructor, should be used for creating handlers within handlers.
 62    *
 63    * @param handler Already existing simple handler.
 64    * @param startTag Start tag for this handler.
 65    */
 66  2254 public AbstractSimpleHandler(final AbstractSimpleHandler handler, final String startTag) {
 67  2254 this.defaultHandler = handler.defaultHandler;
 68  2254 this.startTag = startTag;
 69    }
 70   
 71    /**
 72    * Constructor, should be used for creating handlers within handlers.
 73    *
 74    * @param handler Already existing simple handler.
 75    */
 76  276 public AbstractSimpleHandler(final AbstractSimpleHandler handler) {
 77  276 this.defaultHandler = handler.defaultHandler;
 78  276 this.startTag = null;
 79    }
 80   
 81    /**
 82    * Must be called before a handler should parse a new section.
 83    */
 84    public abstract void init();
 85   
 86    /**
 87    * Called at begin of element <code>elementName</code>. Must be overwritten.
 88    *
 89    * @param elementName Tag name.
 90    * @param attributes Tag attributes.
 91    * @throws SyntaxException There is a semantic error in this event occurrence.
 92    */
 93    public abstract void startElement(final String elementName, final SimpleAttributes attributes)
 94    throws SyntaxException;
 95   
 96    /**
 97    * Called at end of element <code>elementName</code>. Must be overwritten.
 98    *
 99    * @param elementName Tag name.
 100    * @throws SyntaxException There is a semantic error in this event occurrence.
 101    */
 102    public abstract void endElement(final String elementName) throws SyntaxException;
 103   
 104    /**
 105    * Called at end of element <code>elementName</code>. Must be overwritten if you expect
 106    * character data.
 107    *
 108    * @param elementName Tag name.
 109    * @param value String value.
 110    * @throws SyntaxException There is a semantic error in this event occurrence.
 111    */
 112  0 public void characters(final String elementName, final String value) throws SyntaxException {
 113    // default implementation
 114  0 throw SyntaxException.createUnexpectedTextDataException(elementName, value);
 115    }
 116   
 117    /**
 118    * Change current handler to new one. The new handler gets automatically a
 119    * <code>beginElement</code> event.
 120    *
 121    * @param newHandler Handler that gets all the events now.
 122    * @param elementName Current element name.
 123    * @param attributes Current element attributes.
 124    * @throws SyntaxException New handler detected semantical problems.
 125    */
 126  7254 public final void changeHandler(final AbstractSimpleHandler newHandler,
 127    final String elementName, final SimpleAttributes attributes)
 128    throws SyntaxException {
 129  7254 if (newHandler.getStartTag() != null && !newHandler.getStartTag().equals(elementName)) {
 130  0 throw new RuntimeException(newHandler.getClass().getName() + " has start tag \""
 131    + newHandler.getStartTag() + "\", but should start with tag \""
 132    + elementName + "\"");
 133    }
 134  7254 defaultHandler.changeHandler(newHandler, elementName, attributes);
 135    }
 136   
 137    /**
 138    * Get current tag level.
 139    *
 140    * @return Current level.
 141    */
 142  1962 public final int getLevel() {
 143  1962 return defaultHandler.getLevel();
 144    }
 145   
 146    /**
 147    * Get start tag for this handler. Could be <code>null</code> if there is no specific start tag.
 148    *
 149    * @return Start tag.
 150    */
 151  84701 public final String getStartTag() {
 152  84701 return startTag;
 153    }
 154   
 155    }