ExistentialHandler.java
01 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
02  *
03  * Copyright 2000-2011,  Michael Meyling <mime@qedeq.org>.
04  *
05  * "Hilbert II" is free software; you can redistribute
06  * it and/or modify it under the terms of the GNU General Public
07  * License as published by the Free Software Foundation; either
08  * version 2 of the License, or (at your option) any later version.
09  *
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.Existential;
20 import org.qedeq.kernel.se.dto.module.ExistentialVo;
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 existential generalization rule usage.
29  *
30  @author  Michael Meyling
31  */
32 public class ExistentialHandler extends AbstractSimpleHandler {
33 
34     /** Rule value object. */
35     private Existential existential;
36 
37     /** Reference to previously proved formula. */
38     private String ref;
39 
40     /** Subject variable. */
41     private Element subjectVariable;
42 
43     /** Handle elements. */
44     private final ElementHandler elementHandler;
45 
46     /**
47      * Deals with definitions.
48      *
49      @param   handler Parent handler.
50      */
51     public ExistentialHandler(final AbstractSimpleHandler handler) {
52         super(handler, "EXISTENTIAL");
53         elementHandler = new ElementHandler(this);
54     }
55 
56     public final void init() {
57         existential = null;
58         subjectVariable = null;
59         ref = null;
60     }
61 
62     /**
63      * Get Substitute Predicate Variable Rule usage.
64      *
65      @return  Substitute Predicate Variable usage.
66      */
67     public final Existential getExistentialVo() {
68         return existential;
69     }
70 
71     public final void startElement(final String name, final SimpleAttributes attributes)
72             throws XmlSyntaxException {
73         if (getStartTag().equals(name)) {
74             ref = attributes.getString("ref");
75         else if ("VAR".equals(name)) {
76             changeHandler(elementHandler, name, attributes);
77         else {
78             throw XmlSyntaxException.createUnexpectedTagException(name);
79         }
80     }
81 
82     public final void endElement(final String namethrows XmlSyntaxException {
83         if (getStartTag().equals(name)) {
84             existential = new ExistentialVo(ref, subjectVariable);
85         else if ("VAR".equals(name)) {
86             subjectVariable = elementHandler.getElement();
87         else {
88             throw XmlSyntaxException.createUnexpectedTagException(name);
89         }
90     }
91 
92 }