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.Universal;
20 import org.qedeq.kernel.se.dto.module.UniversalVo;
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 UniversalHandler extends AbstractSimpleHandler {
33
34 /** Rule value object. */
35 private Universal universal;
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 UniversalHandler(final AbstractSimpleHandler handler) {
52 super(handler, "UNIVERSAL");
53 elementHandler = new ElementHandler(this);
54 }
55
56 public final void init() {
57 universal = null;
58 subjectVariable = null;
59 ref = null;
60 }
61
62 /**
63 * Get rule object.
64 *
65 * @return Universal generalization usage.
66 */
67 public final Universal getUniversalVo() {
68 return universal;
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 name) throws XmlSyntaxException {
83 if (getStartTag().equals(name)) {
84 universal = new UniversalVo(ref, subjectVariable);
85 } else if ("VAR".equals(name)) {
86 subjectVariable = elementHandler.getElement();
87 } else {
88 throw XmlSyntaxException.createUnexpectedTagException(name);
89 }
90 }
91
92 }
|