Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Dez 22 2007 01:35:21 CET
file stats: LOC: 177   Methods: 7
NCLOC: 111   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ParserHandler.java 72,7% 78,6% 100% 77,6%
coverage coverage
 1    /* $Id: ParserHandler.java,v 1.5 2007/12/21 23:33:47 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.handler.parser;
 19   
 20    import java.util.ArrayList;
 21    import java.util.List;
 22   
 23    import org.qedeq.kernel.parser.Operator;
 24    import org.qedeq.kernel.xml.common.XmlSyntaxException;
 25    import org.qedeq.kernel.xml.parser.AbstractSimpleHandler;
 26    import org.qedeq.kernel.xml.parser.SaxDefaultHandler;
 27    import org.qedeq.kernel.xml.parser.SimpleAttributes;
 28   
 29   
 30    /**
 31    * Parses list of operators. Result is a list of all parsed operators.
 32    *
 33    * @version $Revision: 1.5 $
 34    * @author Michael Meyling
 35    */
 36    public final class ParserHandler extends AbstractSimpleHandler {
 37   
 38    /** List of all Operators. */
 39    private List operators = new ArrayList();
 40   
 41    /** Operator start symbol. */
 42    private String startSymbol;
 43   
 44    /** QEDEQ representation. E.g. "PREDCON". */
 45    private String qedeq;
 46   
 47    /** QEDEQ argument. E.g. "equal". */
 48    private String qedeqArgument;
 49   
 50    /** Operator priority. */
 51    private Integer priority;
 52   
 53    /** Minimum argument number. */
 54    private Integer min;
 55   
 56    /** Maximum argument number. */
 57    private Integer max;
 58   
 59   
 60    /**
 61    * Handle a parser XML file.
 62    *
 63    * @param defaultHandler Startup handler.
 64    */
 65  95 public ParserHandler(final SaxDefaultHandler defaultHandler) {
 66  95 super(defaultHandler, "parser");
 67    }
 68   
 69  94 public final void init() {
 70  94 operators.clear();
 71    }
 72   
 73    /**
 74    * Get list of operators.
 75    *
 76    * @return Operator list.
 77    */
 78  94 public final List getOperators() {
 79  94 return operators;
 80    }
 81   
 82  1638 public final void startElement(final String name, final SimpleAttributes attributes)
 83    throws XmlSyntaxException {
 84  1638 if (getStartTag().equals(name)) {
 85    // nothing todo
 86  1544 } else if ("prefixOperator".equals(name)) {
 87  511 setBasisAttributes(name, attributes);
 88  511 addOperator(Operator.SIMPLE_PREFIX);
 89  1033 } else if ("infixOperator".equals(name)) {
 90  777 setBasisAttributes(name, attributes);
 91  777 addOperator(Operator.INFIX);
 92  256 } else if ("functionOperator".equals(name)) {
 93  68 setBasisAttributes(name, attributes);
 94  68 addOperator(Operator.FUNCTION);
 95  188 } else if ("complexOperator".equals(name)) {
 96  188 setBasisAttributes(name, attributes);
 97  188 final String separatorSymbol = attributes.getString("separatorSymbol");
 98  188 if (separatorSymbol == null) {
 99  0 XmlSyntaxException.createEmptyAttributeException(name, "separatorSymbol");
 100    }
 101  188 if (separatorSymbol.length() == 0) {
 102  0 XmlSyntaxException.createMissingAttributeException(name, "separatorSymbol");
 103    }
 104  188 final String endSymbol = attributes.getString("endSymbol");
 105  188 if (endSymbol == null) {
 106  0 XmlSyntaxException.createEmptyAttributeException(name, "endSymbol");
 107    }
 108  188 if (endSymbol.length() == 0) {
 109  0 XmlSyntaxException.createMissingAttributeException(name, "endSymbol");
 110    }
 111  188 if (max == null) {
 112  94 operators.add(new Operator(startSymbol, separatorSymbol, endSymbol, qedeq,
 113    qedeqArgument, priority.intValue(), min.intValue()));
 114    } else {
 115  94 operators.add(new Operator(startSymbol, separatorSymbol, endSymbol, qedeq,
 116    qedeqArgument, priority.intValue(), min.intValue(), max.intValue()));
 117    }
 118    } else {
 119  0 throw XmlSyntaxException.createUnexpectedTagException(name);
 120    }
 121    }
 122   
 123  1356 private void addOperator(final int type) {
 124  1356 if (max == null) {
 125  574 operators.add(new Operator(startSymbol, qedeq, qedeqArgument, priority.intValue(),
 126    type, min.intValue()));
 127    } else {
 128  782 operators.add(new Operator(startSymbol, qedeq, qedeqArgument, priority.intValue(),
 129    type, min.intValue(), max.intValue()));
 130    }
 131    }
 132   
 133  1544 private void setBasisAttributes(final String element, final SimpleAttributes attributes)
 134    throws XmlSyntaxException {
 135  1544 startSymbol = attributes.getString("startSymbol");
 136  1544 if (startSymbol == null) {
 137  0 throw XmlSyntaxException.createMissingAttributeException(element, "startSymbol");
 138    }
 139  1544 if (startSymbol.length() == 0) {
 140  0 throw XmlSyntaxException.createEmptyAttributeException(element, "startSymbol");
 141    }
 142  1544 qedeq = attributes.getString("qedeq");
 143  1544 if (qedeq == null) {
 144  0 throw XmlSyntaxException.createMissingAttributeException(element, "qedeq");
 145    }
 146  1544 if (qedeq.length() == 0) {
 147  0 throw XmlSyntaxException.createEmptyAttributeException(element, "qedeq");
 148    }
 149  1544 qedeqArgument = attributes.getString("qedeqArgument");
 150  1544 priority = attributes.getInteger("priority");
 151  1544 if (priority == null || priority.intValue() < 0) {
 152  0 throw XmlSyntaxException.createMissingAttributeException(element, "priority");
 153    }
 154  1544 min = attributes.getInteger("min");
 155  1544 if (min == null) {
 156  0 min = new Integer(0);
 157    }
 158  1544 max = attributes.getInteger("max");
 159    }
 160   
 161  1638 public final void endElement(final String name) throws XmlSyntaxException {
 162  1638 if (getStartTag().equals(name)) {
 163    // nothing to do
 164  1544 } else if ("prefixOperator".equals(name)) {
 165    // nothing to do
 166  1033 } else if ("infixOperator".equals(name)) {
 167    // nothing to do
 168  256 } else if ("functionOperator".equals(name)) {
 169    // nothing to do
 170  188 } else if ("complexOperator".equals(name)) {
 171    // nothing to do
 172    } else {
 173  0 throw XmlSyntaxException.createUnexpectedTagException(name);
 174    }
 175    }
 176   
 177    }