01: package org.mandarax.xkb.framework;
02:
03: /**
04: * Copyright (C) 1999-2004 Jens Dietrich (mailto:mandarax@jbdietrich.com)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: import java.util.Map;
22:
23: import org.jdom.Element;
24: import org.mandarax.kernel.LogicFactory;
25: import org.mandarax.kernel.VariableTerm;
26: import org.mandarax.xkb.XKBException;
27:
28: /**
29: * An adapter class for variable terms.
30: * @see org.mandarax.kernel.VariableTerm
31: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
32: * @version 3.4 <7 March 05>
33: * @since 1.6
34: * @deprecated from v 3.4 - support for new features such as validation will not be added to XKB, please use ZKB instead
35: */
36: public class XMLAdapter4VariableTerms extends AbstractXMLAdapter {
37: public static final String VARIABLE_TERM = "var";
38: public static final String NAME = "name";
39:
40: /**
41: * Export an object, i.e., convert it to an element in the DOM.
42: * @param obj an object
43: * @param driver the generic driver
44: * @param cache a cache used in order to associate the same
45: * id with various occurences of the same object
46: * @exception an XKBException is thrown if export fails
47: */
48: public Element exportObject(Object obj, GenericDriver driver,
49: Map cache) throws XKBException {
50: check(obj, VariableTerm.class);
51: VariableTerm varTerm = (VariableTerm) obj;
52: Element e = new Element(VARIABLE_TERM);
53: // add name and type
54: e.setAttribute(NAME, varTerm.getName());
55: XMLAdapter adapter4Types = driver
56: .getAdapterByKindOfObject(GenericDriver.TYPE);
57: Element et = adapter4Types.exportObject(varTerm.getType(),
58: driver, cache);
59: e.addContent(et);
60: return e;
61: }
62:
63: /**
64: * Build an object from an XML element.
65: * @param e an element
66: * @param driver the generic driver
67: * @param cache a cache used to identify objects that have the same id
68: * @param lfactory the logic factory used to create objects
69: * @exception an XKBException is thrown if import fails
70: */
71: public Object importObject(Element e, GenericDriver driver,
72: Map cache, LogicFactory lfactory) throws XKBException {
73: String name = e.getAttribute(NAME).getValue();
74: XMLAdapter adapter4Types = driver
75: .getAdapterByKindOfObject(GenericDriver.TYPE);
76: Element typeElement = e.getChild(adapter4Types.getTagName());
77: Class type = (Class) adapter4Types.importObject(typeElement,
78: driver, cache, lfactory);
79: return lfactory.createVariableTerm(name, type);
80: }
81:
82: /**
83: * Get the name of the associated tag (element).
84: * @return a string
85: */
86: public String getTagName() {
87: return VARIABLE_TERM;
88: }
89:
90: /**
91: * Get the kind of object the adapter can export/import.
92: * @return a string
93: */
94: public String getKindOfObject() {
95: return GenericDriver.VARIABLE_TERM;
96: }
97: }
|