Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart8.png 62% of files have more coverage
27   110   15   4.5
18   58   0.56   6
6     2.5  
1    
 
  PredicateDefinitionHandler       Line # 30 27 15 72.5% 0.7254902
 
  (102)
 
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.base.module.PredicateDefinition;
19    import org.qedeq.kernel.se.dto.module.PredicateDefinitionVo;
20    import org.qedeq.kernel.xml.common.XmlSyntaxException;
21    import org.qedeq.kernel.xml.handler.common.AbstractSimpleHandler;
22    import org.qedeq.kernel.xml.handler.common.SimpleAttributes;
23   
24   
25    /**
26    * Parse a predicate definition.
27    *
28    * @author Michael Meyling
29    */
 
30    public class PredicateDefinitionHandler extends AbstractSimpleHandler {
31   
32    /** Handler for formula. */
33    private final FormulaHandler formulaHandler;
34   
35    /** Handler for rule description. */
36    private final LatexListHandler descriptionHandler;
37   
38    /** Definition value object. */
39    private PredicateDefinitionVo definition;
40   
41    /** LaTeX pattern for the definition. */
42    private String latexPattern;
43   
44   
45    /**
46    * Deals with definitions.
47    *
48    * @param handler Parent handler.
49    */
 
50  614 toggle public PredicateDefinitionHandler(final AbstractSimpleHandler handler) {
51  614 super(handler, "DEFINITION_PREDICATE");
52  614 formulaHandler = new FormulaHandler(this);
53  614 descriptionHandler = new LatexListHandler(this, "DESCRIPTION");
54    }
55   
 
56  1284 toggle public final void init() {
57  1284 definition = null;
58  1284 latexPattern = null;
59    }
60   
61    /**
62    * Get definition.
63    *
64    * @return Definition.
65    */
 
66  1284 toggle public final PredicateDefinition getDefinition() {
67  1284 return definition;
68    }
69   
 
70  3852 toggle public final void startElement(final String name, final SimpleAttributes attributes)
71    throws XmlSyntaxException {
72  3852 if (getStartTag().equals(name)) {
73  1284 definition = new PredicateDefinitionVo();
74  1284 definition.setArgumentNumber(attributes.getString("arguments"));
75  1284 definition.setName(attributes.getString("name"));
76  2568 } else if ("LATEXPATTERN".equals(name)) {
77    // nothing to do yet
78  1284 } else if (formulaHandler.getStartTag().equals(name)) {
79  1284 changeHandler(formulaHandler, name, attributes);
80  0 } else if (descriptionHandler.getStartTag().equals(name)) {
81  0 changeHandler(descriptionHandler, name, attributes);
82    } else {
83  0 throw XmlSyntaxException.createUnexpectedTagException(name);
84    }
85    }
86   
 
87  3852 toggle public final void endElement(final String name) throws XmlSyntaxException {
88  3852 if (getStartTag().equals(name)) {
89    // nothing to do
90  2568 } else if ("LATEXPATTERN".equals(name)) {
91  1284 definition.setLatexPattern(latexPattern);
92  1284 } else if (formulaHandler.getStartTag().equals(name)) {
93  1284 definition.setFormula(formulaHandler.getFormula());
94  0 } else if (descriptionHandler.getStartTag().equals(name)) {
95  0 definition.setDescription(descriptionHandler.getLatexList());
96    } else {
97  0 throw XmlSyntaxException.createUnexpectedTagException(name);
98    }
99    }
100   
 
101  1284 toggle public final void characters(final String name, final String data) {
102  1284 if ("LATEXPATTERN".equals(name)) {
103  1284 latexPattern = data;
104    } else {
105  0 throw new RuntimeException("Unexpected character data in tag: " + name);
106    }
107    }
108   
109   
110    }