Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart8.png 62% of files have more coverage
27   108   15   4.5
18   57   0.56   6
6     2.5  
1    
 
  FunctionDefinitionHandler       Line # 29 27 15 72.5% 0.7254902
 
  (101)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.xml.handler.module;
17   
18    import org.qedeq.kernel.se.dto.module.FunctionDefinitionVo;
19    import org.qedeq.kernel.xml.common.XmlSyntaxException;
20    import org.qedeq.kernel.xml.handler.common.AbstractSimpleHandler;
21    import org.qedeq.kernel.xml.handler.common.SimpleAttributes;
22   
23   
24    /**
25    * Parse a function definition.
26    *
27    * @author Michael Meyling
28    */
 
29    public class FunctionDefinitionHandler extends AbstractSimpleHandler {
30   
31    /** Handler for formulas. */
32    private final FormulaHandler formulaHandler;
33   
34    /** Handler for rule description. */
35    private final LatexListHandler descriptionHandler;
36   
37    /** Definition value object. */
38    private FunctionDefinitionVo definition;
39   
40    /** LaTeX pattern for the definition. */
41    private String latexPattern;
42   
43   
44    /**
45    * Deals with definitions.
46    *
47    * @param handler Parent handler.
48    */
 
49  614 toggle public FunctionDefinitionHandler(final AbstractSimpleHandler handler) {
50  614 super(handler, "DEFINITION_FUNCTION");
51  614 formulaHandler = new FormulaHandler(this);
52  614 descriptionHandler = new LatexListHandler(this, "DESCRIPTION");
53    }
54   
 
55  2586 toggle public final void init() {
56  2586 definition = null;
57  2586 latexPattern = null;
58    }
59   
60    /**
61    * Get definition.
62    *
63    * @return Definition.
64    */
 
65  2586 toggle public final FunctionDefinitionVo getDefinition() {
66  2586 return definition;
67    }
68   
 
69  7758 toggle public final void startElement(final String name, final SimpleAttributes attributes)
70    throws XmlSyntaxException {
71  7758 if (getStartTag().equals(name)) {
72  2586 definition = new FunctionDefinitionVo();
73  2586 definition.setArgumentNumber(attributes.getString("arguments"));
74  2586 definition.setName(attributes.getString("name"));
75  5172 } else if ("LATEXPATTERN".equals(name)) {
76    // nothing to do yet
77  2586 } else if (formulaHandler.getStartTag().equals(name)) {
78  2586 changeHandler(formulaHandler, name, attributes);
79  0 } else if (descriptionHandler.getStartTag().equals(name)) {
80  0 changeHandler(descriptionHandler, name, attributes);
81    } else {
82  0 throw XmlSyntaxException.createUnexpectedTagException(name);
83    }
84    }
85   
 
86  7758 toggle public final void endElement(final String name) throws XmlSyntaxException {
87  7758 if (getStartTag().equals(name)) {
88    // nothing to do
89  5172 } else if ("LATEXPATTERN".equals(name)) {
90  2586 definition.setLatexPattern(latexPattern);
91  2586 } else if (formulaHandler.getStartTag().equals(name)) {
92  2586 definition.setFormula(formulaHandler.getFormula());
93  0 } else if (descriptionHandler.getStartTag().equals(name)) {
94  0 definition.setDescription(descriptionHandler.getLatexList());
95    } else {
96  0 throw XmlSyntaxException.createUnexpectedTagException(name);
97    }
98    }
99   
 
100  2586 toggle public final void characters(final String name, final String data) {
101  2586 if ("LATEXPATTERN".equals(name)) {
102  2586 latexPattern = data;
103    } else {
104  0 throw new RuntimeException("Unexpected character data in tag: " + name);
105    }
106    }
107   
108    }