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.w3c.dom.*;
33 import org.wsmo.common.*;
34 import org.wsmo.common.exception.*;
35 import org.wsmo.service.*;
36 import org.wsmo.wsml.*;
37
38 import com.ontotext.wsmo4j.serializer.xml.*;
39
40 /**
41 * Helper type to serialize/deserialize xml element goal
42 *
43 * @author not attributable
44 */
45 class NodeGoal {
46 static Goal deserialize(Node xmlNode, WsmlXmlParser parser) throws InvalidModelException,
47 ParserException {
48 if (xmlNode == null || parser == null || xmlNode.getNodeName() != "goal"
49 || xmlNode.getNodeType() != Element.ELEMENT_NODE) {
50 throw new IllegalArgumentException();
51 }
52
53 IRI goalIri = parser.getFactory().createIRI(WsmlXmlHelper.getAttrValue(xmlNode, "name"));
54 Goal goal = parser.getFactory().createGoal(goalIri);
55 NodeTopEntity.processTopEntityNode(goal, xmlNode, parser);
56 NodeList nodes = xmlNode.getChildNodes();
57
58 for (int i = 0; i < nodes.getLength(); i++) {
59 Node node = nodes.item(i);
60 if (node.getNodeName() == "nonFunctionalProperties") {
61 NodeNFP.deserialize(goal, node, parser);
62 }
63 else if (node.getNodeName() == "capability") {
64 goal.setCapability(NodeCapability.deserialize(node, parser));
65 }
66 else if (node.getNodeName() == "interface") {
67 goal.addInterface(NodeInterface.deserialize(node, parser));
68 }
69 }
70
71 return goal;
72 }
73
74 static Element serialize(Goal goal, WsmlXmlSerializer serializer) {
75 Element goalElement = serializer.createElement("goal");
76 goalElement.setAttribute("name", goal.getIdentifier().toString());
77 NodeTopEntity.serializeTopEntity(goalElement, goal, serializer);
78
79 if (!goal.listNFPValues().isEmpty()) {
80 NodeNFP.serialize(goalElement, goal, serializer);
81 }
82
83 goalElement.appendChild(NodeCapability.serialize(goal.getCapability(), serializer));
84
85 if (!goal.listInterfaces().isEmpty()) {
86 for (Iterator i = goal.listInterfaces().iterator(); i.hasNext();) {
87 Interface intrface = (Interface) i.next();
88 goalElement.appendChild(NodeInterface.serialize(intrface, serializer));
89 }
90 }
91
92 return goalElement;
93 }
94 }
95
96 /*
97 * $Log$
98 * Revision 1.2 2006/03/29 11:20:51 vassil_momtchev
99 * mediator support added; some code refactored; minor bugs fixed
100 *
101 * Revision 1.1 2005/11/28 14:03:48 vassil_momtchev
102 * package refactored from com.ontotext.wsmo4j.xmlparser to com.ontotext.wsmo4j.parser.xml
103 *
104 * Revision 1.5 2005/09/16 14:02:45 alex_simov
105 * Identifier.asString() removed, use Object.toString() instead
106 * (Implementations MUST override toString())
107 *
108 * Revision 1.4 2005/08/31 09:24:22 vassil_momtchev
109 * add InvalidModelException and ParserException to LogicalExpressionFactory::createLogixExpression methods
110 *
111 * Revision 1.3 2005/08/08 08:24:40 vassil_momtchev
112 * javadoc added, bugfixes
113 *
114 */