Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 250   Methods: 2
NCLOC: 170   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeConcept.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.deri.wsmo4j.logicalexpression.*;
 33    import org.omwg.ontology.*;
 34    import org.w3c.dom.*;
 35    import org.wsmo.common.*;
 36    import org.wsmo.common.Entity;
 37    import org.wsmo.common.exception.*;
 38   
 39    import com.ontotext.wsmo4j.serializer.xml.*;
 40   
 41    /**
 42    * Helper type to serialize/deserialize xml element concept
 43    *
 44    * @author not attributable
 45    */
 46    class NodeConcept {
 47  0 static Concept deserialize(Node xmlNode, WsmlXmlParser parser) throws InvalidModelException {
 48  0 if (xmlNode == null || parser == null || xmlNode.getNodeName() != "concept") {
 49  0 throw new IllegalArgumentException();
 50    }
 51   
 52  0 IRI iriConcept = parser.getFactory().createIRI(WsmlXmlHelper.getAttrValue(xmlNode, "name"));
 53  0 Concept concept = parser.getFactory().createConcept(iriConcept);
 54   
 55  0 NodeList nodes = xmlNode.getChildNodes();
 56  0 for (int i = 0; i < nodes.getLength(); i++) {
 57  0 Node node = nodes.item(i);
 58   
 59  0 if (node.getNodeName() == "superConcept" && node.getNodeType() == Node.ELEMENT_NODE) {
 60  0 IRI scIri = parser.getFactory().createIRI(WsmlXmlHelper.getElementText(node));
 61  0 Concept superConcept = parser.getFactory().getConcept(scIri);
 62  0 concept.addSuperConcept(superConcept);
 63  0 superConcept.addSubConcept(concept);
 64    }
 65  0 else if (node.getNodeName() == "nonFunctionalProperties"
 66    && node.getNodeType() == Node.ELEMENT_NODE) {
 67  0 NodeNFP.deserialize(concept, node, parser);
 68    }
 69  0 else if (node.getNodeName() == "attribute" && node.getNodeType() == Node.ELEMENT_NODE) {
 70  0 IRI attrIri = parser.getFactory().createIRI(
 71    WsmlXmlHelper.getAttrValue(node, "name"));
 72  0 Attribute attr = concept.createAttribute(attrIri);
 73  0 String attrType = WsmlXmlHelper.getAttrValue(node, "type");
 74   
 75  0 if (attrType.equals("inferring")) {
 76  0 attr.setConstraining(false);
 77    }
 78    else {
 79  0 attr.setConstraining(true);
 80    }
 81   
 82  0 NodeList attrNodes = node.getChildNodes();
 83  0 IRI inverseAttrIRI = null;
 84  0 for (int j = 0; j < attrNodes.getLength(); j++) {
 85  0 Node attrNode = attrNodes.item(j);
 86  0 if (attrNode.getNodeName() == "range"
 87    && attrNode.getNodeType() == Node.ELEMENT_NODE) {
 88  0 ConstantTransformer cf = ConstantTransformer.getInstance();
 89  0 String type = WsmlXmlHelper.getElementText(attrNode);
 90  0 if (cf.isDataType(type)) {
 91  0 attr.addType(parser.getDataFactory().createWsmlDataType(type));
 92    }
 93    else {
 94  0 attr.addType(parser.getFactory().createConcept(
 95    parser.getFactory().createIRI(type)));
 96    }
 97    }
 98  0 else if (attrNode.getNodeName() == "symmetric"
 99    && attrNode.getNodeType() == Node.ELEMENT_NODE) {
 100  0 attr.setSymmetric(true);
 101    }
 102  0 else if (attrNode.getNodeName() == "transitive"
 103    && attrNode.getNodeType() == Node.ELEMENT_NODE) {
 104  0 attr.setTransitive(true);
 105    }
 106  0 else if (attrNode.getNodeName() == "reflexive"
 107    && attrNode.getNodeType() == Node.ELEMENT_NODE) {
 108  0 attr.setReflexive(true);
 109    }
 110  0 else if (attrNode.getNodeName() == "inverseOf"
 111    && attrNode.getNodeType() == Node.ELEMENT_NODE) {
 112  0 inverseAttrIRI = parser.getFactory().createIRI(
 113    WsmlXmlHelper.getAttrValue(attrNode, "type"));
 114  0 attr.setInverseOf(inverseAttrIRI);
 115    }
 116  0 else if (attrNode.getNodeName() == "minCardinality"
 117    && attrNode.getNodeType() == Node.ELEMENT_NODE) {
 118  0 attr.setMinCardinality(Integer.parseInt(WsmlXmlHelper
 119    .getElementText(attrNode)));
 120    }
 121  0 else if (attrNode.getNodeName() == "maxCardinality"
 122    && attrNode.getNodeType() == Node.ELEMENT_NODE) {
 123  0 attr.setMaxCardinality(Integer.parseInt(WsmlXmlHelper
 124    .getElementText(attrNode)));
 125    }
 126  0 else if (attrNode.getNodeName() == "nonFunctionalProperties"
 127    && attrNode.getNodeType() == Node.ELEMENT_NODE) {
 128  0 NodeNFP.deserialize(attr, attrNode, parser);
 129    }
 130    }
 131    }
 132    }
 133   
 134  0 return concept;
 135    }
 136   
 137  0 static Element serialize(Concept concept, WsmlXmlSerializer serializer) {
 138  0 Element conceptElement = serializer.createElement("concept");
 139  0 conceptElement.setAttribute("name", concept.getIdentifier().toString());
 140   
 141  0 if (!concept.listSuperConcepts().isEmpty()) {
 142  0 Object[] entities = concept.listSuperConcepts().toArray();
 143  0 for (int i = 0; i < entities.length; i++) {
 144  0 Element superConcept = serializer.createElement("superConcept");
 145  0 conceptElement.appendChild(superConcept);
 146  0 superConcept.appendChild(serializer.createTextNode(((Entity) entities[i])
 147    .getIdentifier().toString()));
 148    }
 149    }
 150  0 if (!concept.listNFPValues().isEmpty()) {
 151  0 NodeNFP.serialize(conceptElement, concept, serializer);
 152    }
 153  0 if (!concept.listAttributes().isEmpty()) {
 154  0 Object[] attrList = concept.listAttributes().toArray();
 155  0 for (int i = 0; i < attrList.length; i++) {
 156  0 Element attrElement = serializer.createElement("attribute");
 157  0 conceptElement.appendChild(attrElement);
 158   
 159  0 Attribute attribute = (Attribute) attrList[i];
 160  0 attrElement.setAttribute("name", attribute.getIdentifier().toString());
 161  0 attrElement.setAttribute("type", attribute.isConstraining() ? "constraining"
 162    : "inferring");
 163   
 164  0 if (!attribute.listTypes().isEmpty()) {
 165  0 Element range = serializer.createElement("range");
 166  0 attrElement.appendChild(range);
 167  0 for (Iterator j = attribute.listTypes().iterator(); j.hasNext();) {
 168  0 Object o = j.next();
 169  0 if (o instanceof Concept)
 170  0 range.appendChild(serializer.createTextNode(((Concept) o)
 171    .getIdentifier().toString()));
 172  0 else if (o instanceof WsmlDataType) {
 173  0 range.appendChild(serializer.createTextNode(
 174    ((WsmlDataType) o).getIRI().toString()));
 175    }
 176    else {
 177  0 throw new RuntimeException("Unknown range for attribute!");
 178    }
 179  0 break; // only 1 is allowed in the schema?!
 180    }
 181    }
 182   
 183  0 if (attribute.isSymmetric()) {
 184  0 attrElement.appendChild(serializer.createElement("symmetric"));
 185    }
 186  0 if (attribute.isTransitive()) {
 187  0 attrElement.appendChild(serializer.createElement("transitive"));
 188    }
 189  0 if (attribute.isReflexive()) {
 190  0 attrElement.appendChild(serializer.createElement("reflexive"));
 191    }
 192  0 if (attribute.getInverseOf() != null) {
 193  0 Element inverseOf = serializer.createElement("inverseOf");
 194  0 attrElement.appendChild(inverseOf);
 195  0 inverseOf.setAttribute("type", attribute.getInverseOf().toString());
 196    }
 197  0 if (attribute.getMinCardinality() > 0) {
 198  0 Element minCardinality = serializer.createElement("minCardinality");
 199  0 attrElement.appendChild(minCardinality);
 200  0 minCardinality.appendChild(serializer.createTextNode(String.valueOf(attribute
 201    .getMinCardinality())));
 202    }
 203  0 if (attribute.getMaxCardinality() < Integer.MAX_VALUE) {
 204  0 Element maxCardinality = serializer.createElement("maxCardinality");
 205  0 attrElement.appendChild(maxCardinality);
 206  0 maxCardinality.appendChild(serializer.createTextNode(String.valueOf(attribute
 207    .getMaxCardinality())));
 208    }
 209  0 if (!attribute.listNFPValues().isEmpty()) {
 210  0 NodeNFP.serialize(attrElement, attribute, serializer);
 211    }
 212    }
 213    }
 214   
 215  0 assert conceptElement != null;
 216  0 return conceptElement;
 217    }
 218    }
 219   
 220    /*
 221    * $Log$
 222    * Revision 1.6 2006/07/04 14:30:30 vassil_momtchev
 223    * datatype parsing problem fixed
 224    *
 225    * Revision 1.5 2006/03/29 11:20:51 vassil_momtchev
 226    * mediator support added; some code refactored; minor bugs fixed
 227    *
 228    * Revision 1.4 2006/02/16 09:56:50 vassil_momtchev
 229    * setInverseOf(Attribute) changed to setInverseOf(Identifier)
 230    *
 231    * Revision 1.3 2006/02/10 15:06:23 vassil_momtchev
 232    * addapted to the latest api changes
 233    *
 234    * Revision 1.2 2006/01/17 11:51:53 vassil_momtchev
 235    * range can be WsmlDataType also
 236    *
 237    * Revision 1.1 2005/11/28 14:03:48 vassil_momtchev
 238    * package refactored from com.ontotext.wsmo4j.xmlparser to com.ontotext.wsmo4j.parser.xml
 239    *
 240    * Revision 1.4 2005/09/16 14:02:45 alex_simov
 241    * Identifier.asString() removed, use Object.toString() instead
 242    * (Implementations MUST override toString())
 243    *
 244    * Revision 1.3 2005/09/01 14:56:59 vassil_momtchev
 245    * createAttribute method moved from WsmoFactory to Concept interface
 246    *
 247    * Revision 1.2 2005/08/08 08:24:40 vassil_momtchev
 248    * javadoc added, bugfixes
 249    *
 250    */