| 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.list.Element; |
| 19 | import org.qedeq.kernel.se.base.module.Term; |
| 20 | import org.qedeq.kernel.se.dto.module.SubstFuncVo; |
| 21 | import org.qedeq.kernel.xml.common.XmlSyntaxException; |
| 22 | import org.qedeq.kernel.xml.handler.common.AbstractSimpleHandler; |
| 23 | import org.qedeq.kernel.xml.handler.common.SimpleAttributes; |
| 24 | import org.qedeq.kernel.xml.handler.list.ElementHandler; |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * Parse a Substitute Function Variable Rule usage. |
| 29 | * |
| 30 | * @author Michael Meyling |
| 31 | */ |
| 32 | public class SubstFuncvarHandler extends AbstractSimpleHandler { |
| 33 | |
| 34 | /** Rule value object. */ |
| 35 | private SubstFuncVo substFunc; |
| 36 | |
| 37 | /** Reference to previously proved formula. */ |
| 38 | private String ref; |
| 39 | |
| 40 | /** Function variable we want to substitute. */ |
| 41 | private Element functionVariable; |
| 42 | |
| 43 | /** Replacement term. */ |
| 44 | private Term substituteTerm; |
| 45 | |
| 46 | /** Handle terms. */ |
| 47 | private final TermHandler termHandler; |
| 48 | |
| 49 | /** Handle elements. */ |
| 50 | private final ElementHandler elementHandler; |
| 51 | |
| 52 | /** |
| 53 | * Deals with definitions. |
| 54 | * |
| 55 | * @param handler Parent handler. |
| 56 | */ |
| 57 | public SubstFuncvarHandler(final AbstractSimpleHandler handler) { |
| 58 | super(handler, "SUBST_FUNVAR"); |
| 59 | termHandler = new TermHandler(this); |
| 60 | elementHandler = new ElementHandler(this); |
| 61 | } |
| 62 | |
| 63 | public final void init() { |
| 64 | substFunc = null; |
| 65 | substituteTerm = null; |
| 66 | functionVariable = null; |
| 67 | ref = null; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get Substitute Function Variable Rule usage. |
| 72 | * |
| 73 | * @return Substitute Free Variable usage. |
| 74 | */ |
| 75 | public final SubstFuncVo getSubstFuncVo() { |
| 76 | return substFunc; |
| 77 | } |
| 78 | |
| 79 | public final void startElement(final String name, final SimpleAttributes attributes) |
| 80 | throws XmlSyntaxException { |
| 81 | if (getStartTag().equals(name)) { |
| 82 | ref = attributes.getString("ref"); |
| 83 | } else if ("FUNVAR".equals(name)) { |
| 84 | changeHandler(elementHandler, name, attributes); |
| 85 | } else if (termHandler.getStartTag().equals(name)) { |
| 86 | changeHandler(termHandler, name, attributes); |
| 87 | } else { |
| 88 | throw XmlSyntaxException.createUnexpectedTagException(name); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | public final void endElement(final String name) throws XmlSyntaxException { |
| 93 | if (getStartTag().equals(name)) { |
| 94 | substFunc = new SubstFuncVo(ref, functionVariable, |
| 95 | (substituteTerm != null ? substituteTerm.getElement() : null)); |
| 96 | } else if ("FUNVAR".equals(name)) { |
| 97 | functionVariable = elementHandler.getElement(); |
| 98 | } else if (termHandler.getStartTag().equals(name)) { |
| 99 | substituteTerm = termHandler.getTerm(); |
| 100 | } else { |
| 101 | throw XmlSyntaxException.createUnexpectedTagException(name); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | } |