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.DynaBeanFunction;
27: import org.mandarax.xkb.XKBException;
28:
29: /**
30: * An adapter class for DynaBeanFunctions.
31: * @see org.mandarax.kernel.meta.DynaBeanFunction
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 2.2.1
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 XMLAdapter4DynaBeanFunctions extends AbstractXMLAdapter {
38: public static final String DYNA_BEAN_FUNCTION = "dynabeanfunction";
39: public static final String NAME = "name";
40: public static final String PROPERTY_NAME = "property_name";
41:
42: /**
43: * Export an object, i.e., convert it to an element in the DOM.
44: * @param obj an object
45: * @param driver the generic driver
46: * @param cache a cache used in order to associate the same
47: * id with various occurences of the same object
48: * @exception an XKBException is thrown if export fails
49: */
50: public Element exportObject(Object obj, GenericDriver driver,
51: Map cache) throws XKBException {
52: check(obj, org.mandarax.kernel.meta.DynaBeanFunction.class);
53: DynaBeanFunction f = (DynaBeanFunction) obj;
54: Element e = new Element(DYNA_BEAN_FUNCTION);
55: e.setAttribute(NAME, f.getName());
56: e.setAttribute(PROPERTY_NAME, f.getPropertyName());
57: Element eMethod = this .exportObject(f.getMethod(),
58: GenericDriver.METHOD, driver, cache);
59: e.addContent(eMethod);
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 export fails
70: */
71: public Object importObject(Element e, GenericDriver driver,
72: Map cache, LogicFactory lfactory) throws XKBException {
73: String name = e.getAttributeValue(NAME);
74: String propertyName = e.getAttributeValue(PROPERTY_NAME);
75: Method method = (Method) importChild(e, GenericDriver.METHOD,
76: driver, cache, lfactory);
77: return new DynaBeanFunction(method, propertyName, name);
78: }
79:
80: /**
81: * Get the name of the associated tag (element).
82: * @return a string
83: */
84: public String getTagName() {
85: return DYNA_BEAN_FUNCTION;
86: }
87:
88: /**
89: * Get the kind of object the adapter can export/import.
90: * @return a string
91: */
92: public String getKindOfObject() {
93: return GenericDriver.DYNA_BEAN_FUNCTION;
94: }
95: }
|