View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3    
4    Copyright (c) 2004-2005, OntoText Lab. / SIRMA
5    
6    This library is free software; you can redistribute it and/or modify it under
7    the terms of the GNU Lesser General Public License as published by the Free
8    Software Foundation; either version 2.1 of the License, or (at your option)
9    any later version.
10   This library is distributed in the hope that it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13   details.
14   You should have received a copy of the GNU Lesser General Public License along
15   with this library; if not, write to the Free Software Foundation, Inc.,
16   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17   */
18  
19  package com.ontotext.wsmo4j.serializer.wsml;
20  
21  /**
22   * <p>Title: WSMO4J</p>
23   * <p>Description: WSMO API and a Reference Implementation</p>
24   * <p>Copyright:  Copyright (c) 2004-2005</p>
25   * <p>Company: OntoText Lab. / SIRMA </p>
26   * @author not attributable
27   * @version 1.0
28   *
29   */
30  import java.util.*;
31  
32  import org.omwg.logicalexpression.*;
33  import org.omwg.ontology.*;
34  import org.wsmo.common.*;
35  import org.wsmo.mediator.*;
36  import org.wsmo.service.*;
37  
38  public class WSMLEnumerator implements Visitor {
39      
40      private final static boolean USE_MULTIPLE_INTERFACE_LIST = false;
41  
42      public void visit(IRI uri) {
43          throw new UnsupportedOperationException("this should not happen");
44      }
45  
46      public void visit(Entity item) {
47          Map map = item.listNFPValues();
48          if (map.size() > 0) {
49              inEntity(item);
50  
51              Iterator iter = map.entrySet().iterator();
52              while (iter.hasNext()) {
53                  Map.Entry en = (Map.Entry)iter.next();
54                  IRI key = (IRI)en.getKey();
55                  Set vals = (Set)en.getValue();
56                  onNFPKeyValues(key, vals);
57              }
58  
59              outEntity(item);
60          }
61      }
62      public void inEntity(Entity item) {    }
63      public void onNFPKeyValues(IRI key, Set vals) {    }
64      public void outEntity(Entity item) {    }
65  
66  
67      public void visit(TopEntity item) {
68          inTopEntity(item);
69          visit((Entity)item);
70          Set list = item.listOntologies();
71          if (list.size() > 0) {
72              inImportsOntologies(item);
73              onImportedOntologies(list);
74              outImportsOntologies(item);
75          }
76          list = item.listMediators();
77          if (list.size() > 0) {
78              inUsesMediators(item);
79              onUsedMediators(list);
80              outUsesMediators(item);
81          }
82  
83          outTopEntity(item);
84      }
85      
86      public void inTopEntity(TopEntity item) {   
87          if (item.getIdentifier() instanceof IRI == false) {
88              throw new RuntimeException("Cannot serialize " +
89                      item.getClass() + " identified not by IRI!");
90          }
91      }
92      public void outTopEntity(TopEntity item) {   }
93  
94      public void inImportsOntologies(TopEntity item) {    }
95      public void outImportsOntologies(TopEntity item) {    }
96      public void onImportedOntologies(Set list) {    }
97  
98      public void inUsesMediators(TopEntity item) {    }
99      public void outUsesMediators(TopEntity item) {    }
100     public void onUsedMediators(Set list) {    }
101 
102     public void visit(Ontology item) {
103         inOntology(item);
104         visit((TopEntity)item);
105         Iterator items = null;
106         // dump axioms
107         items = item.listAxioms().iterator();
108         while (items.hasNext()) {
109             new WSMLItem((Entity)items.next()).apply(this);
110         }
111         // dump concepts
112         items = item.listConcepts().iterator();
113         while (items.hasNext()) {
114             new WSMLItem((Entity)items.next()).apply(this);
115         }
116         // dump relations
117         items = item.listRelations().iterator();
118         while (items.hasNext()) {
119             Entity relItem = (Entity)items.next();
120             new WSMLItem(relItem).apply(this);
121         }
122         // dump instances
123         items = item.listInstances().iterator();
124         while (items.hasNext()) {
125             new WSMLItem((Entity)items.next()).apply(this);
126         }
127         // dump relationInstances
128         items = item.listRelationInstances().iterator();
129         while (items.hasNext()) {
130             new WSMLItem((Entity)items.next()).apply(this);
131         }
132 
133         outOntology(item);
134     }
135 
136     public void visit(Axiom item) {
137         inAxiom(item);
138         onAxiomDefinition(item);
139         outAxiom(item);
140     }
141 
142     public void onAxiomDefinition(Axiom item) {
143         visit((Entity)item);
144         Set list = item.listDefinitions();
145         if (list.size() > 0 ) {
146             inLogExpressionDefinition(item);
147             Iterator iter = list.iterator();
148             while (iter.hasNext()) {
149                 visit((LogicalExpression)iter.next());
150             }
151             outLogExpressionDefinition(item);
152         }
153     }
154     public void visit(LogicalExpression item) {
155         onLogExpression(item);
156     }
157     public void onLogExpression(LogicalExpression item) {   }
158     public void inLogExpressionDefinition(Axiom item) {    }
159     public void outLogExpressionDefinition(Axiom item) {    }
160 
161     public void visit(Concept item) {
162         inConcept(item);
163         Set list = item.listSuperConcepts();
164         if (list.size() > 0) {
165             onSuperConcepts(list);
166         }
167         visit((Entity)item);
168         list = item.listAttributes();
169         if (list.size() > 0) {
170             Iterator iter = list.iterator();
171             while (iter.hasNext()) {
172                 new WSMLItem((Entity)iter.next()).apply(this);
173             }
174         }
175         outConcept(item);
176     }
177     public void onSuperConcepts(Set superconcepts) {    }
178     public void visit(Attribute item) {
179         inAttribute(item);
180         visit((Entity)item);
181         outAttribute(item);
182     }
183     public void inAttribute(Attribute item) { }
184     public void outAttribute(Attribute item) { }
185     
186     public void visit(Relation item) {
187         inRelation(item);
188         List aList = item.listParameters();
189         if (aList.size() > 0) {
190             onParameters(aList);
191         }
192         Set list = item.listSuperRelations();
193         if (list.size() > 0) {
194             onSuperRelations(list);
195         }
196         visit((Entity)item);
197         outRelation(item);
198     }
199     public void onSuperRelations(Set list) {    }
200 
201     public void onParameters(List list) { }
202 
203     public void visit(Instance item) {
204         inInstance(item);
205         Set list = item.listConcepts();
206         onInstanceMemberOf(list);
207 
208         visit((Entity)item);
209         Map map = item.listAttributeValues();
210         Iterator iter = map.entrySet().iterator();
211         while (iter.hasNext()) {
212             Map.Entry e = (Map.Entry)iter.next();
213             Identifier key = (Identifier)e.getKey();
214             Set val = (Set)e.getValue();
215             onAttributeKeyValue(key, val);
216         }
217         outInstance(item);
218     }
219     public void onInstanceMemberOf(Set list) { }
220     public void onAttributeKeyValue(Identifier key, Set values) { }
221 
222     public void visit(RelationInstance item) {
223         inRelationInstance(item);
224         onRelationInstanceMemberOf(item.getRelation());
225         List values = item.listParameterValues();
226         onParameterValues(values);
227         visit((Entity)item);
228         outRelationInstance(item);
229     }
230     public void onRelationInstanceMemberOf(Relation concept) { }
231     public void onParameterValues(List values) { }
232 
233     public void visit(ServiceDescription item) {
234         visit((TopEntity)item);
235         Capability capability = item.getCapability();
236         if (capability != null)
237             new WSMLItem(capability).apply(this);
238         Set list = item.listInterfaces();
239         if (list.size()> 0) {
240             if (!USE_MULTIPLE_INTERFACE_LIST || list.size() == 1) {
241                 for (Iterator i = list.iterator(); i.hasNext();) {
242                     new WSMLItem((Entity) i.next()).apply(this);
243                 }
244             }
245             else {
246                 onMultipleInterfaces(list);
247             }
248         }
249     }
250     public void onMultipleInterfaces(Set list) {
251     }
252 
253     public void onSharedVariables(Set list) {
254     }
255 
256     public void visit(Capability item) {
257         inCapability(item);
258         visit((TopEntity)item);
259         Set list = null;
260         list = item.listSharedVariables();
261         if (list.size() > 0) {
262             onSharedVariables(list);
263         }
264 
265         list = item.listAssumptions();
266         if (list.size() > 0) {
267             Iterator iter = list.iterator();
268             while (iter.hasNext()) {
269                 Axiom ax = (Axiom)iter.next();
270                 onHasAssumptions(ax);
271                 onAxiomDefinition(ax);
272             }
273         }
274         list = item.listEffects();
275         if (list.size() > 0) {
276             Iterator iter = list.iterator();
277             while (iter.hasNext()) {
278                 Axiom ax = (Axiom)iter.next();
279                 onHasEffects(ax);
280                 onAxiomDefinition(ax);
281             }
282         }
283         list = item.listPreConditions();
284         if (list.size() > 0) {
285             Iterator iter = list.iterator();
286             while (iter.hasNext()) {
287                 Axiom ax = (Axiom)iter.next();
288                 onHasPreconditions(ax);
289                 onAxiomDefinition(ax);
290             }
291         }
292         list = item.listPostConditions();
293         if (list.size() > 0) {
294             Iterator iter = list.iterator();
295             while (iter.hasNext()) {
296                 Axiom ax = (Axiom)iter.next();
297                 onHasPostconditions(ax);
298                 onAxiomDefinition(ax);
299             }
300         }
301         outCapability(item);
302     }
303     public void onHasAssumptions(Entity item) { }
304     public void onHasEffects(Entity item) { }
305     public void onHasPreconditions(Entity item) { }
306     public void onHasPostconditions(Entity item) { }
307 
308     public void visit(Interface item) {
309         inInterface(item);
310         visit((TopEntity)item);
311         if (item.getChoreography() != null)
312             new WSMLItem(item.getChoreography()).apply(this);
313         if (item.getOrchestration() != null)
314             new WSMLItem(item.getOrchestration()).apply(this);
315         outInterface(item);
316     }
317     public void visit(Orchestration item) {
318         inOrchestration(item);
319         visit((Entity)item);
320         outOrchestration(item);
321     }
322     public void visit(Choreography item) {
323         inChoreography(item);
324         visit((Entity)item);
325         outChoreography(item);
326     }
327 
328     public void visit(WebService item) {
329         inWebService(item);
330         visit((ServiceDescription)item);
331         outWebService(item);
332     }
333 
334     public void visit(Goal item) {
335         inGoal(item);
336         visit((ServiceDescription)item);
337         outGoal(item);
338     }
339 
340     public void visit(Mediator item) {
341         visit((TopEntity)item);
342         Set list = item.listSources();
343         if (list.size() > 0) {
344             onMediatorSources(list);
345         }
346         if (item.getTarget() != null)
347             onMediatorTarget((Identifier)item.getTarget());
348         if (item.getMediationService() != null)
349             onMediatorUseService(item.getMediationService());
350     }
351     public void visit(OOMediator item) {
352         inOOMediator(item);
353         visit((Mediator)item);
354         outOOMediator(item);
355     }
356     public void visit(WGMediator item) {
357         inWGMediator(item);
358         visit((Mediator)item);
359         outWGMediator(item);
360     }
361     public void visit(WWMediator item) {
362         inWWMediator(item);
363         visit((Mediator)item);
364         outWWMediator(item);
365     }
366     public void visit(GGMediator item) {
367         inGGMediator(item);
368         visit((Mediator)item);
369         outGGMediator(item);
370     }
371 // ------------------ complete ---
372     public void inOntology(Ontology item) {
373     }
374     public void inAxiom(Axiom item) {
375     }
376     public void inConcept(Concept item) {
377     }
378     public void inRelation(Relation item) {
379     }
380     public void inInstance(Instance item) {
381     }
382     public void inRelationInstance(RelationInstance item) {
383     }
384 
385     public void inWebService(WebService item) {
386     }
387     public void inCapability(Capability item) {
388     }
389     public void inInterface(Interface item) {
390     }
391     public void inOrchestration(Orchestration item) {
392     }
393     public void inChoreography(Choreography item) {
394     }
395 
396     public void inGoal(Goal item) {
397     }
398 
399     public void inOOMediator(OOMediator item) {
400     }
401     public void inWGMediator(WGMediator item) {
402     }
403     public void inWWMediator(WWMediator item) {
404     }
405     public void inGGMediator(GGMediator item) {
406     }
407 
408     public void onMediatorSources(Set item) {
409     }
410     public void onMediatorTarget(Identifier item) {
411     }
412     public void onMediatorUseService(Identifier item) {
413     }
414 
415     public void outOntology(Ontology item) {
416     }
417     public void outAxiom(Axiom item) {
418     }
419     public void outConcept(Concept item) {
420     }
421     public void outRelation(Relation item) {
422     }
423     public void outInstance(Instance item) {
424     }
425     public void outRelationInstance(RelationInstance item) {
426     }
427 
428     public void outWebService(WebService item) {
429     }
430     public void outCapability(Capability item) {
431     }
432     public void outInterface(Interface item) {
433     }
434     public void outOrchestration(Orchestration item) {
435     }
436     public void outChoreography(Choreography item) {
437     }
438 
439     public void outGoal(Goal item) {
440     }
441 
442     public void outOOMediator(OOMediator item) {
443     }
444     public void outWGMediator(WGMediator item) {
445     }
446     public void outWWMediator(WWMediator item) {
447     }
448     public void outGGMediator(GGMediator item) {
449     }
450 
451 }
452 
453 /*
454  * $Log$
455  * Revision 1.6  2006/03/29 08:51:57  vassil_momtchev
456  * mediator reference source/target by IRI (changed from TopEntity); mediator reference mediationService by IRI (changed from Identifier)
457  *
458  * Revision 1.5  2006/03/06 15:22:40  vassil_momtchev
459  * when multiple interfaces used in a webservice, serialize the full interface data instead of minterfaces = 'interface' '{' id moreids* '}' reference construction
460  *
461  * Revision 1.4  2006/02/13 10:42:36  vassil_momtchev
462  * throw exception if topentity identified by anonId (created by another impl) serialized
463  *
464  * Revision 1.3  2006/02/10 14:39:49  vassil_momtchev
465  * serializer addapted to the new api changes
466  *
467  * Revision 1.2  2005/11/28 14:51:37  vassil_momtchev
468  * moved from com.ontotext.wsmo4j.parser
469  *
470  * Revision 1.1.2.1  2005/11/28 13:59:35  vassil_momtchev
471  * package refactored from com.ontotext.wsmo4j.parser to com.ontotext.wsmo4j.serializer.wsml
472  *
473  * Revision 1.3.2.1  2005/11/21 17:38:36  holgerlausen
474  * added more logexp support
475  *
476  * Revision 1.3  2005/09/02 13:32:45  ohamano
477  * move logicalexpression packages from ext to core
478  * move tests from logicalexpression.test to test module
479  *
480  * Revision 1.2  2005/07/05 12:45:51  alex_simov
481  * attributes refactored
482  *
483  * Revision 1.1  2005/06/27 08:32:00  alex_simov
484  * refactoring: *.io.parser -> *.parser
485  *
486  * Revision 1.12  2005/06/22 15:53:36  alex_simov
487  * capability parse bug fix
488  *
489  * Revision 1.11  2005/06/22 14:49:27  alex_simov
490  * Copyright header added/updated
491  *
492  * Revision 1.10  2005/06/02 14:19:19  alex_simov
493  * v0.4.0
494  *
495  * Revision 1.2  2005/06/02 12:33:09  damian
496  * fixes
497  *
498  * Revision 1.1  2005/05/26 09:36:03  damian
499  * io package
500  *
501  * Revision 1.9  2005/03/02 10:56:41  morcen
502  * fixed bugs 1154273, 1154263, 1154190 with the serializers
503  *
504  * Revision 1.8  2005/01/25 14:03:55  alex_simov
505  * Refactoring:
506  * 1. Instance: getMemberOf()/setMemberOf() replaced by getConcept()/setConcept()
507  * 2. RelationInstance: getInstanceOf()/setInstanceOf() replaced by getRelation()/setRelation()
508  *
509  * Revision 1.7  2005/01/12 15:20:18  alex_simov
510  * checkstyle formatting
511  *
512  */