Clover Coverage Report
Coverage timestamp: Fri Feb 14 2014 07:28:57 UTC
../../../../../../img/srcFileCovDistChart8.png 62% of files have more coverage
27   111   15   4.5
18   59   0.56   6
6     2.5  
1    
 
  InitialPredicateDefinitionHandler       Line # 31 27 15 72.5% 0.7254902
 
  (116)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2014, 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.InitialPredicateDefinition;
19    import org.qedeq.kernel.se.dto.module.InitialPredicateDefinitionVo;
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    import org.qedeq.kernel.xml.handler.list.ElementHandler;
24   
25   
26    /**
27    * Parse an initial predicate definition.
28    *
29    * @author Michael Meyling
30    */
 
31    public class InitialPredicateDefinitionHandler extends AbstractSimpleHandler {
32   
33    /** Handler for an element. */
34    private final ElementHandler elementHandler;
35   
36    /** Handler for predicate description. */
37    private final LatexListHandler descriptionHandler;
38   
39    /** Definition value object. */
40    private InitialPredicateDefinitionVo definition;
41   
42    /** LaTeX pattern for the definition. */
43    private String latexPattern;
44   
45   
46    /**
47    * Deals with definitions.
48    *
49    * @param handler Parent handler.
50    */
 
51  680 toggle public InitialPredicateDefinitionHandler(final AbstractSimpleHandler handler) {
52  680 super(handler, "DEFINITION_PREDICATE_INITIAL");
53  680 elementHandler = new ElementHandler(this);
54  680 descriptionHandler = new LatexListHandler(this, "DESCRIPTION");
55    }
56   
 
57  393 toggle public final void init() {
58  393 definition = null;
59  393 latexPattern = null;
60    }
61   
62    /**
63    * Get definition.
64    *
65    * @return Definition.
66    */
 
67  393 toggle public final InitialPredicateDefinition getInitialDefinition() {
68  393 return definition;
69    }
70   
 
71  1179 toggle public final void startElement(final String name, final SimpleAttributes attributes)
72    throws XmlSyntaxException {
73  1179 if (getStartTag().equals(name)) {
74  393 definition = new InitialPredicateDefinitionVo();
75  393 definition.setArgumentNumber(attributes.getString("arguments"));
76  393 definition.setName(attributes.getString("name"));
77  786 } else if ("LATEXPATTERN".equals(name)) {
78    // nothing to do yet
79  393 } else if ("PREDCON".equals(name)) {
80  393 changeHandler(elementHandler, name, attributes);
81  0 } else if (descriptionHandler.getStartTag().equals(name)) {
82  0 changeHandler(descriptionHandler, name, attributes);
83    } else {
84  0 throw XmlSyntaxException.createUnexpectedTagException(name);
85    }
86    }
87   
 
88  1179 toggle public final void endElement(final String name) throws XmlSyntaxException {
89  1179 if (getStartTag().equals(name)) {
90    // nothing to do
91  786 } else if ("LATEXPATTERN".equals(name)) {
92  393 definition.setLatexPattern(latexPattern);
93  393 } else if ("PREDCON".equals(name)) {
94  393 definition.setPredCon(elementHandler.getElement());
95  0 } else if (descriptionHandler.getStartTag().equals(name)) {
96  0 definition.setDescription(descriptionHandler.getLatexList());
97    } else {
98  0 throw XmlSyntaxException.createUnexpectedTagException(name);
99    }
100    }
101   
 
102  393 toggle public final void characters(final String name, final String data) {
103  393 if ("LATEXPATTERN".equals(name)) {
104  393 latexPattern = data;
105    } else {
106  0 throw new RuntimeException("Unexpected character data in tag: " + name);
107    }
108    }
109   
110   
111    }