1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.ontotext.wsmo4j.examples;
20
21 import java.io.PrintWriter;
22 import java.util.HashMap;
23
24 import org.omwg.logicalexpression.*;
25 import org.omwg.ontology.*;
26 import org.wsmo.common.*;
27 import org.wsmo.common.exception.*;
28 import org.wsmo.factory.*;
29 import org.wsmo.service.*;
30 import org.wsmo.wsml.*;
31
32
33
34
35
36
37
38
39
40
41 public class CreateWebServiceExample {
42
43 private WsmoFactory factory;
44
45 private LogicalExpressionFactory leFactory;
46
47 private DataFactory dataFactory;
48
49 private static String SERVICE_ID = "http://www.wsmo.org/2004/d3/d3.3/v0.1/20041008/resources/ws.wsml";
50
51 public static void main(String[] args) throws Exception{
52 WebService service = showExample();
53
54 Serializer serializer = Factory.createSerializer(new HashMap<String, Object>(0));
55 serializer.serialize(new TopEntity[] {service}, new PrintWriter(System.out));
56 }
57
58 public static WebService showExample() throws InvalidModelException, ParserException {
59 CreateWebServiceExample example = new CreateWebServiceExample();
60 example.createFactory();
61 return example.createWebservice();
62 }
63
64 private void createFactory() {
65
66 factory = Factory.createWsmoFactory(null);
67 leFactory = Factory.createLogicalExpressionFactory(null);
68 dataFactory = Factory.createDataFactory(null);
69 }
70
71 private WebService createWebservice() throws InvalidModelException, ParserException {
72 IRI serviceIRI = factory.createIRI(SERVICE_ID);
73 WebService service = factory.createWebService(serviceIRI);
74 Namespace targetNamespace = factory.createNamespace("targetnamespace",
75 factory.createIRI("http://www.wsmo.org/2004/d3/d3.3/v0.1/20041008/resources/ws#"));
76
77
78 service.setDefaultNamespace(factory.createNamespace("",
79 factory.createIRI("http://www.wsmo.org/2004/d3/d3.3/v0.1/20041008/resources/ws#")));
80 service.addNamespace(factory.createNamespace("dt",
81 factory.createIRI("http:://www.wsmo.org/ontologies/dateTime#")));
82 service.addNamespace(factory.createNamespace("tc",
83 factory.createIRI("http:://www.wsmo.org/ontologies/trainConnection#")));
84 service.addNamespace(factory.createNamespace("po",
85 factory.createIRI("http://www.wsmo.org/ontologies/purchase#")));
86 service.addNamespace(factory.createNamespace("loc",
87 factory.createIRI("http:://www.wsmo.org/ontologies/location#")));
88 service.addNamespace(factory.createNamespace("ucaswe",
89 factory.createIRI("http://www.wsmo.org/2004/d3/d3.3/v0.1/20041008/resources/")));
90 service.addNamespace(targetNamespace);
91
92
93 service.addNFPValue(factory.createIRI(NFP.DC_TITLE), dataFactory
94 .createWsmlString("OEBB Online Ticket Booking Web Service"));
95 service.addNFPValue(factory.createIRI(NFP.DC_CREATOR), dataFactory
96 .createWsmlString("DERI International"));
97 service.addNFPValue(factory.createIRI(NFP.DC_DESCRIPTION), dataFactory
98 .createWsmlString("Web service for booking online train "
99 + " tickets for Austria and Germany"));
100
101
102 service.addOntology(factory.getOntology(factory
103 .createIRI("http:://www.wsmo.org/ontologies/dateTime")));
104 service.addOntology(factory.getOntology(factory
105 .createIRI("http:://www.wsmo.org/ontologies/trainConnection")));
106 service.addOntology(factory.getOntology(factory
107 .createIRI("http:://www.wsmo.org/ontologies/purchase")));
108 service.addOntology(factory.getOntology(factory
109 .createIRI("http:://www.wsmo.org/ontologies/location")));
110
111
112 Capability capability = factory.createCapability(factory.createIRI(targetNamespace, "capability"));
113 Axiom axiom = null;
114 LogicalExpression logExp = null;
115
116
117 axiom = factory.createAxiom(factory.createIRI(targetNamespace, "axiom1"));
118 logExp = leFactory.createLogicalExpression(
119 "?Buyer memberOf po#buyer and \n"
120 + " ?Trip memberOf tc#trainTrip[ \n"
121 + " tc#start hasValue ?Start, \n"
122 + " tc#end hasValue ?End, \n"
123 + " tc#departure hasValue ?Departure \n"
124 + "] and \n"
125 + "?Start[locatedIn hasValue ?StartLocation] and \n "
126 + "(?StartLocation = austria or ?StartLocation = germany) and \n"
127 + "?End[locatedIn hasValue ?EndLocation] and \n"
128 + "(?EndLocation = austria or ?EndLocation = germany) and \n"
129 + "(?Departure > currentDate()).", service);
130 axiom.addDefinition(logExp);
131 capability.addPreCondition(axiom);
132
133
134 axiom = factory.createAxiom(factory.createIRI(targetNamespace, "axiom2"));
135 logExp = leFactory.createLogicalExpression(
136 "?CreditCard memberOf creditCard[ \n"
137 + " cardholdername hasValue ?someHolder, \n"
138 + " creditcardidentifier hasValue ?someIdentifier, \n"
139 + " expirydate hasValue ?someExpiration, \n"
140 + " globalcreditcardclassificationcode hasValue \"Master Card\" \n"
141 + "] \n"
142 + "and ?someHolder memberOf po#cardHolderName[ \n"
143 + " po#freeformtext hasValue \"Tim Berners-Lee\"\n "
144 + "] \n"
145 + "and ?someIdentifier memberOf creditCardIdentifier[ \n"
146 + " proprietaryreferenceidentifier hasValue \"5535 4464 6686 7747\"\n"
147 + "] \n"
148 + "and ?someExpiration memberOf expiryDate[ \n"
149 + " expmonth hasValue 09, \n"
150 + " expyear hasValue 2007 \n"
151 + "]\n", service);
152 axiom.addDefinition(logExp);
153 capability.addAssumption(axiom);
154
155
156 axiom = factory.createAxiom(factory.createIRI(targetNamespace, "axiom3"));
157 logExp = leFactory.createLogicalExpression("?Trip memberOf trainTrip[ \n"
158 + " start hasValue ?Start, \n"
159 + " end hasValue ?End, \n"
160 + " departure hasValue ?Departure \n"
161 + "] and \n"
162 + "?Start[locatedIn hasValue ?StartLocation] and \n "
163 + "(?StartLocation = austria or ?StartLocation = germany) and \n"
164 + "?End[locatedIn hasValue ?EndLocation] and \n"
165 + "(?EndLocation = austria or ?EndLocation = germany) and \n"
166 + "(?Departure > currentDate()).", service);
167 axiom.addDefinition(logExp);
168 capability.addPostCondition(axiom);
169
170
171 axiom = factory.createAxiom(factory.createIRI(targetNamespace, "axiom4"));
172 logExp = leFactory.createLogicalExpression(
173 "?someTrade memberOf trade[\n"
174 + " items hasValue ?Trip, \n"
175 + " payment hasValue ?acceptedPayment\n"
176 + "]\n"
177 + "and ?acceptedPayment memberOf creditCard .\n", service);
178 axiom.addDefinition(logExp);
179 capability.addEffect(axiom);
180 service.setCapability(capability);
181
182
183 Interface i = factory.createInterface(factory.createIRI(targetNamespace, "interface"));
184 service.addInterface(i);
185
186 return service;
187 }
188 }
189
190
191
192
193
194
195
196
197
198
199
200
201