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