Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 189   Methods: 2
NCLOC: 118   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeRelation.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 relation
 43    *
 44    * @author not attributable
 45    */
 46    class NodeRelation {
 47  0 static Relation deserialize(Node xmlNode, WsmlXmlParser parser) throws InvalidModelException {
 48  0 if (xmlNode == null || parser == null || xmlNode.getNodeName() != "relation") {
 49  0 throw new IllegalArgumentException();
 50    }
 51   
 52  0 IRI relationIri = parser.getFactory()
 53    .createIRI(WsmlXmlHelper.getAttrValue(xmlNode, "name"));
 54  0 Relation relation = parser.getFactory().createRelation(relationIri);
 55   
 56  0 byte arity = Byte.parseByte(WsmlXmlHelper.getAttrValue(xmlNode, "arity"));
 57  0 byte currentArity = 0;
 58   
 59  0 NodeList nodes = xmlNode.getChildNodes();
 60  0 for (int i = 0; i < nodes.getLength(); i++) {
 61  0 Node node = nodes.item(i);
 62  0 if (node.getNodeName() == "superRelation" && node.getNodeType() == Node.ELEMENT_NODE) {
 63  0 IRI superRelIri = parser.getFactory().createIRI(WsmlXmlHelper.getElementText(node));
 64  0 Relation superRel = parser.getFactory().getRelation(superRelIri);
 65  0 relation.addSuperRelation(superRel);
 66  0 superRel.addSubRelation(relation);
 67   
 68    }
 69  0 else if (node.getNodeName() == "parameters" && node.getNodeType() == Node.ELEMENT_NODE) {
 70  0 NodeList parametersNodes = node.getChildNodes();
 71  0 for (int j = 0; j < parametersNodes.getLength(); j++) {
 72  0 Node paramNode = parametersNodes.item(j);
 73  0 if (paramNode.getNodeType() == Node.ELEMENT_NODE
 74    && paramNode.getNodeName() == "parameter") {
 75  0 String paramType = WsmlXmlHelper.getAttrValue(paramNode, "type");
 76  0 Parameter param = relation.createParameter(currentArity++);
 77  0 if (paramType.equals("inferring")) {
 78  0 param.setConstraining(false);
 79    }
 80    else {
 81  0 param.setConstraining(true);
 82    }
 83  0 NodeList rangeNodes = paramNode.getChildNodes();
 84  0 for (int k = 0; k < rangeNodes.getLength(); k++) {
 85  0 Node childNode = rangeNodes.item(k);
 86  0 if (childNode.getNodeName() == "range"
 87    && childNode.getNodeType() == Node.ELEMENT_NODE) {
 88  0 ConstantTransformer cf = ConstantTransformer.getInstance();
 89  0 String type = WsmlXmlHelper.getElementText(childNode);
 90  0 if (cf.isDataType(type)) {
 91  0 param.addType(parser.getDataFactory().createWsmlDataType(type));
 92    }
 93    else {
 94  0 param.addType(parser.getFactory().createConcept(
 95    parser.getFactory().createIRI(type)));
 96    }
 97    }
 98    }
 99    }
 100    }
 101  0 if (currentArity != arity) {
 102  0 throw new IllegalArgumentException("Relation exepected "
 103    + String.valueOf(arity) + "but " + String.valueOf(currentArity)
 104    + " parameters were found!");
 105    }
 106    }
 107  0 else if (node.getNodeName() == "nonFunctionalProperties"
 108    && node.getNodeType() == Node.ELEMENT_NODE) {
 109  0 NodeNFP.deserialize(relation, node, parser);
 110    }
 111    }
 112   
 113  0 return relation;
 114    }
 115   
 116  0 static Element serialize(Relation relation, WsmlXmlSerializer serializer) {
 117  0 Element relationElement = serializer.createElement("relation");
 118  0 relationElement.setAttribute("name", relation.getIdentifier().toString());
 119  0 int arity = 0;
 120   
 121  0 if (!relation.listSuperRelations().isEmpty()) {
 122  0 Object[] entities = relation.listSuperRelations().toArray();
 123  0 for (int i = 0; i < entities.length; i++) {
 124  0 Element superRel = serializer.createElement("superRelation");
 125  0 relationElement.appendChild(superRel);
 126  0 superRel.appendChild(serializer.createTextNode(((Entity) entities[i])
 127    .getIdentifier().toString()));
 128    }
 129    }
 130   
 131  0 if (!relation.listNFPValues().isEmpty()) {
 132  0 NodeNFP.serialize(relationElement, relation, serializer);
 133    }
 134   
 135  0 if (!relation.listParameters().isEmpty()) {
 136  0 Element parametersElement = serializer.createElement("parameters");
 137  0 relationElement.appendChild(parametersElement);
 138   
 139  0 for (Iterator i = relation.listParameters().iterator(); i.hasNext();) {
 140  0 arity++;
 141  0 Parameter param = (Parameter) i.next();
 142  0 Element paramElement = serializer.createElement("parameter");
 143  0 paramElement.setAttribute("type", param.isConstraining() == true ? "constraining"
 144    : "inferring");
 145  0 parametersElement.appendChild(paramElement);
 146   
 147  0 for (Iterator j = param.listTypes().iterator(); j.hasNext();) {
 148  0 Type type = (Type) j.next();
 149  0 Element rangeElement = serializer.createElement("range");
 150  0 paramElement.appendChild(rangeElement);
 151  0 if (type instanceof Concept) {
 152  0 rangeElement.appendChild(serializer.createTextNode(
 153    ((Concept) type).getIdentifier().toString()));
 154    }
 155    else {
 156  0 rangeElement.appendChild(serializer.createTextNode(
 157    ((WsmlDataType) type).getIRI().toString()));
 158    }
 159    }
 160    }
 161    }
 162   
 163  0 relationElement.setAttribute("arity", String.valueOf(arity));
 164  0 return relationElement;
 165    }
 166    }
 167   
 168    /*
 169    * $Log$
 170    * Revision 1.3 2006/07/04 14:30:30 vassil_momtchev
 171    * datatype parsing problem fixed
 172    *
 173    * Revision 1.2 2006/03/29 11:20:51 vassil_momtchev
 174    * mediator support added; some code refactored; minor bugs fixed
 175    *
 176    * Revision 1.1 2005/11/28 14:03:48 vassil_momtchev
 177    * package refactored from com.ontotext.wsmo4j.xmlparser to com.ontotext.wsmo4j.parser.xml
 178    *
 179    * Revision 1.4 2005/09/16 14:02:45 alex_simov
 180    * Identifier.asString() removed, use Object.toString() instead
 181    * (Implementations MUST override toString())
 182    *
 183    * Revision 1.3 2005/08/31 09:19:14 vassil_momtchev
 184    * use Type and Value instead of Object where appropriate bug SF 1276677
 185    *
 186    * Revision 1.2 2005/08/08 08:24:40 vassil_momtchev
 187    * javadoc added, bugfixes
 188    *
 189    */