1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.deri.wsmo4j.orchestration; |
20 | |
|
21 | |
import java.util.HashMap; |
22 | |
import java.util.Map; |
23 | |
import java.util.Set; |
24 | |
|
25 | |
import org.deri.wsmo4j.choreography.signature.ControlledRI; |
26 | |
import org.deri.wsmo4j.choreography.signature.InRI; |
27 | |
import org.deri.wsmo4j.choreography.signature.OutRI; |
28 | |
import org.deri.wsmo4j.choreography.signature.SharedRI; |
29 | |
import org.deri.wsmo4j.choreography.signature.StateSignatureRI; |
30 | |
import org.deri.wsmo4j.choreography.signature.StaticRI; |
31 | |
import org.deri.wsmo4j.choreography.signature.WSDLGroundingRI; |
32 | |
import org.deri.wsmo4j.orchestration.rule.ChooseRI; |
33 | |
import org.deri.wsmo4j.orchestration.rule.ForAllRI; |
34 | |
import org.deri.wsmo4j.orchestration.rule.IfThenRI; |
35 | |
import org.deri.wsmo4j.orchestration.rule.OrchestrationAchieveGoalRI; |
36 | |
import org.deri.wsmo4j.orchestration.rule.OrchestrationApplyMediationRI; |
37 | |
import org.deri.wsmo4j.orchestration.rule.OrchestrationInvokeServiceRI; |
38 | |
import org.deri.wsmo4j.orchestration.rule.ReceiveRI; |
39 | |
import org.deri.wsmo4j.orchestration.rule.RulesRI; |
40 | |
import org.deri.wsmo4j.orchestration.rule.SendRI; |
41 | |
import org.deri.wsmo4j.rule.AddRI; |
42 | |
import org.deri.wsmo4j.rule.ConditionRI; |
43 | |
import org.deri.wsmo4j.rule.DeleteRI; |
44 | |
import org.deri.wsmo4j.rule.MoleculeFactRI; |
45 | |
import org.deri.wsmo4j.rule.RelationFactRI; |
46 | |
import org.deri.wsmo4j.rule.UpdateRI; |
47 | |
import org.omwg.logicalexpression.Atom; |
48 | |
import org.omwg.logicalexpression.AttributeValueMolecule; |
49 | |
import org.omwg.logicalexpression.LogicalExpression; |
50 | |
import org.omwg.logicalexpression.MembershipMolecule; |
51 | |
import org.omwg.ontology.Concept; |
52 | |
import org.omwg.ontology.Relation; |
53 | |
import org.omwg.ontology.Variable; |
54 | |
import org.wsmo.common.Entity; |
55 | |
import org.wsmo.common.IRI; |
56 | |
import org.wsmo.common.Identifier; |
57 | |
import org.wsmo.common.exception.InvalidModelException; |
58 | |
import org.wsmo.factory.OrchestrationFactory; |
59 | |
import org.wsmo.service.Goal; |
60 | |
import org.wsmo.service.WebService; |
61 | |
import org.wsmo.service.orchestration.Orchestration; |
62 | |
import org.wsmo.service.orchestration.PpMediator; |
63 | |
import org.wsmo.service.orchestration.rule.OrchestrationAchieveGoal; |
64 | |
import org.wsmo.service.orchestration.rule.OrchestrationApplyMediation; |
65 | |
import org.wsmo.service.orchestration.rule.OrchestrationChoose; |
66 | |
import org.wsmo.service.orchestration.rule.OrchestrationForAll; |
67 | |
import org.wsmo.service.orchestration.rule.OrchestrationIfThen; |
68 | |
import org.wsmo.service.orchestration.rule.OrchestrationInvokeService; |
69 | |
import org.wsmo.service.orchestration.rule.OrchestrationRules; |
70 | |
import org.wsmo.service.orchestration.rule.Receive; |
71 | |
import org.wsmo.service.orchestration.rule.Send; |
72 | |
import org.wsmo.service.rule.Add; |
73 | |
import org.wsmo.service.rule.CompoundFact; |
74 | |
import org.wsmo.service.rule.Condition; |
75 | |
import org.wsmo.service.rule.Delete; |
76 | |
import org.wsmo.service.rule.MoleculeFact; |
77 | |
import org.wsmo.service.rule.RelationFact; |
78 | |
import org.wsmo.service.rule.Rule; |
79 | |
import org.wsmo.service.rule.Update; |
80 | |
import org.wsmo.service.signature.Controlled; |
81 | |
import org.wsmo.service.signature.Grounding; |
82 | |
import org.wsmo.service.signature.In; |
83 | |
import org.wsmo.service.signature.Out; |
84 | |
import org.wsmo.service.signature.Shared; |
85 | |
import org.wsmo.service.signature.StateSignature; |
86 | |
import org.wsmo.service.signature.Static; |
87 | |
import org.wsmo.service.signature.WSDLGrounding; |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | 0 | public class OrchestrationFactoryRI extends OrchestrationFactory |
101 | |
{ |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public OrchestrationFactoryRI() { |
107 | 0 | super(); |
108 | 0 | synchronized(OrchestrationFactoryRI.class) { |
109 | 0 | if (registry == null) |
110 | 0 | registry = new HashMap<Identifier, Entity>(); |
111 | 0 | } |
112 | 0 | } |
113 | |
|
114 | |
private static Map<Identifier, Entity> registry; |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
@Override |
122 | |
protected Containers createContainers() |
123 | |
{ |
124 | 0 | return new ContainersRI(); |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
@Override |
133 | |
protected TransitionRules createTransitionRules() |
134 | |
{ |
135 | 0 | return new TransitionRulesRI(); |
136 | |
} |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
@Override |
144 | |
protected UpdateRules createUpdateRules() |
145 | |
{ |
146 | 0 | return new UpdateRulesRI(); |
147 | |
} |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
@Override |
155 | |
protected Facts createFacts() |
156 | |
{ |
157 | 0 | return new FactsRI(); |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
@Override |
166 | |
protected Modes createModes() |
167 | |
{ |
168 | 0 | return new ModesRI(); |
169 | |
} |
170 | |
|
171 | 0 | private class ContainersRI implements Containers |
172 | |
{ |
173 | |
|
174 | |
public Orchestration createOrchestration(Identifier id) |
175 | |
{ |
176 | 0 | return new OrchestrationRI(id); |
177 | |
} |
178 | |
|
179 | |
public Orchestration createOrchestration(Identifier id, |
180 | |
StateSignature signature, OrchestrationRules rules) |
181 | |
{ |
182 | 0 | return new OrchestrationRI(id, signature, rules); |
183 | |
} |
184 | |
|
185 | |
public StateSignature createStateSignature(Identifier id) |
186 | |
{ |
187 | 0 | return new StateSignatureRI(id); |
188 | |
} |
189 | |
|
190 | |
public StateSignature createStateSignature(Identifier id, Set<In> inMode, |
191 | |
Set<Out> outMode, Set<Shared> sharedMode, Set<Static> staticMode, |
192 | |
Set<Controlled> controlledMode) |
193 | |
{ |
194 | 0 | return new StateSignatureRI(id, inMode, outMode, sharedMode, staticMode, |
195 | |
controlledMode); |
196 | |
} |
197 | |
|
198 | |
public OrchestrationRules createRules(Identifier id) |
199 | |
{ |
200 | 0 | return new RulesRI(id); |
201 | |
} |
202 | |
|
203 | |
public OrchestrationRules createRules(Identifier id, Set<Rule> rules) |
204 | |
{ |
205 | 0 | return new RulesRI(id, rules); |
206 | |
} |
207 | |
|
208 | |
} |
209 | |
|
210 | 0 | private class TransitionRulesRI implements TransitionRules |
211 | |
{ |
212 | |
|
213 | |
public Condition createConditionFromLogicalExpression(LogicalExpression e) |
214 | |
throws InvalidModelException |
215 | |
{ |
216 | 0 | return new ConditionRI(e); |
217 | |
} |
218 | |
|
219 | |
public OrchestrationIfThen createIfThen(Condition expression, Rule rule) |
220 | |
{ |
221 | 0 | return new IfThenRI(expression, rule); |
222 | |
} |
223 | |
|
224 | |
public OrchestrationIfThen createIfThen(Condition expression, Set<Rule> rules) |
225 | |
{ |
226 | 0 | return new IfThenRI(expression, rules); |
227 | |
} |
228 | |
|
229 | |
public OrchestrationForAll createForAll(Variable variable, Condition condition, Rule rule) |
230 | |
{ |
231 | 0 | return new ForAllRI(variable, condition, rule); |
232 | |
} |
233 | |
|
234 | |
public OrchestrationForAll createForAll(Set<Variable> variables, Condition condition, |
235 | |
Rule rule) |
236 | |
{ |
237 | 0 | return new ForAllRI(variables, condition, rule); |
238 | |
} |
239 | |
|
240 | |
public OrchestrationForAll createForAll(Variable variable, Condition condition, |
241 | |
Set<Rule> rules) |
242 | |
{ |
243 | 0 | return new ForAllRI(variable, condition, rules); |
244 | |
} |
245 | |
|
246 | |
public OrchestrationForAll createForAll(Set<Variable> variables, Condition condition, |
247 | |
Set<Rule> rules) |
248 | |
{ |
249 | 0 | return new ForAllRI(variables, condition, rules); |
250 | |
} |
251 | |
|
252 | |
public OrchestrationChoose createChoose(Variable variable, Condition condition, Rule rule) |
253 | |
{ |
254 | 0 | return new ChooseRI(variable, condition, rule); |
255 | |
} |
256 | |
|
257 | |
public OrchestrationChoose createChoose(Set<Variable> variables, Condition condition, |
258 | |
Rule rule) |
259 | |
{ |
260 | 0 | return new ChooseRI(variables, condition, rule); |
261 | |
} |
262 | |
|
263 | |
public OrchestrationChoose createChoose(Variable variable, Condition condition, |
264 | |
Set<Rule> rules) |
265 | |
{ |
266 | 0 | return new ChooseRI(variable, condition, rules); |
267 | |
} |
268 | |
|
269 | |
public OrchestrationChoose createChoose(Set<Variable> variables, Condition condition, |
270 | |
Set<Rule> rules) |
271 | |
{ |
272 | 0 | return new ChooseRI(variables, condition, rules); |
273 | |
} |
274 | |
|
275 | |
} |
276 | |
|
277 | 0 | private class UpdateRulesRI implements UpdateRules |
278 | |
{ |
279 | |
|
280 | |
public Add createAdd(CompoundFact fact) |
281 | |
{ |
282 | 0 | return new AddRI(fact); |
283 | |
} |
284 | |
|
285 | |
public Delete createDelete(CompoundFact fact) |
286 | |
{ |
287 | 0 | return new DeleteRI(fact); |
288 | |
} |
289 | |
|
290 | |
public Update createUpdate(CompoundFact newFact) |
291 | |
{ |
292 | 0 | return new UpdateRI(newFact); |
293 | |
} |
294 | |
|
295 | |
public Update createUpdate(CompoundFact newFact, CompoundFact oldFact) |
296 | |
throws InvalidModelException |
297 | |
{ |
298 | 0 | return new UpdateRI(newFact, oldFact); |
299 | |
} |
300 | |
|
301 | |
public OrchestrationAchieveGoal createOrchestrationAchieveGoal(IRI perform, Goal goal) { |
302 | 0 | return new OrchestrationAchieveGoalRI(perform, goal); |
303 | |
} |
304 | |
|
305 | |
public OrchestrationApplyMediation createOrchestrationApplyMediation(IRI perform, PpMediator mediator) { |
306 | 0 | return new OrchestrationApplyMediationRI(perform, mediator); |
307 | |
} |
308 | |
|
309 | |
public OrchestrationInvokeService createOrchestrationInvokeService(IRI perform, WebService service) { |
310 | 0 | return new OrchestrationInvokeServiceRI(perform, service); |
311 | |
} |
312 | |
|
313 | |
public synchronized PpMediator createPpMediator(Identifier id) { |
314 | 0 | Object o = registry.get(id); |
315 | 0 | if (o instanceof PpMediator) { |
316 | 0 | return (PpMediator) o; |
317 | |
} |
318 | 0 | PpMediator mediator = new PpMediatorRi(id); |
319 | 0 | registry.put(id, mediator); |
320 | 0 | return mediator; |
321 | |
} |
322 | |
|
323 | |
public Receive createReceive(IRI performance, IRI source) { |
324 | 0 | return new ReceiveRI(performance, source); |
325 | |
} |
326 | |
|
327 | |
public Send createSend(IRI performance, IRI target) { |
328 | 0 | return new SendRI(performance, target); |
329 | |
} |
330 | |
|
331 | |
|
332 | |
} |
333 | |
|
334 | 0 | private class ModesRI implements Modes |
335 | |
{ |
336 | |
|
337 | |
public In createIn(Concept concept) |
338 | |
{ |
339 | 0 | return new InRI(concept); |
340 | |
} |
341 | |
|
342 | |
public In createIn(Concept concept, Set<Grounding> grounding) |
343 | |
{ |
344 | 0 | return new InRI(concept, grounding); |
345 | |
} |
346 | |
|
347 | |
public In createIn(Relation relation) |
348 | |
{ |
349 | 0 | return new InRI(relation); |
350 | |
} |
351 | |
|
352 | |
public In createIn(Relation relation, Set<Grounding> grounding) |
353 | |
{ |
354 | 0 | return new InRI(relation, grounding); |
355 | |
} |
356 | |
|
357 | |
public Out createOut(Concept concept) |
358 | |
{ |
359 | 0 | return new OutRI(concept); |
360 | |
} |
361 | |
|
362 | |
public Out createOut(Concept concept, Set<Grounding> grounding) |
363 | |
{ |
364 | 0 | return new OutRI(concept, grounding); |
365 | |
} |
366 | |
|
367 | |
public Out createOut(Relation relation) |
368 | |
{ |
369 | 0 | return new OutRI(relation); |
370 | |
} |
371 | |
|
372 | |
public Out createOut(Relation relation, Set<Grounding> grounding) |
373 | |
{ |
374 | 0 | return new OutRI(relation, grounding); |
375 | |
} |
376 | |
|
377 | |
public Shared createShared(Concept concept) |
378 | |
{ |
379 | 0 | return new SharedRI(concept); |
380 | |
} |
381 | |
|
382 | |
public Shared createShared(Concept concept, Set<Grounding> grounding) |
383 | |
{ |
384 | 0 | return new SharedRI(concept, grounding); |
385 | |
} |
386 | |
|
387 | |
public Shared createShared(Relation relation) |
388 | |
{ |
389 | 0 | return new SharedRI(relation); |
390 | |
} |
391 | |
|
392 | |
public Shared createShared(Relation relation, Set<Grounding> grounding) |
393 | |
{ |
394 | 0 | return new SharedRI(relation, grounding); |
395 | |
} |
396 | |
|
397 | |
public Controlled createControlled(Concept concept) |
398 | |
{ |
399 | 0 | return new ControlledRI(concept); |
400 | |
} |
401 | |
|
402 | |
public Controlled createControlled(Relation relation) |
403 | |
{ |
404 | 0 | return new ControlledRI(relation); |
405 | |
} |
406 | |
|
407 | |
public Static createStatic(Concept concept) |
408 | |
{ |
409 | 0 | return new StaticRI(concept); |
410 | |
} |
411 | |
|
412 | |
public Static createStatic(Relation relation) |
413 | |
{ |
414 | 0 | return new StaticRI(relation); |
415 | |
} |
416 | |
|
417 | |
public WSDLGrounding createWSDLGrounding(IRI iri) |
418 | |
{ |
419 | 0 | return new WSDLGroundingRI(iri); |
420 | |
} |
421 | |
|
422 | |
} |
423 | |
|
424 | 0 | private class FactsRI implements Facts |
425 | |
{ |
426 | |
|
427 | |
public MoleculeFact createMoleculeFact() |
428 | |
{ |
429 | 0 | return new MoleculeFactRI(); |
430 | |
} |
431 | |
|
432 | |
public MoleculeFact createMoleculeFact( |
433 | |
Set<MembershipMolecule> memberMolecules, |
434 | |
Set<AttributeValueMolecule> attrValues) |
435 | |
{ |
436 | 0 | return new MoleculeFactRI(memberMolecules, attrValues); |
437 | |
} |
438 | |
|
439 | |
public MoleculeFact createMoleculeFact(MembershipMolecule memberMolecule, |
440 | |
Set<AttributeValueMolecule> attrValues) |
441 | |
{ |
442 | 0 | return new MoleculeFactRI(memberMolecule, attrValues); |
443 | |
} |
444 | |
|
445 | |
public MoleculeFact createMoleculeFact( |
446 | |
Set<MembershipMolecule> memberMolecules, |
447 | |
AttributeValueMolecule attrValue) |
448 | |
{ |
449 | 0 | return new MoleculeFactRI(memberMolecules, attrValue); |
450 | |
} |
451 | |
|
452 | |
public MoleculeFact createMoleculeFact(MembershipMolecule memberMolecule, |
453 | |
AttributeValueMolecule attrValue) |
454 | |
{ |
455 | 0 | return new MoleculeFactRI(memberMolecule, attrValue); |
456 | |
} |
457 | |
|
458 | |
public RelationFact createRelationFact() |
459 | |
{ |
460 | 0 | return new RelationFactRI(); |
461 | |
} |
462 | |
|
463 | |
public RelationFact createRelationFact(Atom atom) |
464 | |
{ |
465 | 0 | return new RelationFactRI(atom); |
466 | |
} |
467 | |
|
468 | |
} |
469 | |
|
470 | |
} |