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 java.util.*; |
31 |
| |
32 |
| import org.omwg.ontology.*; |
33 |
| import org.w3c.dom.*; |
34 |
| import org.wsmo.common.*; |
35 |
| import org.wsmo.common.exception.*; |
36 |
| import org.wsmo.service.*; |
37 |
| import org.wsmo.wsml.*; |
38 |
| |
39 |
| import com.ontotext.wsmo4j.serializer.xml.*; |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| class NodeCapability { |
47 |
0
| static Capability deserialize(Node xmlNode, WsmlXmlParser parser)
|
48 |
| throws InvalidModelException, ParserException { |
49 |
0
| if (xmlNode == null || parser == null || xmlNode.getNodeName() != "capability") {
|
50 |
0
| throw new IllegalArgumentException();
|
51 |
| } |
52 |
| |
53 |
0
| IRI iriCapability = parser.getFactory().createIRI(
|
54 |
| WsmlXmlHelper.getAttrValue(xmlNode, "name")); |
55 |
0
| Capability capability = parser.getFactory().createCapability(iriCapability);
|
56 |
0
| NodeTopEntity.processTopEntityNode(capability, xmlNode, parser);
|
57 |
| |
58 |
0
| NodeList nodes = xmlNode.getChildNodes();
|
59 |
0
| for (int i = 0; i < nodes.getLength(); i++) {
|
60 |
0
| Node node = nodes.item(i);
|
61 |
| |
62 |
0
| if (node.getNodeName() == "nonFunctionalProperties"
|
63 |
| && node.getNodeType() == Node.ELEMENT_NODE) { |
64 |
0
| NodeNFP.deserialize(capability, node, parser);
|
65 |
| } |
66 |
0
| else if (node.getNodeName() == "sharedVariable" && node.getNodeType() == Node.ELEMENT_NODE) {
|
67 |
0
| NodeList childNodes = node.getChildNodes();
|
68 |
0
| for (int j = 0; j < childNodes.getLength(); j++) {
|
69 |
0
| Node childNode = childNodes.item(j);
|
70 |
0
| if (childNode.getNodeName() == "variable") {
|
71 |
0
| capability.addSharedVariable(
|
72 |
| parser.getLEFactory().createVariable( |
73 |
| WsmlXmlHelper.getElementText(node))); |
74 |
| } |
75 |
| } |
76 |
| } |
77 |
0
| else if (node.getNodeName() == "precondition") {
|
78 |
0
| capability.addPreCondition(NodeLogExp.deserialize(node, parser));
|
79 |
| } |
80 |
0
| else if (node.getNodeName() == "assumption") {
|
81 |
0
| capability.addAssumption(NodeLogExp.deserialize(node, parser));
|
82 |
| } |
83 |
0
| else if (node.getNodeName() == "postcondition") {
|
84 |
0
| capability.addPostCondition(NodeLogExp.deserialize(node, parser));
|
85 |
| } |
86 |
0
| else if (node.getNodeName() == "effect") {
|
87 |
0
| capability.addEffect(NodeLogExp.deserialize(node, parser));
|
88 |
| } |
89 |
| } |
90 |
| |
91 |
0
| return capability;
|
92 |
| } |
93 |
| |
94 |
0
| static Element serialize(Capability capability, WsmlXmlSerializer serializer) {
|
95 |
0
| Element capabilityElement = serializer.createElement("capability");
|
96 |
0
| NodeTopEntity.serializeTopEntity(capabilityElement, capability, serializer);
|
97 |
| |
98 |
0
| if (!capability.listNFPValues().isEmpty()) {
|
99 |
0
| NodeNFP.serialize(capabilityElement, capability, serializer);
|
100 |
| } |
101 |
| |
102 |
0
| if (!capability.listSharedVariables().isEmpty()) {
|
103 |
0
| Element sharedVarElement = serializer.createElement("sharedVariable");
|
104 |
0
| capabilityElement.appendChild(sharedVarElement);
|
105 |
0
| for (Iterator i = capability.listSharedVariables().iterator(); i.hasNext();) {
|
106 |
0
| Variable var = (Variable) i.next();
|
107 |
0
| Element variableElement = serializer.createElement("variable");
|
108 |
0
| variableElement.appendChild(serializer.createTextNode("?" + var.getName()));
|
109 |
| } |
110 |
| } |
111 |
| |
112 |
0
| if (!capability.listPreConditions().isEmpty()) {
|
113 |
0
| for (Iterator i = capability.listPreConditions().iterator(); i.hasNext();) {
|
114 |
0
| Axiom axiom = (Axiom) i.next();
|
115 |
0
| capabilityElement.appendChild(serializer.createElement("precondition").appendChild(
|
116 |
| NodeLogExp.serialize("precondition", axiom, serializer))); |
117 |
| } |
118 |
| } |
119 |
| |
120 |
0
| if (!capability.listAssumptions().isEmpty()) {
|
121 |
0
| for (Iterator i = capability.listPreConditions().iterator(); i.hasNext();) {
|
122 |
0
| Axiom axiom = (Axiom) i.next();
|
123 |
0
| capabilityElement.appendChild(serializer.createElement("assumption").appendChild(
|
124 |
| NodeLogExp.serialize("assumption", axiom, serializer))); |
125 |
| } |
126 |
| } |
127 |
| |
128 |
0
| if (!capability.listPostConditions().isEmpty()) {
|
129 |
0
| for (Iterator i = capability.listPostConditions().iterator(); i.hasNext();) {
|
130 |
0
| Axiom axiom = (Axiom) i.next();
|
131 |
0
| capabilityElement.appendChild(serializer.createElement("postcondition").appendChild(
|
132 |
| NodeLogExp.serialize("postcondition", axiom, serializer))); |
133 |
| } |
134 |
| } |
135 |
| |
136 |
0
| if (!capability.listEffects().isEmpty()) {
|
137 |
0
| for (Iterator i = capability.listEffects().iterator(); i.hasNext();) {
|
138 |
0
| Axiom axiom = (Axiom) i.next();
|
139 |
0
| capabilityElement.appendChild(serializer.createElement("effect").appendChild(
|
140 |
| NodeLogExp.serialize("effect", axiom, serializer))); |
141 |
| } |
142 |
| } |
143 |
| |
144 |
0
| return capabilityElement;
|
145 |
| } |
146 |
| } |
147 |
| |
148 |
| |
149 |
| |
150 |
| |
151 |
| |
152 |
| |
153 |
| |
154 |
| |
155 |
| |
156 |
| |
157 |
| |
158 |
| |
159 |
| |
160 |
| |
161 |
| |
162 |
| |
163 |
| |
164 |
| |
165 |
| |
166 |
| |
167 |
| |
168 |
| |
169 |
| |
170 |
| |
171 |
| |
172 |
| |
173 |
| |
174 |
| |
175 |
| |