View Javadoc
1   /*
2    ORDI - Ontology Repository and Data Integration
3   
4    Copyright (c) 2004-2007, 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 examples;
19  
20  import java.util.ArrayList;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import org.wsmo.common.Entity;
25  import org.wsmo.common.IRI;
26  import org.wsmo.common.TopEntity;
27  import org.wsmo.factory.Factory;
28  import org.wsmo.wsml.Serializer;
29  
30  import com.ontotext.ordi.wsmo4rdf.WsmoConnection;
31  import com.ontotext.ordi.wsmo4rdf.WsmoSource;
32  
33  /**
34   * This class provides a sample how to instantiate and retrieve WSMO entities
35   * from a default WsmoRepository implementation.
36   */
37  class LoadFromWsmoRepository {
38      public static void main(String[] args) {
39  
40          // Create WSMO Repository with the default ORDI implementation
41          WsmoSource wsmoSource = com.ontotext.ordi.Factory.create(
42                  WsmoSource.class, null);
43          WsmoConnection repository = wsmoSource.getConnection();
44  
45          // Retrieve all IRIs of Goal, Ontology, WebService and Mediator
46          List<IRI> allIRIs = new ArrayList<IRI>();
47          allIRIs.addAll(repository.listGoals());
48          allIRIs.addAll(repository.listMediators());
49          allIRIs.addAll(repository.listOntologies());
50          allIRIs.addAll(repository.listWebServices());
51  
52          // Retrieve all Goal, Ontology, WebService and Mediator entities
53          Iterator<IRI> iterator = allIRIs.iterator();
54          List<Entity> allTopEntities = new ArrayList<Entity>();
55          while (iterator.hasNext()) {
56              IRI iri = iterator.next();
57              Iterator<Entity> eIterator = repository.load(iri).iterator();
58              while (eIterator.hasNext()) {
59                  allTopEntities.add(eIterator.next());
60              }
61          }
62  
63          // Print all retrieved Goal, Ontology, WebService and Mediator entities
64          Serializer serializer = Factory.createSerializer(null);
65          Iterator<Entity> eIterator = allTopEntities.iterator();
66          while (eIterator.hasNext()) {
67              Entity entity = eIterator.next();
68              if (entity instanceof TopEntity) {
69                  StringBuffer buffer = new StringBuffer();
70                  serializer.serialize(new TopEntity[] { (TopEntity) entity },
71                          buffer);
72                  System.out.println("Retrieved TopEntity:");
73                  System.out.println(buffer);
74                  System.out.println();
75              }
76          }
77          
78          wsmoSource.shutdown();
79      }
80  }