Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart8.png 62% of files have more coverage
56   174   30   8
44   111   0.54   7
7     4.29  
1    
 
  ParserHandler       Line # 33 56 30 77.6% 0.7757009
 
  (99)
 
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.parser;
17   
18    import java.util.ArrayList;
19    import java.util.List;
20   
21    import org.qedeq.kernel.bo.parser.Operator;
22    import org.qedeq.kernel.xml.common.XmlSyntaxException;
23    import org.qedeq.kernel.xml.handler.common.AbstractSimpleHandler;
24    import org.qedeq.kernel.xml.handler.common.SaxDefaultHandler;
25    import org.qedeq.kernel.xml.handler.common.SimpleAttributes;
26   
27   
28    /**
29    * Parses list of operators. Result is a list of all parsed operators.
30    *
31    * @author Michael Meyling
32    */
 
33    public final class ParserHandler extends AbstractSimpleHandler {
34   
35    /** List of all Operators. */
36    private List operators = new ArrayList();
37   
38    /** Operator start symbol. */
39    private String startSymbol;
40   
41    /** QEDEQ representation. E.g. "PREDCON". */
42    private String qedeq;
43   
44    /** QEDEQ argument. E.g. "equal". */
45    private String qedeqArgument;
46   
47    /** Operator priority. */
48    private Integer priority;
49   
50    /** Minimum argument number. */
51    private Integer min;
52   
53    /** Maximum argument number. */
54    private Integer max;
55   
56   
57    /**
58    * Handle a parser XML file.
59    *
60    * @param defaultHandler Startup handler.
61    */
 
62  99 toggle public ParserHandler(final SaxDefaultHandler defaultHandler) {
63  99 super(defaultHandler, "parser");
64    }
65   
 
66  99 toggle public final void init() {
67  99 operators.clear();
68    }
69   
70    /**
71    * Get list of operators.
72    *
73    * @return Operator list.
74    */
 
75  99 toggle public final List getOperators() {
76  99 return operators;
77    }
78   
 
79  1791 toggle public final void startElement(final String name, final SimpleAttributes attributes)
80    throws XmlSyntaxException {
81  1791 if (getStartTag().equals(name)) {
82    // nothing todo
83  1692 } else if ("prefixOperator".equals(name)) {
84  545 setBasisAttributes(name, attributes);
85  545 addOperator(Operator.SIMPLE_PREFIX);
86  1147 } else if ("infixOperator".equals(name)) {
87  803 setBasisAttributes(name, attributes);
88  803 addOperator(Operator.INFIX);
89  344 } else if ("functionOperator".equals(name)) {
90  146 setBasisAttributes(name, attributes);
91  146 addOperator(Operator.FUNCTION);
92  198 } else if ("complexOperator".equals(name)) {
93  198 setBasisAttributes(name, attributes);
94  198 final String separatorSymbol = attributes.getString("separatorSymbol");
95  198 if (separatorSymbol == null) {
96  0 throw XmlSyntaxException.createEmptyAttributeException(name, "separatorSymbol");
97    }
98  198 if (separatorSymbol.length() == 0) {
99  0 throw XmlSyntaxException.createMissingAttributeException(name, "separatorSymbol");
100    }
101  198 final String endSymbol = attributes.getString("endSymbol");
102  198 if (endSymbol == null) {
103  0 throw XmlSyntaxException.createEmptyAttributeException(name, "endSymbol");
104    }
105  198 if (endSymbol.length() == 0) {
106  0 throw XmlSyntaxException.createMissingAttributeException(name, "endSymbol");
107    }
108  198 if (max == null) {
109  99 operators.add(new Operator(startSymbol, separatorSymbol, endSymbol, qedeq,
110    qedeqArgument, priority.intValue(), min.intValue()));
111    } else {
112  99 operators.add(new Operator(startSymbol, separatorSymbol, endSymbol, qedeq,
113    qedeqArgument, priority.intValue(), min.intValue(), max.intValue()));
114    }
115    } else {
116  0 throw XmlSyntaxException.createUnexpectedTagException(name);
117    }
118    }
119   
 
120  1494 toggle private void addOperator(final int type) {
121  1494 if (max == null) {
122  586 operators.add(new Operator(startSymbol, qedeq, qedeqArgument, priority.intValue(),
123    type, min.intValue()));
124    } else {
125  908 operators.add(new Operator(startSymbol, qedeq, qedeqArgument, priority.intValue(),
126    type, min.intValue(), max.intValue()));
127    }
128    }
129   
 
130  1692 toggle private void setBasisAttributes(final String element, final SimpleAttributes attributes)
131    throws XmlSyntaxException {
132  1692 startSymbol = attributes.getString("startSymbol");
133  1692 if (startSymbol == null) {
134  0 throw XmlSyntaxException.createMissingAttributeException(element, "startSymbol");
135    }
136  1692 if (startSymbol.length() == 0) {
137  0 throw XmlSyntaxException.createEmptyAttributeException(element, "startSymbol");
138    }
139  1692 qedeq = attributes.getString("qedeq");
140  1692 if (qedeq == null) {
141  0 throw XmlSyntaxException.createMissingAttributeException(element, "qedeq");
142    }
143  1692 if (qedeq.length() == 0) {
144  0 throw XmlSyntaxException.createEmptyAttributeException(element, "qedeq");
145    }
146  1692 qedeqArgument = attributes.getString("qedeqArgument");
147  1692 priority = attributes.getInteger("priority");
148  1692 if (priority == null || priority.intValue() < 0) {
149  0 throw XmlSyntaxException.createMissingAttributeException(element, "priority");
150    }
151  1692 min = attributes.getInteger("min");
152  1692 if (min == null) {
153  0 min = new Integer(0);
154    }
155  1692 max = attributes.getInteger("max");
156    }
157   
 
158  1791 toggle public final void endElement(final String name) throws XmlSyntaxException {
159  1791 if (getStartTag().equals(name)) {
160    // nothing to do
161  1692 } else if ("prefixOperator".equals(name)) {
162    // nothing to do
163  1147 } else if ("infixOperator".equals(name)) {
164    // nothing to do
165  344 } else if ("functionOperator".equals(name)) {
166    // nothing to do
167  198 } else if ("complexOperator".equals(name)) {
168    // nothing to do
169    } else {
170  0 throw XmlSyntaxException.createUnexpectedTagException(name);
171    }
172    }
173   
174    }