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 import java.io.FileWriter;
23 import java.io.IOException;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.wsmo.common.TopEntity;
28 import org.wsmo.factory.Factory;
29 import org.wsmo.wsml.Parser;
30 import org.wsmo.wsml.Serializer;
31
32 import com.ontotext.ordi.wsmo4rdf.WSMLTripleParser;
33
34 /**
35 * This class provides a sample how to parse WSMLRDF file and generate a WSML
36 * output.
37 */
38 class ParseWSMLRDF {
39
40 public static void main(String[] args) {
41
42 if (args.length == 0) {
43 System.out
44 .println("Specify WSMLRDF file to be transformed to WSML!");
45 System.exit(1);
46 }
47 File file = new File(args[0]);
48 if (file.exists() == false) {
49 System.out.println(String.format(
50 "The specified file name %s does not exist!", args[0]));
51 System.exit(1);
52 }
53
54
55 Map<String, Object> createParams = new HashMap<String, Object>();
56 createParams.put(org.wsmo.factory.Factory.PROVIDER_CLASS,
57 WSMLTripleParser.class.getName());
58 Parser wsmlrdfParser = Factory.createParser(createParams);
59
60
61 TopEntity[] topEntities = null;
62 try {
63 topEntities = wsmlrdfParser.parse(new FileReader(file));
64 } catch (Exception e) {
65 throw new RuntimeException(String.format(
66 "Could not processes the input file %s!", file
67 .getAbsolutePath()), e);
68 }
69
70
71 File outputFile = null;
72 FileWriter writer = null;
73 try {
74 outputFile = new File(file.getAbsolutePath() + ".wsml");
75 writer = new FileWriter(outputFile);
76 } catch (IOException e) {
77 throw new RuntimeException("Could not create the output file!", e);
78 }
79
80
81 createParams = new HashMap<String, Object>();
82 createParams.put(org.wsmo.factory.Factory.PROVIDER_CLASS,
83 "org.deri.wsmo4j.io.serializer.wsml.SerializerImpl");
84 Serializer serializer = Factory.createSerializer(createParams);
85 try {
86 serializer.serialize(topEntities, writer);
87 } catch (IOException e) {
88 throw new RuntimeException("Could not serialize to WSML!", e);
89 }
90 System.out.println(String.format("Output has beed saved in %s!",
91 outputFile.getAbsolutePath()));
92 }
93 }