1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.wsmo.grounding.sawsdl.examples;
20
21
22 import java.io.*;
23 import java.net.URI;
24 import java.util.List;
25
26 import javax.xml.namespace.QName;
27
28 import org.wsmo.factory.WsmoFactory;
29 import org.wsmo.grounding.sawsdl.*;
30 import org.wsmo.grounding.sawsdl.io.*;
31
32
33
34
35
36
37
38
39
40
41
42
43 public class SawsdlExample {
44
45 private static final String INPUT_FILE = "WSDL-input.wsdl";
46 private static final String OUTPUT_FILE = "SAWSDL-output.wsdl";
47
48 public static void main(String[] args) throws Exception {
49
50
51 Grounding grounding = readGrounding(INPUT_FILE);
52
53
54 System.out.println("* * * * * * * * INITIAL GROUNDING STATE * * * * * * ");
55 dumpGrounding(grounding);
56
57
58 WsmoFactory factory = org.wsmo.factory.Factory.createWsmoFactory(null);
59 String targetNamespace = "http://www.w3.org/2002/ws/sawsdl/spec/wsdl/order#";
60
61 grounding.createElementModelRef(
62 new QName(targetNamespace, "OrderRequest"),
63 factory.createIRI("http://www.example-one.org#elementRef"));
64
65 grounding.createAttributeModelRef(
66 new QName(targetNamespace, "quantity"),
67 factory.createIRI("http://www.example-one.org#attrRef"));
68
69 grounding.createComplexTypeModelRef(
70 new QName(targetNamespace, "item"),
71 factory.createIRI("http://www.example-one.org#complexTypeRef"));
72
73 grounding.createSimpleTypeModelRef(
74 new QName(targetNamespace, "confirmation"),
75 factory.createIRI("http://www.example-one.org#simpleTypeRef"));
76
77 grounding.createOperationModelRef(
78 new QName(targetNamespace, "order"),
79 factory.createIRI("http://www.example-one.org#operationRef"));
80
81 grounding.createFaultModelRef(
82 new QName(targetNamespace, "orderFault"),
83 factory.createIRI("http://www.example-one.org#faultRef"));
84
85 grounding.createInterfaceCategory(
86 new QName(targetNamespace, "Order"),
87 factory.createIRI("http://www.example-one.org#orderRef"));
88
89 grounding.createLiftingSchemaMapping(
90 new QName(targetNamespace, "OrderRequest"),
91 new URI("http://www.example-one.org/Request2RDFOnt.xml"));
92
93
94 System.out.println("\n* * * * * * * * FINAL GROUNDING STATE * * * * * * ");
95 dumpGrounding(grounding);
96
97
98 System.out.print("Saving to " + OUTPUT_FILE + " ...");
99 writeGrounding(OUTPUT_FILE, grounding);
100 System.out.println("Done");
101 }
102
103 private static Grounding readGrounding(String inputWSDL) throws Exception {
104
105 Reader in = new InputStreamReader(
106 ClassLoader.getSystemResourceAsStream(inputWSDL));
107
108
109 GroundingParser parser = Factory.createParser(null);
110 return parser.parse(in);
111 }
112
113 private static void writeGrounding(String outputWSDL, Grounding grounding) throws Exception {
114
115 Writer out = new OutputStreamWriter(
116 new FileOutputStream(outputWSDL));
117
118
119 GroundingSerializer serializer = Factory.createSerializer(null);
120
121 serializer.serialize(grounding, out);
122 }
123
124 private static void dumpGrounding(Grounding grounding) throws Exception {
125 List<ModelRef> refs = grounding.listModelRefs();
126 System.out.println(refs.size() + " model reference(s) detected:");
127 for(ModelRef ref : refs) {
128 String type;
129 if (ref instanceof AttributeModelRef) {
130 type = "Attribute";
131 }
132 else if (ref instanceof ElementModelRef) {
133 type = "Element";
134 }
135 else if (ref instanceof ComplexTypeModelRef) {
136 type = "ComplexType";
137 }
138 else if (ref instanceof SimpleTypeModelRef) {
139 type = "SimpleType";
140 }
141 else if (ref instanceof InterfaceCategory) {
142 type = "Interface";
143 }
144 else if (ref instanceof OperationModelRef) {
145 type = "Operation";
146 }
147 else if (ref instanceof FaultModelRef) {
148 type = "Fault";
149 }
150 else {
151 type = "unknown";
152 }
153 System.out.println(" " + type + " [" + ref.getSource().getLocalPart() + " -> " + ref.getTarget() + "]");
154 }
155 List<SchemaMapping> mappings = grounding.listSchemaMappings();
156
157 System.out.println(mappings.size() + " schema mappings detected:");
158 for(SchemaMapping ref : mappings) {
159 String type;
160 if (ref instanceof LiftingSchemaMapping) {
161 type = " Lifting";
162 }
163 else {
164 type = " Lowering";
165 }
166 System.out.println(type + " schema mapping [" + ref.getSource() + " -> " + ref.getSchema() + "]");
167 }
168
169 }
170
171 }