| 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 | 0 | 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 | 0 | Grounding grounding = readGrounding(INPUT_FILE); |
| 52 | |
|
| 53 | |
|
| 54 | 0 | System.out.println("* * * * * * * * INITIAL GROUNDING STATE * * * * * * "); |
| 55 | 0 | dumpGrounding(grounding); |
| 56 | |
|
| 57 | |
|
| 58 | 0 | WsmoFactory factory = org.wsmo.factory.Factory.createWsmoFactory(null); |
| 59 | 0 | String targetNamespace = "http://www.w3.org/2002/ws/sawsdl/spec/wsdl/order#"; |
| 60 | |
|
| 61 | 0 | grounding.createElementModelRef( |
| 62 | |
new QName(targetNamespace, "OrderRequest"), |
| 63 | |
factory.createIRI("http://www.example-one.org#elementRef")); |
| 64 | |
|
| 65 | 0 | grounding.createAttributeModelRef( |
| 66 | |
new QName(targetNamespace, "quantity"), |
| 67 | |
factory.createIRI("http://www.example-one.org#attrRef")); |
| 68 | |
|
| 69 | 0 | grounding.createComplexTypeModelRef( |
| 70 | |
new QName(targetNamespace, "item"), |
| 71 | |
factory.createIRI("http://www.example-one.org#complexTypeRef")); |
| 72 | |
|
| 73 | 0 | grounding.createSimpleTypeModelRef( |
| 74 | |
new QName(targetNamespace, "confirmation"), |
| 75 | |
factory.createIRI("http://www.example-one.org#simpleTypeRef")); |
| 76 | |
|
| 77 | 0 | grounding.createOperationModelRef( |
| 78 | |
new QName(targetNamespace, "order"), |
| 79 | |
factory.createIRI("http://www.example-one.org#operationRef")); |
| 80 | |
|
| 81 | 0 | grounding.createFaultModelRef( |
| 82 | |
new QName(targetNamespace, "orderFault"), |
| 83 | |
factory.createIRI("http://www.example-one.org#faultRef")); |
| 84 | |
|
| 85 | 0 | grounding.createInterfaceCategory( |
| 86 | |
new QName(targetNamespace, "Order"), |
| 87 | |
factory.createIRI("http://www.example-one.org#orderRef")); |
| 88 | |
|
| 89 | 0 | grounding.createLiftingSchemaMapping( |
| 90 | |
new QName(targetNamespace, "OrderRequest"), |
| 91 | |
new URI("http://www.example-one.org/Request2RDFOnt.xml")); |
| 92 | |
|
| 93 | |
|
| 94 | 0 | System.out.println("\n* * * * * * * * FINAL GROUNDING STATE * * * * * * "); |
| 95 | 0 | dumpGrounding(grounding); |
| 96 | |
|
| 97 | |
|
| 98 | 0 | System.out.print("Saving to " + OUTPUT_FILE + " ..."); |
| 99 | 0 | writeGrounding(OUTPUT_FILE, grounding); |
| 100 | 0 | System.out.println("Done"); |
| 101 | 0 | } |
| 102 | |
|
| 103 | |
private static Grounding readGrounding(String inputWSDL) throws Exception { |
| 104 | |
|
| 105 | 0 | Reader in = new InputStreamReader( |
| 106 | |
ClassLoader.getSystemResourceAsStream(inputWSDL)); |
| 107 | |
|
| 108 | |
|
| 109 | 0 | GroundingParser parser = Factory.createParser(null); |
| 110 | 0 | return parser.parse(in); |
| 111 | |
} |
| 112 | |
|
| 113 | |
private static void writeGrounding(String outputWSDL, Grounding grounding) throws Exception { |
| 114 | |
|
| 115 | 0 | Writer out = new OutputStreamWriter( |
| 116 | |
new FileOutputStream(outputWSDL)); |
| 117 | |
|
| 118 | |
|
| 119 | 0 | GroundingSerializer serializer = Factory.createSerializer(null); |
| 120 | |
|
| 121 | 0 | serializer.serialize(grounding, out); |
| 122 | 0 | } |
| 123 | |
|
| 124 | |
private static void dumpGrounding(Grounding grounding) throws Exception { |
| 125 | 0 | List<ModelRef> refs = grounding.listModelRefs(); |
| 126 | 0 | System.out.println(refs.size() + " model reference(s) detected:"); |
| 127 | 0 | for(ModelRef ref : refs) { |
| 128 | |
String type; |
| 129 | 0 | if (ref instanceof AttributeModelRef) { |
| 130 | 0 | type = "Attribute"; |
| 131 | |
} |
| 132 | 0 | else if (ref instanceof ElementModelRef) { |
| 133 | 0 | type = "Element"; |
| 134 | |
} |
| 135 | 0 | else if (ref instanceof ComplexTypeModelRef) { |
| 136 | 0 | type = "ComplexType"; |
| 137 | |
} |
| 138 | 0 | else if (ref instanceof SimpleTypeModelRef) { |
| 139 | 0 | type = "SimpleType"; |
| 140 | |
} |
| 141 | 0 | else if (ref instanceof InterfaceCategory) { |
| 142 | 0 | type = "Interface"; |
| 143 | |
} |
| 144 | 0 | else if (ref instanceof OperationModelRef) { |
| 145 | 0 | type = "Operation"; |
| 146 | |
} |
| 147 | 0 | else if (ref instanceof FaultModelRef) { |
| 148 | 0 | type = "Fault"; |
| 149 | |
} |
| 150 | |
else { |
| 151 | 0 | type = "unknown"; |
| 152 | |
} |
| 153 | 0 | System.out.println(" " + type + " [" + ref.getSource().getLocalPart() + " -> " + ref.getTarget() + "]"); |
| 154 | 0 | } |
| 155 | 0 | List<SchemaMapping> mappings = grounding.listSchemaMappings(); |
| 156 | |
|
| 157 | 0 | System.out.println(mappings.size() + " schema mappings detected:"); |
| 158 | 0 | for(SchemaMapping ref : mappings) { |
| 159 | |
String type; |
| 160 | 0 | if (ref instanceof LiftingSchemaMapping) { |
| 161 | 0 | type = " Lifting"; |
| 162 | |
} |
| 163 | |
else { |
| 164 | 0 | type = " Lowering"; |
| 165 | |
} |
| 166 | 0 | System.out.println(type + " schema mapping [" + ref.getSource() + " -> " + ref.getSchema() + "]"); |
| 167 | 0 | } |
| 168 | |
|
| 169 | 0 | } |
| 170 | |
|
| 171 | |
} |