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.dto.module.ConditionalProofVo; |
19 | import org.qedeq.kernel.xml.common.XmlSyntaxException; |
20 | import org.qedeq.kernel.xml.handler.common.AbstractSimpleHandler; |
21 | import org.qedeq.kernel.xml.handler.common.SimpleAttributes; |
22 | |
23 | |
24 | /** |
25 | * Parse a conditional proof rule usage. |
26 | * |
27 | * @author Michael Meyling |
28 | */ |
29 | public class ConditionalProofHandler extends AbstractSimpleHandler { |
30 | |
31 | /** Rule value object. */ |
32 | private ConditionalProofVo conditionalProof; |
33 | |
34 | /** Handle hypothesis. */ |
35 | private HypothesisHandler hypothesisHandler; |
36 | |
37 | /** Handle elements. */ |
38 | private FormalProofLineListHandler proofListHandler; |
39 | |
40 | /** Handle hypothesis. */ |
41 | private ConclusionHandler conclusionHandler; |
42 | |
43 | /** |
44 | * Deals with definitions. |
45 | * |
46 | * @param handler Parent handler. |
47 | */ |
48 | public ConditionalProofHandler(final AbstractSimpleHandler handler) { |
49 | super(handler, "CP"); |
50 | } |
51 | |
52 | public final void init() { |
53 | conditionalProof = null; |
54 | // we initialize the parsers only when really needed (so we have no recursive calls) |
55 | hypothesisHandler = new HypothesisHandler(this); |
56 | proofListHandler = new FormalProofLineListHandler(this); |
57 | conclusionHandler = new ConclusionHandler(this); |
58 | } |
59 | |
60 | /** |
61 | * Get conditional proof usage. |
62 | * |
63 | * @return Substitute Free Variable usage. |
64 | */ |
65 | public final ConditionalProofVo getConditionalProofVo() { |
66 | return conditionalProof; |
67 | } |
68 | |
69 | public final void startElement(final String name, final SimpleAttributes attributes) |
70 | throws XmlSyntaxException { |
71 | if (getStartTag().equals(name)) { |
72 | // ok |
73 | } else if (hypothesisHandler.getStartTag().equals(name)) { |
74 | changeHandler(hypothesisHandler, name, attributes); |
75 | } else if (proofListHandler.getStartTag().equals(name)) { |
76 | changeHandler(proofListHandler, name, attributes); |
77 | } else if (conclusionHandler.getStartTag().equals(name)) { |
78 | changeHandler(conclusionHandler, name, attributes); |
79 | } else { |
80 | throw XmlSyntaxException.createUnexpectedTagException(name); |
81 | } |
82 | } |
83 | |
84 | public final void endElement(final String name) throws XmlSyntaxException { |
85 | if (getStartTag().equals(name)) { |
86 | conditionalProof = new ConditionalProofVo(hypothesisHandler.getHypothesis(), |
87 | proofListHandler.getFormalProofLineList(), |
88 | conclusionHandler.getConclusion()); |
89 | } else if (hypothesisHandler.getStartTag().equals(name)) { |
90 | // ok |
91 | } else if (proofListHandler.getStartTag().equals(name)) { |
92 | // ok |
93 | } else if (conclusionHandler.getStartTag().equals(name)) { |
94 | // ok |
95 | } else { |
96 | throw XmlSyntaxException.createUnexpectedTagException(name); |
97 | } |
98 | } |
99 | |
100 | } |