Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 129   Methods: 2
NCLOC: 69   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeInstance.java 0% 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3   
 4    Copyright (c) 2004-2005, OntoText Lab. / SIRMA
 5   
 6    This library is free software; you can redistribute it and/or modify it under
 7    the terms of the GNU Lesser General Public License as published by the Free
 8    Software Foundation; either version 2.1 of the License, or (at your option)
 9    any later version.
 10    This library is distributed in the hope that it will be useful, but WITHOUT
 11    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 12    FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 13    details.
 14    You should have received a copy of the GNU Lesser General Public License along
 15    with this library; if not, write to the Free Software Foundation, Inc.,
 16    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 17    */
 18    package com.ontotext.wsmo4j.parser.xml;
 19   
 20    /**
 21    * <p>Title: WSMO4J</p>
 22    * <p>Description: WSMO API and a Reference Implementation</p>
 23    * <p>Copyright: Copyright (c) 2004-2005</p>
 24    * <p>Company: OntoText Lab. / SIRMA </p>
 25    * @author not attributable
 26    * @version 1.0
 27    *
 28    */
 29   
 30    import java.util.*;
 31   
 32    import org.omwg.ontology.*;
 33    import org.w3c.dom.*;
 34    import org.wsmo.common.*;
 35    import org.wsmo.common.Entity;
 36    import org.wsmo.common.exception.*;
 37   
 38    import com.ontotext.wsmo4j.serializer.xml.*;
 39   
 40    /**
 41    * Helper type to serialize/deserialize xml element instance
 42    *
 43    * @author not attributable
 44    */
 45    class NodeInstance {
 46  0 static Instance deserialize(Node xmlNode, WsmlXmlParser parser) throws InvalidModelException {
 47  0 if (xmlNode == null || parser == null || xmlNode.getNodeName() != "instance"
 48    || xmlNode.getNodeType() != Node.ELEMENT_NODE) {
 49  0 throw new IllegalArgumentException();
 50    }
 51   
 52  0 IRI instanceIri = parser.getFactory()
 53    .createIRI(WsmlXmlHelper.getAttrValue(xmlNode, "name"));
 54  0 Instance instance = parser.getFactory().createInstance(instanceIri);
 55   
 56  0 NodeList nodes = xmlNode.getChildNodes();
 57  0 for (int i = 0; i < nodes.getLength(); i++) {
 58  0 Node node = nodes.item(i);
 59  0 if (node.getNodeName() == "memberOf" && node.getNodeType() == Node.ELEMENT_NODE) {
 60  0 IRI conceptIri = parser.getFactory().createIRI(WsmlXmlHelper.getElementText(node));
 61  0 instance.addConcept(parser.getFactory().getConcept(conceptIri));
 62    }
 63  0 else if (node.getNodeName() == "nonFunctionalProperties"
 64    && node.getNodeType() == Node.ELEMENT_NODE) {
 65  0 NodeNFP.deserialize(instance, node, parser);
 66    }
 67  0 else if (node.getNodeName() == "attributeValue"
 68    && node.getNodeType() == Node.ELEMENT_NODE) {
 69  0 IRI attrIri = parser.getFactory().createIRI(
 70    WsmlXmlHelper.getAttrValue(node, "name"));
 71  0 Value value = NodeValue.deserialize(WsmlXmlHelper.getFirstChildElement(node),
 72    parser);
 73  0 instance.addAttributeValue(attrIri, value);
 74    }
 75    }
 76   
 77  0 return instance;
 78    }
 79   
 80  0 static Element serialize(Instance instance, WsmlXmlSerializer serializer) {
 81  0 Element instanceElement = serializer.createElement("instance");
 82  0 instanceElement.setAttribute("name", instance.getIdentifier().toString());
 83   
 84  0 if (!instance.listConcepts().isEmpty()) {
 85  0 Object[] entities = instance.listConcepts().toArray();
 86  0 for (int i = 0; i < entities.length; i++) {
 87  0 Element memberOf = serializer.createElement("memberOf");
 88  0 instanceElement.appendChild(memberOf);
 89  0 memberOf.appendChild(serializer.createTextNode(((Entity) entities[i])
 90    .getIdentifier().toString()));
 91    }
 92    }
 93  0 if (!instance.listNFPValues().isEmpty()) {
 94  0 NodeNFP.serialize(instanceElement, instance, serializer);
 95    }
 96  0 if (!instance.listAttributeValues().isEmpty()) {
 97  0 for (Iterator i = instance.listAttributeValues().keySet().iterator(); i.hasNext();) {
 98  0 Identifier attrId = (Identifier) i.next();
 99  0 Element attributeValElement = serializer.createElement("attributeValue");
 100  0 attributeValElement.setAttribute("name", attrId.toString());
 101  0 instanceElement.appendChild(attributeValElement);
 102   
 103  0 Set datavalues = instance.listAttributeValues(attrId);
 104  0 for (Iterator j = datavalues.iterator(); j.hasNext();) {
 105  0 attributeValElement.appendChild(NodeValue.serialize(j.next(), serializer));
 106    }
 107    }
 108    }
 109   
 110  0 return instanceElement;
 111    }
 112    }
 113   
 114    /*
 115    * $Log$
 116    * Revision 1.2 2006/02/10 15:06:23 vassil_momtchev
 117    * addapted to the latest api changes
 118    *
 119    * Revision 1.1 2005/11/28 14:03:48 vassil_momtchev
 120    * package refactored from com.ontotext.wsmo4j.xmlparser to com.ontotext.wsmo4j.parser.xml
 121    *
 122    * Revision 1.3 2005/09/16 14:02:45 alex_simov
 123    * Identifier.asString() removed, use Object.toString() instead
 124    * (Implementations MUST override toString())
 125    *
 126    * Revision 1.2 2005/08/08 08:24:40 vassil_momtchev
 127    * javadoc added, bugfixes
 128    *
 129    */