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 non functional properties
42 *
43 * @author not attributable
44 */
45 class NodeNFP {
46 static void deserialize(Entity entity, Node xmlNode, WsmlXmlParser parser)
47 throws InvalidModelException {
48 if (entity == null || xmlNode == null || parser == null
49 || xmlNode.getNodeName() != "nonFunctionalProperties") {
50 throw new IllegalArgumentException();
51 }
52
53 NodeList nodes = xmlNode.getChildNodes();
54 for (int i = 0; i < nodes.getLength(); i++) {
55 Node node = nodes.item(i);
56 if (node.getNodeName() == "attributeValue") {
57 IRI nfpIri = parser.getFactory()
58 .createIRI(WsmlXmlHelper.getAttrValue(node, "name"));
59
60 Node nodeValue = WsmlXmlHelper.getFirstChildElement(node);
61 Object value = NodeValue.deserialize(nodeValue, parser);
62
63 if (value instanceof DataValue) {
64 entity.addNFPValue(nfpIri, (DataValue) value);
65 }
66 else if (value instanceof Identifier) {
67 entity.addNFPValue(nfpIri, (Identifier) value);
68 }
69 else if (value instanceof Instance) {
70 entity.addNFPValue(nfpIri, ((Instance) value).getIdentifier());
71 }
72 }
73 }
74 }
75
76 static void serialize(Element parent, Entity entity, WsmlXmlSerializer serializer) {
77 if (entity.listNFPValues().isEmpty()) {
78 return;
79 }
80
81 Element nfpElement = serializer.createElement("nonFunctionalProperties");
82 parent.appendChild(nfpElement);
83 Map map = entity.listNFPValues();
84 for (Iterator i = map.entrySet().iterator(); i.hasNext();) {
85 Map.Entry entry = (Map.Entry) i.next();
86 Element attr = serializer.createElement("attributeValue");
87 nfpElement.appendChild(attr);
88 attr.setAttribute("name", entry.getKey().toString());
89
90 Set dataValues = (Set) entry.getValue();
91 for (Iterator j = dataValues.iterator(); j.hasNext();) {
92 attr.appendChild(NodeValue.serialize(j.next(), serializer));
93 }
94 }
95 }
96 }
97
98 /*
99 * $Log$
100 * Revision 1.2 2006/07/04 14:31:32 vassil_momtchev
101 * no longer instances used as nfp values; identifier used instead
102 *
103 * Revision 1.1 2005/11/28 14:03:48 vassil_momtchev
104 * package refactored from com.ontotext.wsmo4j.xmlparser to com.ontotext.wsmo4j.parser.xml
105 *
106 * Revision 1.3 2005/09/16 14:02:45 alex_simov
107 * Identifier.asString() removed, use Object.toString() instead
108 * (Implementations MUST override toString())
109 *
110 * Revision 1.2 2005/08/08 08:24:40 vassil_momtchev
111 * javadoc added, bugfixes
112 *
113 */