1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
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
61 WsmoSource wsmoSource = com.ontotext.ordi.Factory.create(
62 WsmoSource.class, null);
63 WsmoConnection repository = wsmoSource.getConnection();
64
65
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 }