View Javadoc

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 org.omwg.ontology.*;
31  import org.w3c.dom.*;
32  import org.wsmo.common.*;
33  import org.wsmo.common.exception.*;
34  import org.wsmo.mediator.*;
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 wsml
42   * 
43   * @author not attributable
44   */
45  public class NodeWsml {
46  
47      static TopEntity deserialzieTopEntity(Node xmlNode, WsmlXmlParser parser)
48              throws InvalidModelException, ParserException {
49          if (xmlNode == null || xmlNode.getNodeName() != "wsml") {
50              throw new IllegalArgumentException();
51          }
52  
53          // TODO: Process wsmlVariant information
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() == "ontology" && node.getNodeType() == Node.ELEMENT_NODE) {
59                  return NodeOntology.deserialize(node, parser);
60              }
61              else if (node.getNodeName().endsWith("Mediator")
62                      && node.getNodeType() == Node.ELEMENT_NODE) {
63                  return NodeMediator.processMediatorNode(node, parser);
64              }
65              else if (node.getNodeName() == "goal" && node.getNodeType() == Node.ELEMENT_NODE) {
66                  return NodeGoal.deserialize(node, parser);
67              }
68              else if (node.getNodeName() == "webService" && node.getNodeType() == Node.ELEMENT_NODE) {
69                  return NodeWebService.deserialize(node, parser);
70              }
71          }
72  
73          return null;
74      }
75  
76      public static Element serializeTopEntity(TopEntity[] entities, WsmlXmlSerializer serializer) {
77          Element wsmlElement = serializer.createElement("wsml");
78          for (int i = 0; i < entities.length; i++) {
79              if (entities[i] instanceof Ontology) {
80                  wsmlElement.appendChild(NodeOntology.serialize((Ontology) entities[i], serializer));
81              }
82              else if (entities[i] instanceof Mediator) {
83                  NodeMediator.serializeMediator(wsmlElement, (Mediator) entities[i], serializer);
84              }
85              else if (entities[i] instanceof Goal) {
86                  wsmlElement.appendChild(NodeGoal.serialize((Goal) entities[i], serializer));
87              }
88              else if (entities[i] instanceof WebService) {
89                  wsmlElement.appendChild(NodeWebService.serialize((WebService) entities[i], serializer));
90              }
91          }
92  
93          return wsmlElement;
94      }
95  }
96  
97  /*
98   * $Log$
99   * Revision 1.2  2007/04/04 08:37:59  alex_simov
100  * The serializer is enabled for all types of topentities
101  *
102  * Revision 1.1  2005/11/28 14:03:48  vassil_momtchev
103  * package refactored from com.ontotext.wsmo4j.xmlparser to com.ontotext.wsmo4j.parser.xml
104  *
105  * Revision 1.4  2005/08/31 09:24:22  vassil_momtchev
106  * add InvalidModelException and ParserException to LogicalExpressionFactory::createLogixExpression methods
107  *
108  * Revision 1.3  2005/08/08 08:24:40  vassil_momtchev
109  * javadoc added, bugfixes
110  *
111 */