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.*;
21  import java.util.*;
22  
23  import org.omwg.ontology.*;
24  import org.openrdf.model.*;
25  import org.openrdf.vocabulary.RDFS;
26  import org.wsmo.common.*;
27  
28  /**
29   * Helper type to serialize/deserialize xml element non functional properties
30   * 
31   * @author not attributable
32   */
33  class NodeNFP {
34   
35      static void serialize(Resource subject, Entity entity, WsmlRdfSerializer serializer) {
36          if (entity.listNFPValues().isEmpty()) {
37              return;
38          }
39          Map map = entity.listNFPValues();
40          for (Iterator i = map.entrySet().iterator(); i.hasNext();) {
41              Map.Entry entry = (Map.Entry) i.next();
42              URI comment = serializer.getFactory().createURI(entry.getKey().toString());
43              Set dataValues = (Set) entry.getValue();
44              for (Iterator j = dataValues.iterator(); j.hasNext();) {
45                  try {
46                      if(comment.getURI().equals(WsmlRdfSerializer.DC_RELATION)) {
47                          serializer.getWriter().writeComment(comment + ":" + 
48                                  NodeValue.serialize(j.next(), serializer));
49                      }
50                      else if (comment.getURI().equals(RDFS.LABEL)) {
51                      	serializer.getWriter().writeStatement(
52                      			subject, serializer.getFactory().createURI(RDFS.LABEL), 
53                      			NodeValue.serialize(j.next(), serializer));
54                      }
55                      else {
56                          serializer.getWriter().writeStatement(
57                              subject,
58                              comment,
59                              NodeValue.serialize(j.next(), serializer));
60                      }
61                  } catch(IOException e) {
62                      throw new RuntimeException(e);
63                  }
64              }
65          }
66      }
67      
68      static void serialize(Ontology onto, WsmlRdfSerializer serializer) {
69          if (onto.listNFPValues().isEmpty()) {
70              return;
71          }
72  
73          Map map = onto.listNFPValues();
74          for (Iterator i = map.entrySet().iterator(); i.hasNext();) {
75              Map.Entry entry = (Map.Entry) i.next();
76              String comment = entry.getKey().toString() + ":"; 
77              Set dataValues = (Set) entry.getValue();
78              for (Iterator j = dataValues.iterator(); j.hasNext();) {
79                  comment = comment + " " + NodeValue.serialize(j.next(), serializer);
80              }
81              try {
82                  serializer.getWriter().writeComment(comment);
83              } catch(IOException e) {
84                  throw new RuntimeException(e);
85              }
86          }
87      }
88  }
89  
90  /*
91   * $Log$
92   * Revision 1.2  2006/11/16 14:35:09  ohamano
93   * *** empty log message ***
94   *
95   * Revision 1.1  2006/11/10 15:02:59  ohamano
96   * *** empty log message ***
97   *
98   * Revision 1.1  2006/11/10 10:08:42  ohamano
99   * *** empty log message ***
100  *
101  *
102 */