View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3   
4    Copyright (c) 2006, University of Innsbruck, Austria
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 org.deri.wsmo4j.io.serializer.rdf;
19  
20  import java.io.IOException;
21  
22  import org.deri.wsmo4j.io.parser.rdf.RDFExprParser;
23  import org.omwg.ontology.*;
24  import org.openrdf.vocabulary.RDF;
25  import org.openrdf.vocabulary.RDFS;
26  
27  /**
28   * Helper type to serialize/deserialize xml element ontology
29   * 
30   * @author not attributable
31   */
32  class NodeOntology {
33  
34      static void serialize(Ontology ontology, WsmlRdfSerializer serializer) {
35      	// keep in mind the ontology id (for better roundtripping)
36      	try {
37  			serializer.getWriter().writeStatement(
38  			        serializer.getFactory().createURI(ontology.getIdentifier().toString()),
39  			        serializer.getFactory().createURI(RDFExprParser.WSML_ONTOLOGY_ID),
40  			        serializer.getFactory().createURI(ontology.getIdentifier().toString()));
41  		} catch (IOException e) {
42  			throw new RuntimeException();
43  		}
44          if (!ontology.listNFPValues().isEmpty()) {
45              NodeNFP.serialize(ontology, serializer);
46          }
47  
48          if (!ontology.listConcepts().isEmpty()) {
49              Object[] concepts = ontology.listConcepts().toArray();
50              for (int i = 0; i < concepts.length; i++) {
51                  NodeConcept.serialize((Concept) concepts[i], serializer);
52              }
53          }
54  
55          if (!ontology.listInstances().isEmpty()) {
56              Object[] instances = ontology.listInstances().toArray();
57              for (int i = 0; i < instances.length; i++) {
58                  NodeInstance.serialize((Instance) instances[i],serializer);
59              }
60          }
61  
62          if (!ontology.listRelations().isEmpty()) {
63              Object[] relations = ontology.listRelations().toArray();
64              for (int i = 0; i < relations.length; i++)
65                  NodeRelation.serialize((Relation) relations[i],serializer);
66          }
67  
68          if (!ontology.listRelationInstances().isEmpty()) {
69              Object[] relationInstances = ontology.listRelationInstances().toArray();
70              for (int i = 0; i < relationInstances.length; i++) {
71                  NodeRelationInstance.serialize(
72                          (RelationInstance) relationInstances[i], serializer);
73              }
74          }
75          
76          if (!ontology.listAxioms().isEmpty()) {
77              Object[] axioms = ontology.listAxioms().toArray();
78              for (int i = 0; i < axioms.length; i++) {
79                  NodeLogExp.serialize((Axiom) axioms[i], serializer);
80              }
81          }
82          
83      }
84  }
85  
86  /*
87   * $Log$
88   * Revision 1.2  2006/11/16 14:35:09  ohamano
89   * *** empty log message ***
90   *
91   * Revision 1.1  2006/11/10 15:02:59  ohamano
92   * *** empty log message ***
93   *
94   * Revision 1.1  2006/11/10 10:08:42  ohamano
95   * *** empty log message ***
96   *
97   *
98  */