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.*;
26  import org.wsmo.common.*;
27  
28  /**
29   * Helper type to serialize/deserialize xml element instance
30   * 
31   * @author not attributable
32   */
33  class NodeInstance {
34      
35      static void serialize(Instance instance, WsmlRdfSerializer serializer) {
36          try {
37              Resource inst = serializer.getFactory().createURI(instance.getIdentifier().toString());
38              
39              if (!instance.listConcepts().isEmpty()) {
40                  Object[] entities = instance.listConcepts().toArray();
41                  for (int i = 0; i < entities.length; i++) {
42                      serializer.getWriter().writeStatement(
43                              inst,
44                              serializer.getFactory().createURI(RDF.TYPE),
45                              serializer.getFactory().createURI(((Entity) entities[i])
46                                      .getIdentifier().toString()));
47                  }
48              } else {
49                  serializer.getWriter().writeStatement(
50                          inst,
51                          serializer.getFactory().createURI(RDF.TYPE),
52                          serializer.getFactory().createURI(RDFS.RESOURCE));
53              }
54              if (!instance.listNFPValues().isEmpty()) {
55                  NodeNFP.serialize(inst,instance, serializer);
56              }
57              if (!instance.listAttributeValues().isEmpty()) {
58                  for (Iterator i = instance.listAttributeValues().keySet().iterator(); i.hasNext();) {
59                      Identifier attrId = (Identifier)i.next();
60                      URI attrURI = serializer.getFactory().createURI(attrId.toString());
61                      
62                      Set datavalues = instance.listAttributeValues(attrId);
63                      for (Iterator j = datavalues.iterator(); j.hasNext();) {
64                          serializer.getWriter().writeStatement(
65                                  inst,
66                                  attrURI,
67                                  NodeValue.serialize(j.next(), serializer));
68                      }
69                  }
70              }
71          } catch (IOException e) {
72              throw new RuntimeException(e);
73          }
74      }
75  }
76  
77  /*
78   * $Log$
79   * Revision 1.1  2006/11/10 15:02:59  ohamano
80   * *** empty log message ***
81   *
82   * Revision 1.1  2006/11/10 10:08:42  ohamano
83   * *** empty log message ***
84   *
85   *
86  */