Coverage Report - org.deri.wsmo4j.io.parser.wsml.ChoreographyAnalysis
 
Classes in this File Line Coverage Branch Coverage Complexity
ChoreographyAnalysis
0%
0/130
0%
0/64
0
 
 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  
 /**
 20  
  * <p>Title: WSMO4J</p>
 21  
  * <p>Description: WSMO API and a Reference Implementation</p>
 22  
  * <p>Copyright:  Copyright (c) 2004-2005</p>
 23  
  * <p>Company: OntoText Lab. / SIRMA </p>
 24  
  */
 25  
 
 26  
 package org.deri.wsmo4j.io.parser.wsml;
 27  
 
 28  
 import java.util.*;
 29  
 
 30  
 import org.deri.wsmo4j.choreography.signature.*;
 31  
 import org.omwg.ontology.*;
 32  
 import org.wsmo.common.*;
 33  
 import org.wsmo.factory.*;
 34  
 import org.wsmo.service.*;
 35  
 import org.wsmo.service.choreography.Choreography;
 36  
 import org.wsmo.service.choreography.rule.*;
 37  
 import org.wsmo.service.orchestration.Orchestration;
 38  
 import org.wsmo.service.orchestration.rule.*;
 39  
 import org.wsmo.service.signature.*;
 40  
 import org.wsmo.wsml.compiler.node.*;
 41  
 
 42  
 import com.ontotext.wsmo4j.parser.wsml.*;
 43  
 
 44  0
 @SuppressWarnings("unchecked")
 45  
 public class ChoreographyAnalysis extends ASTAnalysis {
 46  
 
 47  
     private ChoreographyFactory factory;
 48  
 
 49  
     private WsmoFactory wsmoFactory;
 50  
 
 51  
     private OrchestrationFactory orchFactory;
 52  
 
 53  
     private ASTAnalysisContainer container;
 54  
 
 55  
     private ASTAnalysis orignalHeaderAnalysis;
 56  
 
 57  
     public ChoreographyAnalysis(ASTAnalysisContainer container, ChoreographyFactory factory,
 58  0
             OrchestrationFactory orchFactory, WsmoFactory wsmoFactory) {
 59  0
         if (container == null || factory == null || wsmoFactory == null) {
 60  0
             throw new IllegalArgumentException();
 61  
         }
 62  0
         this.factory = factory;
 63  0
         this.wsmoFactory = wsmoFactory;
 64  0
         this.orchFactory = orchFactory;
 65  0
         this.container = container;
 66  
 
 67  
         // register the handled nodes
 68  0
         container.registerNodeHandler(AChorAsmChoreographyFormalism.class, this);
 69  0
         container.registerNodeHandler(AOrchAsmOrchestrationFormalism.class, this);
 70  0
         container.registerNodeHandler(AStateSignature.class, this);
 71  0
         container.registerNodeHandler(AMode.class, this);
 72  0
         container.registerNodeHandler(ADefaultModeModeEntry.class, this);
 73  0
         container.registerNodeHandler(AConceptModeModeEntry.class, this);
 74  0
         container.registerNodeHandler(ARelationModeModeEntry.class, this);
 75  0
         container.registerNodeHandler(AIrilistGroundingInfo.class, this);
 76  0
         container.registerNodeHandler(AIriGroundingInfo.class, this);
 77  
 
 78  
         // StateSignature may have use OOMediator or import Ontology 
 79  0
         container.registerNodeHandler(AImportsontology.class, this);
 80  0
         container.registerNodeHandler(AUsesmediator.class, this);
 81  
         // Get a handle to the original object to process AImportsontology and AUsesmediator
 82  0
         orignalHeaderAnalysis = container.getNodeHandler(AWsmlvariant.class);
 83  
         assert (orignalHeaderAnalysis instanceof TopEntityAnalysis) : "TopEntityAnalysis implemention is required to be registered in the "
 84  0
                 + "container in order to use ChoreographyAnalysis!";
 85  0
     }
 86  
 
 87  
     public void inAOrchAsmOrchestrationFormalism(AOrchAsmOrchestrationFormalism node) {
 88  0
         org.wsmo.service.Orchestration old = (org.wsmo.service.Orchestration) container.popFromStack(
 89  
                 org.wsmo.service.Orchestration.class, org.wsmo.service.Orchestration.class);
 90  0
         Orchestration newOrchestration = orchFactory.containers.createOrchestration(old.getIdentifier());
 91  0
         ServiceAnalysis.copyNFP(old, newOrchestration);
 92  0
         Interface iface = (Interface) container.peekFromStack(TopEntity.class, Interface.class);
 93  0
         iface.setOrchestration(newOrchestration);
 94  0
         container.getStack(org.wsmo.service.Orchestration.class).push(newOrchestration);
 95  0
     }
 96  
 
 97  
     public void outAOrchAsmOrchestrationFormalism(AOrchAsmOrchestrationFormalism node) {
 98  0
         Orchestration orch = (Orchestration) container.peekFromStack(
 99  
                 org.wsmo.service.Orchestration.class, Orchestration.class);
 100  0
         if (!container.getStack(StateSignature.class).isEmpty()) {
 101  0
             orch.setStateSignature((StateSignature) container.popFromStack(StateSignature.class,
 102  
                     StateSignature.class));
 103  
         }
 104  0
         if (!container.getStack(RuleAnalyzer.class).isEmpty()) {
 105  0
             orch.setRules((OrchestrationRules) container.popFromStack(RuleAnalyzer.class,
 106  
                     OrchestrationRules.class));
 107  
         }
 108  0
     }
 109  
 
 110  
     public void inAChorAsmChoreographyFormalism(AChorAsmChoreographyFormalism node) {
 111  0
         org.wsmo.service.Choreography old = (org.wsmo.service.Choreography) container.popFromStack(
 112  
                 org.wsmo.service.Choreography.class, org.wsmo.service.Choreography.class);
 113  0
         Choreography newChoreography = factory.containers.createChoreography(old.getIdentifier());
 114  0
         ServiceAnalysis.copyNFP(old, newChoreography);
 115  0
         Interface iface = (Interface) container.peekFromStack(TopEntity.class, Interface.class);
 116  0
         iface.setChoreography(newChoreography);
 117  0
         container.getStack(org.wsmo.service.Choreography.class).push(newChoreography);
 118  0
     }
 119  
 
 120  
     public void outAChorAsmChoreographyFormalism(AChorAsmChoreographyFormalism node) {
 121  0
         Choreography choreography = (Choreography) container.peekFromStack(
 122  
                 org.wsmo.service.Choreography.class, Choreography.class);
 123  0
         if (!container.getStack(StateSignature.class).isEmpty()) {
 124  0
             choreography.setStateSignature((StateSignature) container.popFromStack(
 125  
                     StateSignature.class, StateSignature.class));
 126  
         }
 127  0
         if (!container.getStack(RuleAnalyzer.class).isEmpty()) {
 128  0
             choreography.setRules((ChoreographyRules) container.popFromStack(RuleAnalyzer.class,
 129  
                     ChoreographyRules.class));
 130  
         }
 131  0
     }
 132  
 
 133  
     public void inAStateSignature(AStateSignature node) {
 134  0
         Identifier id = null;
 135  0
         if (node.getId() instanceof AAnonymousId || node.getId() == null) {
 136  0
             id = wsmoFactory.createAnonymousID();
 137  
         }
 138  
         else {
 139  0
             node.getId().apply(container.getNodeHandler(PId.class));
 140  0
             id = (Identifier) container.popFromStack(Identifier.class, Identifier.class);
 141  
         }
 142  0
         StateSignature stateSignature = factory.containers.createStateSignature(id);
 143  0
         container.getStack(StateSignature.class).push(stateSignature);
 144  0
         container.getStack(Entity.class).push(stateSignature);
 145  0
     }
 146  
 
 147  
     public void outAStateSignature(AStateSignature node) {
 148  0
         container.popFromStack(Entity.class, StateSignature.class);
 149  0
     }
 150  
 
 151  
     // Mode section
 152  
 
 153  
     private PModeId modeType;
 154  
 
 155  
     public void inAMode(AMode node) {
 156  0
         modeType = node.getModeId();
 157  0
     }
 158  
 
 159  
     public void outADefaultModeModeEntry(ADefaultModeModeEntry node) {
 160  0
         outModeEntry(node.getGrounding(), true);
 161  0
     }
 162  
 
 163  
     public void outAConceptModeModeEntry(AConceptModeModeEntry node) {
 164  0
         outModeEntry(node.getGrounding(), true);
 165  0
     }
 166  
 
 167  
     public void outARelationModeModeEntry(ARelationModeModeEntry node) {
 168  0
         outModeEntry(node.getGrounding(), false);
 169  0
     }
 170  
 
 171  
     private void outModeEntry(PGrounding groundingNode, boolean isConcept) {
 172  0
         Set<Grounding> groundings = new HashSet<Grounding>();
 173  0
         if (groundingNode != null) {
 174  0
             groundings.addAll(Arrays.asList((Grounding[]) container.popFromStack(Grounding[].class,
 175  
                     Grounding[].class)));
 176  
         }
 177  0
         IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 178  0
         if (isConcept)
 179  0
             createMode(wsmoFactory.createConcept(iri), groundings);
 180  
         else
 181  0
             createMode(wsmoFactory.createRelation(iri), groundings);
 182  0
     }
 183  
 
 184  
     private void createMode(Concept concept, Set<Grounding> groundings) {
 185  0
         StateSignature signature = (StateSignature) container.peekFromStack(StateSignature.class,
 186  
                 StateSignature.class);
 187  0
         if (modeType instanceof AInModeId) {
 188  0
             signature.addMode(factory.modes.createIn(concept, groundings));
 189  
         }
 190  0
         else if (modeType instanceof AOutModeId) {
 191  0
             signature.addMode(factory.modes.createOut(concept, groundings));
 192  
         }
 193  0
         else if (modeType instanceof ASharedModeId) {
 194  0
             signature.addMode(factory.modes.createShared(concept, groundings));
 195  
             ;
 196  
         }
 197  0
         else if (modeType instanceof AStaticModeId) {
 198  0
             signature.addMode(factory.modes.createStatic(concept));
 199  
         }
 200  0
         else if (modeType instanceof AControlledModeId) {
 201  0
             signature.addMode(factory.modes.createControlled(concept));
 202  
         }
 203  0
     }
 204  
 
 205  
     private void createMode(Relation relation, Set<Grounding> groundings) {
 206  0
         StateSignature signature = (StateSignature) container.peekFromStack(StateSignature.class,
 207  
                 StateSignature.class);
 208  0
         if (modeType instanceof AInModeId) {
 209  0
             signature.addMode(factory.modes.createIn(relation, groundings));
 210  
         }
 211  0
         else if (modeType instanceof AOutModeId) {
 212  0
             signature.addMode(factory.modes.createOut(relation, groundings));
 213  
         }
 214  0
         else if (modeType instanceof ASharedModeId) {
 215  0
             signature.addMode(factory.modes.createShared(relation, groundings));
 216  
             ;
 217  
         }
 218  0
         else if (modeType instanceof AStaticModeId) {
 219  0
             signature.addMode(factory.modes.createStatic(relation));
 220  
         }
 221  0
         else if (modeType instanceof AControlledModeId) {
 222  0
             signature.addMode(factory.modes.createControlled(relation));
 223  
         }
 224  0
     }
 225  
 
 226  
     // end Mode section
 227  
 
 228  
     // Grounding iri lists section
 229  
 
 230  0
     private Object lastIdentifierItem = null;
 231  
 
 232  
     public void inAIrilistGroundingInfo(AIrilistGroundingInfo node) {
 233  0
         if (container.getStack(Identifier.class).isEmpty())
 234  0
             lastIdentifierItem = null;
 235  
         else
 236  0
             lastIdentifierItem = container.peekFromStack(Identifier.class, Identifier.class);
 237  0
     }
 238  
 
 239  
     public void outAIrilistGroundingInfo(AIrilistGroundingInfo node) {
 240  0
         Stack identifierStack = container.getStack(Identifier.class);
 241  0
         Set<Grounding> groundings = new HashSet<Grounding>();
 242  0
         while (!identifierStack.isEmpty() && lastIdentifierItem != identifierStack.peek()) {
 243  0
             groundings.add(new WSDLGroundingRI((IRI) identifierStack.pop()));
 244  
         }
 245  0
         container.getStack(Grounding[].class).push(groundings.toArray(new Grounding[] {}));
 246  0
     }
 247  
 
 248  
     public void outAIriGroundingInfo(AIriGroundingInfo node) {
 249  0
         IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 250  0
         container.getStack(Grounding[].class).push(new Grounding[] { new WSDLGroundingRI(iri) });
 251  0
     }
 252  
 
 253  
     // end Grounding iri lists section
 254  
 
 255  
     public void outAImportsontology(AImportsontology node) {
 256  0
         if (!container.getStack(StateSignature.class).isEmpty()) {
 257  
             // case 1 header in StateSignature
 258  0
             Identifier[] iris = (Identifier[]) container.popFromStack(Identifier[].class,
 259  
                     Identifier[].class);
 260  0
             StateSignature state = (StateSignature) container.getStack(StateSignature.class).peek();
 261  0
             for (int i = 0; i < iris.length; i++) {
 262  0
                 state.addOntology(wsmoFactory.getOntology((IRI) iris[i]));
 263  
             }
 264  0
         }
 265  
         else { // header of a TopEntity
 266  0
             orignalHeaderAnalysis.outAImportsontology(node);
 267  
         }
 268  0
     }
 269  
 
 270  
     public void outAUsesmediator(AUsesmediator node) {
 271  0
         if (!container.getStack(StateSignature.class).isEmpty()) {
 272  
             // case 1 header in StateSignature
 273  0
             Identifier[] iris = (Identifier[]) container.popFromStack(Identifier[].class,
 274  
                     Identifier[].class);
 275  0
             StateSignature state = (StateSignature) container.getStack(StateSignature.class).peek();
 276  0
             for (int i = 0; i < iris.length; i++) {
 277  0
                 assert iris[i] instanceof IRI;
 278  0
                 state.addMediator(wsmoFactory.getOOMediator((IRI) iris[i]));
 279  
             }
 280  0
         }
 281  
         else {
 282  
             // case 2 header of a topEntity
 283  0
             orignalHeaderAnalysis.outAUsesmediator(node);
 284  
         }
 285  0
     }
 286  
 }
 287  
 
 288  
 /*
 289  
  * $Log$
 290  
  * Revision 1.17  2006/12/04 11:17:53  vassil_momtchev
 291  
  * wsmo4j parser always processe the choreography/orchestration; the extended parser will swap the implementation with the appropriate one
 292  
  *
 293  
  * Revision 1.16  2006/11/22 12:54:23  vassil_momtchev
 294  
  * Choreography/Orchestration parsing is now correct; warning: StateSignature of Chor/Orch will be ignroed if no formalism like Cashew/ASM/AD is defined
 295  
  *
 296  
  * Revision 1.15  2006/11/17 10:09:53  vassil_momtchev
 297  
  * fixed bug in orchestration parsing. the rules container was not set properly;
 298  
  *
 299  
  * Revision 1.14  2006/10/24 14:11:47  vassil_momtchev
 300  
  * choreography/orchestration rules refactored. different types where appropriate now supported
 301  
  *
 302  
  * Revision 1.13  2006/06/07 13:03:42  vassil_momtchev
 303  
  * orchestration parsing added
 304  
  *
 305  
  * Revision 1.12  2006/04/17 10:53:54  vassil_momtchev
 306  
  * outAChoreography and inAChoreography methods use ChoreographyFactory.createChoreography(Identifier); no longer need of dummy Entity object to collect NFPs required
 307  
  *
 308  
  * Revision 1.11  2006/03/06 16:00:30  vassil_momtchev
 309  
  * transitionRules are no longer mandatory for a statesignature (rules container with anonymous id by default is used)
 310  
  *
 311  
  * Revision 1.10  2006/02/17 12:20:19  vassil_momtchev
 312  
  * helper dummy entity was not removed if choreography is only declared
 313  
  *
 314  
  * Revision 1.9  2006/02/10 15:35:34  vassil_momtchev
 315  
  * new grammar implemented
 316  
  *
 317  
  * Revision 1.8  2006/01/31 15:36:04  vassil_momtchev
 318  
  * choreography nfps were assigned to the last previous entity; dummy entity is used now to collect them
 319  
  *
 320  
  * Revision 1.7  2006/01/31 10:51:38  vassil_momtchev
 321  
  * unused fields removed; log footer added
 322  
  *
 323  
  * Revision 1.6  2006/01/10 14:05:21  vassil_momtchev
 324  
  * importOntology in StateSignature node is handled correct now sf:1365514
 325  
  *
 326  
  * Revision 1.5  2005/12/21 14:39:54  vassil_momtchev
 327  
  * choreography refered by id only are created as ChoreographyImpl
 328  
  *
 329  
  * Revision 1.4  2005/12/21 11:36:49  vassil_momtchev
 330  
  * analyse of rules shifted to RuleAnalyzer class
 331  
  *
 332  
  * Revision 1.3  2005/12/07 11:48:09  vassil_momtchev
 333  
  * modified after the latest api changes
 334  
  *
 335  
  * Revision 1.2  2005/11/29 14:09:11  vassil_momtchev
 336  
  * bug fixed in the grounding irilist parsing
 337  
  *
 338  
  * Revision 1.1  2005/11/28 16:00:41  vassil_momtchev
 339  
  * choreography parser added extending com.ontotext.wsmo4j.parser.wsml.ParserImpl (ParserImpl.java)
 340  
  * AST analysis of choreography (ChoreographyAnalysis.java)
 341  
  *
 342  
  */