1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.ontotext.wsmo4j.parser.xml;
19
20
21
22
23
24
25
26
27
28
29
30 import org.omwg.ontology.*;
31 import org.w3c.dom.*;
32 import org.wsmo.common.*;
33 import org.wsmo.common.exception.*;
34 import org.wsmo.wsml.*;
35
36 import com.ontotext.wsmo4j.serializer.xml.*;
37
38
39
40
41
42
43 class NodeOntology {
44
45 static Ontology deserialize(Node xmlNode, WsmlXmlParser parser) throws InvalidModelException,
46 ParserException {
47 if (parser == null || xmlNode == null || xmlNode.getNodeName() != "ontology") {
48 throw new IllegalArgumentException();
49 }
50
51 IRI iri = parser.getFactory().createIRI(WsmlXmlHelper.getAttrValue(xmlNode, "name"));
52 Ontology ontology = parser.getFactory().createOntology(iri);
53 NodeTopEntity.processTopEntityNode(ontology, xmlNode, parser);
54
55 NodeList nodes = xmlNode.getChildNodes();
56 for (int i = 0; i < nodes.getLength(); i++) {
57 Node node = nodes.item(i);
58 if (node.getNodeName() == "nonFunctionalProperties") {
59 NodeNFP.deserialize(ontology, node, parser);
60 }
61 else if (node.getNodeName() == "concept") {
62 ontology.addConcept(NodeConcept.deserialize(node, parser));
63 }
64 else if (node.getNodeName() == "relation") {
65 ontology.addRelation(NodeRelation.deserialize(node, parser));
66 }
67 else if (node.getNodeName() == "instance") {
68 ontology.addInstance(NodeInstance.deserialize(node, parser));
69 }
70 else if (node.getNodeName() == "relationInstance") {
71 ontology.addRelationInstance(NodeRelationInstance.deserialize(node, parser));
72 }
73 else if (node.getNodeName() == "axiom") {
74 ontology.addAxiom(NodeLogExp.deserialize(node, parser));
75 }
76 }
77
78 return ontology;
79 }
80
81 static Element serialize(Ontology ontology, WsmlXmlSerializer serializer) {
82 Element ontologyElement = serializer.createElement("ontology");
83 ontologyElement.setAttribute("name", ontology.getIdentifier().toString());
84 NodeTopEntity.serializeTopEntity(ontologyElement, ontology, serializer);
85
86 if (!ontology.listNFPValues().isEmpty()) {
87 NodeNFP.serialize(ontologyElement, ontology, serializer);
88 }
89
90 if (!ontology.listConcepts().isEmpty()) {
91 Object[] concepts = ontology.listConcepts().toArray();
92 for (int i = 0; i < concepts.length; i++) {
93 ontologyElement.appendChild(NodeConcept
94 .serialize((Concept) concepts[i], serializer));
95 }
96 }
97
98 if (!ontology.listInstances().isEmpty()) {
99 Object[] instances = ontology.listInstances().toArray();
100 for (int i = 0; i < instances.length; i++) {
101 ontologyElement.appendChild(NodeInstance.serialize((Instance) instances[i],
102 serializer));
103 }
104 }
105
106 if (!ontology.listRelations().isEmpty()) {
107 Object[] relations = ontology.listRelations().toArray();
108 for (int i = 0; i < relations.length; i++)
109 ontologyElement.appendChild(NodeRelation.serialize((Relation) relations[i],
110 serializer));
111 }
112
113 if (!ontology.listRelationInstances().isEmpty()) {
114 Object[] relationInstances = ontology.listRelationInstances().toArray();
115 for (int i = 0; i < relationInstances.length; i++) {
116 ontologyElement.appendChild(NodeRelationInstance.serialize(
117 (RelationInstance) relationInstances[i], serializer));
118 }
119 }
120
121 if (!ontology.listAxioms().isEmpty()) {
122 Object[] axioms = ontology.listAxioms().toArray();
123 for (int i = 0; i < axioms.length; i++) {
124 ontologyElement.appendChild(
125 NodeLogExp.serialize("axiom", (Axiom) axioms[i], serializer));
126 }
127 }
128
129 return ontologyElement;
130 }
131 }
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151