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  import org.w3c.dom.*;
21  import org.wsmo.common.*;
22  import org.wsmo.common.Entity;
23  import org.wsmo.common.exception.*;
24  
25  import com.ontotext.wsmo4j.serializer.xml.*;
26  
27  /**
28   * <p>Title: WSMO4J</p>
29   * <p>Description: WSMO API and a Reference Implementation</p>
30   * <p>Copyright:  Copyright (c) 2004-2005</p>
31   * <p>Company: OntoText Lab. / SIRMA </p>
32   * @author not attributable
33   * @version 1.0
34   *
35   */
36  public class NodeTopEntity {
37  
38      static void processTopEntityNode(TopEntity te, Node xmlNode, WsmlXmlParser parser)
39              throws InvalidModelException {
40          if (te == null || xmlNode == null || parser == null
41                  || xmlNode.getNodeType() != Element.ELEMENT_NODE) {
42              throw new IllegalArgumentException();
43          }
44  
45          NodeList nodes = xmlNode.getChildNodes();
46          for (int i = 0; i < nodes.getLength(); i++) {
47              Node node = nodes.item(i);
48              if (node.getNodeName() == "importsOntology") {
49                  te.addOntology(parser.getFactory().createOntology(
50                          parser.getFactory().createIRI(WsmlXmlHelper.getElementText(node))));
51              }
52              else if (node.getNodeName() == "usesMediator") {
53                  IRI iri = parser.getFactory().createIRI(WsmlXmlHelper.getElementText(node));
54                  te.addMediator(iri);
55              }
56          }
57      }
58  
59      static void serializeTopEntity(Element parent, TopEntity te, WsmlXmlSerializer serializer) {
60          if (!te.listOntologies().isEmpty()) {
61              Object[] entities = te.listOntologies().toArray();
62              for (int i = 0; i < entities.length; i++) {
63                  Element importOnto = serializer.createElement("importsOntology");
64                  parent.appendChild(importOnto);
65                  importOnto.appendChild(serializer.createTextNode(((Entity) entities[i])
66                          .getIdentifier().toString()));
67              }
68          }
69  
70          if (!te.listMediators().isEmpty()) {
71              Object[] entities = te.listMediators().toArray();
72              for (int i = 0; i < entities.length; i++) {
73                  Element useMediator = serializer.createElement("usesMediator");
74                  parent.appendChild(useMediator);
75                  useMediator.appendChild(serializer.createTextNode(((Identifier) entities[i])
76                          .toString()));
77              }
78          }
79      }
80  }
81  
82  /*
83   * $Log$
84   * Revision 1.2  2006/04/05 13:25:26  vassil_momtchev
85   * usesMediator now refer mediators by  IRI instead of handle to object
86   *
87   * Revision 1.1  2006/03/29 11:20:51  vassil_momtchev
88   * mediator support added; some code refactored; minor bugs fixed
89   *
90  */