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.io.File;
21  import java.io.FileReader;
22  
23  import org.omwg.ontology.Ontology;
24  import org.wsmo.common.TopEntity;
25  import org.wsmo.mediator.Mediator;
26  import org.wsmo.service.Goal;
27  import org.wsmo.service.WebService;
28  
29  import com.ontotext.ordi.wsmo4rdf.WsmoConnection;
30  import com.ontotext.ordi.wsmo4rdf.WsmoSource;
31  
32  /**
33   * This class demonstrates how to store WSML file to default WsmoRepository
34   * implementation.
35   */
36  class SaveToWsmoRepository {
37  
38      public static void main(String[] args) {
39          // Check the input arguments supplied by the users
40          if (args.length == 0) {
41              System.out
42                      .println("Specify WSML file to be saved to WsmoRepository!");
43          }
44          File file = new File(args[0]);
45          if (file.exists() == false) {
46              System.out.println(String.format(
47                      "The specified file name %s does not exist!", args[0]));
48          }
49  
50          // Create WSML parser and parse the input file
51          org.wsmo.wsml.Parser wsmlParser = org.wsmo.factory.Factory
52                  .createParser(null);
53          TopEntity[] topEntities = null;
54          try {
55              topEntities = wsmlParser.parse(new FileReader(file));
56          } catch (Exception e) {
57              throw new RuntimeException("Could not parse the input file!", e);
58          }
59  
60          // Create WSMO Repository with the default ORDI implementation
61          WsmoSource wsmoSource = com.ontotext.ordi.Factory.create(
62                  WsmoSource.class, null);
63          WsmoConnection repository = wsmoSource.getConnection();
64  
65          // Save the parsed TopEntity objects to WsmoRepository implementation
66          for (int i = 0; i < topEntities.length; i++) {
67              if (topEntities[i] instanceof Ontology)
68                  repository.saveOntology((Ontology) topEntities[i]);
69              else if (topEntities[i] instanceof WebService)
70                  repository.saveWebService((WebService) topEntities[i]);
71              else if (topEntities[i] instanceof Goal)
72                  repository.saveGoal((Goal) topEntities[i]);
73              else if (topEntities[i] instanceof Mediator)
74                  repository.saveMediator((Mediator) topEntities[i]);
75          }
76  
77          wsmoSource.shutdown();
78  
79          System.out
80                  .println("Saved successfully the input WSML types to WSMO4RDF Data Service!");
81      }
82  }