001: package org.mandarax.xkb.framework;
002:
003: /**
004: * Copyright (C) 1999-2004 Jens Dietrich (mailto:mandarax@jbdietrich.com)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: import java.util.Map;
022:
023: import org.jdom.Element;
024: import org.mandarax.kernel.ConstantTerm;
025: import org.mandarax.kernel.LogicFactory;
026: import org.mandarax.xkb.XKBException;
027:
028: /**
029: * An adapter class for constant terms (=java classes).
030: * @see org.mandarax.kernel.ConstantTerm
031: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
032: * @version 3.4 <7 March 05>
033: * @since 1.6
034: * @deprecated from v 3.4 - support for new features such as validation will not be added to XKB, please use ZKB instead
035: */
036: public class XMLAdapter4ConstantTerms extends AbstractXMLAdapter {
037: public static final String CONSTANT_TERM = "ind";
038:
039: /**
040: * Export an object, i.e., convert it to an element in the DOM.
041: * @param obj an object
042: * @param driver the generic driver
043: * @param cache a cache used in order to associate the same
044: * id with various occurences of the same object
045: * @exception an XKBException is thrown if export fails
046: */
047: public Element exportObject(Object obj, GenericDriver driver,
048: Map cache) throws XKBException {
049: check(obj, ConstantTerm.class);
050: ConstantTerm constTerm = (ConstantTerm) obj;
051: Element e = new Element(CONSTANT_TERM);
052: // add type
053: Element et = exportObject(constTerm.getType(),
054: GenericDriver.TYPE, driver, cache);
055: e.addContent(et);
056: // add object
057: Element eo = exportObject(constTerm.getObject(),
058: GenericDriver.OBJECT, driver, cache);
059: e.addContent(eo);
060:
061: return e;
062: }
063:
064: /**
065: * Build an object from an XML element.
066: * @param e an element
067: * @param driver the generic driver
068: * @param cache a cache used to identify objects that have the same id
069: * @param lfactory the logic factory used to create objects
070: * @exception an XKBException is thrown if export fails
071: */
072: public Object importObject(Element e, GenericDriver driver,
073: Map cache, LogicFactory lfactory) throws XKBException {
074: // import type
075: Class type = (Class) importChild(e, GenericDriver.TYPE, driver,
076: cache, lfactory);
077:
078: // import object
079: Object obj = importChild(e, GenericDriver.OBJECT, driver,
080: cache, lfactory);
081: ;
082:
083: // assemble term
084: return lfactory.createConstantTerm(obj, type);
085: }
086:
087: /**
088: * Get the name of the associated tag (element).
089: * @return a string
090: */
091: public String getTagName() {
092: return CONSTANT_TERM;
093: }
094:
095: /**
096: * Get the kind of object the adapter can export/import.
097: * @return a string
098: */
099: public String getKindOfObject() {
100: return GenericDriver.CONSTANT_TERM;
101: }
102: }
|