Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
../../../../../../img/srcFileCovDistChart8.png 50% of files have more coverage
32   119   17   5.33
22   64   0.53   6
6     2.83  
1    
 
  PredicateDefinitionHandler       Line # 31 32 17 76.7% 0.76666665
 
  (55)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, 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.base.module.PredicateDefinition;
19    import org.qedeq.kernel.dto.module.PredicateDefinitionVo;
20    import org.qedeq.kernel.xml.common.XmlSyntaxException;
21    import org.qedeq.kernel.xml.parser.AbstractSimpleHandler;
22    import org.qedeq.kernel.xml.parser.SimpleAttributes;
23   
24   
25    /**
26    * Parse a predicate definition.
27    *
28    * @version $Revision: 1.1 $
29    * @author Michael Meyling
30    */
 
31    public class PredicateDefinitionHandler extends AbstractSimpleHandler {
32   
33    /** Handler for a variable list. */
34    private final VariableListHandler variableListHandler;
35   
36    /** Handler for formulas or terms. */
37    private final FormulaHandler formulaHandler;
38   
39    /** Handler for rule description. */
40    private final LatexListHandler descriptionHandler;
41   
42    /** Definition value object. */
43    private PredicateDefinitionVo definition;
44   
45    /** LaTeX pattern for the definition. */
46    private String latexPattern;
47   
48   
49    /**
50    * Deals with definitions.
51    *
52    * @param handler Parent handler.
53    */
 
54  177 toggle public PredicateDefinitionHandler(final AbstractSimpleHandler handler) {
55  177 super(handler, "DEFINITION_PREDICATE");
56  177 variableListHandler = new VariableListHandler(this);
57  177 formulaHandler = new FormulaHandler(this);
58  177 descriptionHandler = new LatexListHandler(this, "DESCRIPTION");
59    }
60   
 
61  262 toggle public final void init() {
62  262 definition = null;
63  262 latexPattern = null;
64    }
65   
66    /**
67    * Get definition.
68    *
69    * @return Definition.
70    */
 
71  262 toggle public final PredicateDefinition getDefinition() {
72  262 return definition;
73    }
74   
 
75  945 toggle public final void startElement(final String name, final SimpleAttributes attributes)
76    throws XmlSyntaxException {
77  945 if (getStartTag().equals(name)) {
78  262 definition = new PredicateDefinitionVo();
79  262 definition.setArgumentNumber(attributes.getString("arguments"));
80  262 definition.setName(attributes.getString("name"));
81  683 } else if ("LATEXPATTERN".equals(name)) {
82    // nothing to do yet
83  421 } else if (variableListHandler.getStartTag().equals(name)) {
84  244 changeHandler(variableListHandler, name, attributes);
85  177 } else if (formulaHandler.getStartTag().equals(name)) {
86  177 changeHandler(formulaHandler, name, attributes);
87  0 } else if (descriptionHandler.getStartTag().equals(name)) {
88  0 changeHandler(descriptionHandler, name, attributes);
89    } else {
90  0 throw XmlSyntaxException.createUnexpectedTagException(name);
91    }
92    }
93   
 
94  945 toggle public final void endElement(final String name) throws XmlSyntaxException {
95  945 if (getStartTag().equals(name)) {
96    // nothing to do
97  683 } else if ("LATEXPATTERN".equals(name)) {
98  262 definition.setLatexPattern(latexPattern);
99  421 } else if (variableListHandler.getStartTag().equals(name)) {
100  244 definition.setVariableList(variableListHandler.getVariables());
101  177 } else if (formulaHandler.getStartTag().equals(name)) {
102  177 definition.setFormula(formulaHandler.getFormula());
103  0 } else if (descriptionHandler.getStartTag().equals(name)) {
104  0 definition.setDescription(descriptionHandler.getLatexList());
105    } else {
106  0 throw XmlSyntaxException.createUnexpectedTagException(name);
107    }
108    }
109   
 
110  262 toggle public final void characters(final String name, final String data) {
111  262 if ("LATEXPATTERN".equals(name)) {
112  262 latexPattern = data;
113    } else {
114  0 throw new RuntimeException("Unexpected character data in tag: " + name);
115    }
116    }
117   
118   
119    }