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.lang.reflect.Method;
22: import java.util.Map;
23:
24: import org.jdom.Element;
25: import org.mandarax.kernel.LogicFactory;
26: import org.mandarax.kernel.meta.JFunction;
27: import org.mandarax.xkb.XKBException;
28:
29: /**
30: * An adapter class for JFunctions.
31: * @see org.mandarax.kernel.meta.JFunction
32: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
33: * @version 3.4 <7 March 05>
34: * @since 1.6
35: * @deprecated from v 3.4 - support for new features such as validation will not be added to XKB, please use ZKB instead
36: */
37: public class XMLAdapter4JFunctions extends AbstractXMLAdapter {
38: public static final String JFUNCTION = "jfunction";
39: public static final String NAME = "name";
40:
41: /**
42: * Export an object, i.e., convert it to an element in the DOM.
43: * @param obj an object
44: * @param driver the generic driver
45: * @param cache a cache used in order to associate the same
46: * id with various occurences of the same object
47: * @exception an XKBException is thrown if export fails
48: */
49: public Element exportObject(Object obj, GenericDriver driver,
50: Map cache) throws XKBException {
51: check(obj, org.mandarax.kernel.meta.JFunction.class);
52: JFunction f = (JFunction) obj;
53: Element e = new Element(JFUNCTION);
54: e.setAttribute(NAME, f.getName());
55: Element eMethod = this .exportObject(f.getMethod(),
56: GenericDriver.METHOD, driver, cache);
57: e.addContent(eMethod);
58: return e;
59: }
60:
61: /**
62: * Build an object from an XML element.
63: * @param e an element
64: * @param driver the generic driver
65: * @param cache a cache used to identify objects that have the same id
66: * @param lfactory the logic factory used to create objects
67: * @exception an XKBException is thrown if export fails
68: */
69: public Object importObject(Element e, GenericDriver driver,
70: Map cache, LogicFactory lfactory) throws XKBException {
71: String name = e.getAttributeValue(NAME);
72: Method method = (Method) importChild(e, GenericDriver.METHOD,
73: driver, cache, lfactory);
74: return new JFunction(method, name);
75: }
76:
77: /**
78: * Get the name of the associated tag (element).
79: * @return a string
80: */
81: public String getTagName() {
82: return JFUNCTION;
83: }
84:
85: /**
86: * Get the kind of object the adapter can export/import.
87: * @return a string
88: */
89: public String getKindOfObject() {
90: return GenericDriver.JFUNCTION;
91: }
92: }
|