Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 345   Methods: 23
NCLOC: 238   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ServiceAnalysis.java 0% 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3   
 4    Copyright (c) 2004-2005, OntoText Lab. / SIRMA
 5    University of Innsbruck, Austria
 6   
 7    This library is free software; you can redistribute it and/or modify it under
 8    the terms of the GNU Lesser General Public License as published by the Free
 9    Software Foundation; either version 2.1 of the License, or (at your option)
 10    any later version.
 11    This library is distributed in the hope that it will be useful, but WITHOUT
 12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 13    FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 14    details.
 15    You should have received a copy of the GNU Lesser General Public License along
 16    with this library; if not, write to the Free Software Foundation, Inc.,
 17    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 18    */
 19   
 20    /**
 21    * <p>Title: WSMO4J</p>
 22    * <p>Description: WSMO API and a Reference Implementation</p>
 23    * <p>Copyright: Copyright (c) 2004-2005</p>
 24    * <p>Company: OntoText Lab. / SIRMA </p>
 25    */
 26   
 27    package com.ontotext.wsmo4j.parser.wsml;
 28   
 29    import java.util.*;
 30    import java.util.Map.Entry;
 31   
 32    import org.deri.wsmo4j.common.*;
 33    import org.omwg.ontology.*;
 34    import org.wsmo.common.*;
 35    import org.wsmo.common.exception.*;
 36    import org.wsmo.factory.*;
 37    import org.wsmo.service.*;
 38    import org.wsmo.wsml.compiler.analysis.*;
 39    import org.wsmo.wsml.compiler.node.*;
 40   
 41    import com.ontotext.wsmo4j.parser.*;
 42   
 43    public class ServiceAnalysis extends ASTAnalysis {
 44   
 45    private WsmoFactory factory;
 46   
 47    private LogicalExpressionFactory leFactory;
 48   
 49    private ASTAnalysisContainer container;
 50   
 51    private boolean cleanOnParse = false;
 52   
 53  0 public ServiceAnalysis(ASTAnalysisContainer container, WsmoFactory factory,
 54    LogicalExpressionFactory leFactory) {
 55  0 if (container == null || factory == null) {
 56  0 throw new IllegalArgumentException();
 57    }
 58  0 this.factory = factory;
 59  0 this.container = container;
 60  0 this.leFactory = leFactory;
 61   
 62    // register the handled nodes
 63  0 container.registerNodeHandler(AWebservice.class, this);
 64  0 container.registerNodeHandler(AGoal.class, this);
 65  0 container.registerNodeHandler(ACapability.class, this);
 66  0 container.registerNodeHandler(APostconditionPrePostAssOrEff.class, this);
 67  0 container.registerNodeHandler(APreconditionPrePostAssOrEff.class, this);
 68  0 container.registerNodeHandler(AAssumptionPrePostAssOrEff.class, this);
 69  0 container.registerNodeHandler(AEffectPrePostAssOrEff.class, this);
 70  0 container.registerNodeHandler(ASharedvardef.class, this);
 71  0 container.registerNodeHandler(AInterface.class, this);
 72  0 container.registerNodeHandler(AChoreography.class, this);
 73  0 container.registerNodeHandler(AOrchestration.class, this);
 74    }
 75   
 76  0 public void setCleanOnParse(boolean cleanOnParse){
 77  0 this.cleanOnParse=cleanOnParse;
 78    }
 79   
 80  0 private void cleanServiceDescription(ServiceDescription s){
 81    //clean previous contents of this mediator:
 82  0 try {
 83  0 ClearTopEntity.clearTopEntity(s);
 84    }
 85    catch (SynchronisationException e) {
 86    // should never happen
 87  0 throw new RuntimeException("Error During Cleaning TopEntity from previous defintions",e);
 88    }
 89    catch (InvalidModelException e) {
 90    // should never happen
 91  0 throw new RuntimeException("Error During Cleaning TopEntity from previous defintions",e);
 92    }
 93   
 94    }
 95   
 96  0 public void inAWebservice(AWebservice node) {
 97  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(),node.getTWebservice());
 98  0 node.getId().apply(container.getNodeHandler(PId.class));
 99  0 IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 100  0 WebService ws = factory.createWebService(iri);
 101  0 if (cleanOnParse){
 102  0 cleanServiceDescription(ws);
 103    }
 104  0 copyNSAndAddToStacks(ws);
 105    }
 106   
 107  0 public void outAWebservice(AWebservice node) {
 108  0 container.popFromStack(Entity.class, WebService.class);
 109    }
 110   
 111  0 public void inAGoal(AGoal node) {
 112  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(),node.getTGoal());
 113  0 node.getId().apply(container.getNodeHandler(PId.class));
 114  0 IRI id = (IRI) container.popFromStack(Identifier.class, IRI.class);
 115  0 Goal g = factory.createGoal(id);
 116  0 if (cleanOnParse){
 117  0 cleanServiceDescription(g);
 118    }
 119  0 copyNSAndAddToStacks(g);
 120    }
 121   
 122  0 public void outAGoal(AGoal node) {
 123  0 container.popFromStack(Entity.class, Goal.class);
 124    }
 125   
 126  0 public void inACapability(ACapability node) {
 127  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(), node.getTCapability());
 128  0 node.getId().apply(container.getNodeHandler(PId.class));
 129  0 IRI id = (IRI) container.popFromStack(Identifier.class, IRI.class);
 130  0 Capability capability = factory.createCapability(id);
 131   
 132    // find if it's in a Goal
 133  0 Stack entities = container.getStack(Entity.class);
 134  0 for (int i = entities.size() - 1; i >= 0; i--) {
 135  0 Entity entity = (Entity) entities.elementAt(i);
 136  0 if (entity instanceof ServiceDescription) {
 137  0 ((ServiceDescription) entity).setCapability(capability);
 138  0 break;
 139    }
 140    }
 141   
 142  0 copyNSAndAddToStacks(capability);
 143    }
 144   
 145  0 public void outACapability(ACapability node) {
 146  0 container.popFromStack(Entity.class, Capability.class);
 147    }
 148   
 149  0 public void outAPostconditionPrePostAssOrEff(APostconditionPrePostAssOrEff node) {
 150  0 Capability capability = (Capability) container.peekFromStack(TopEntity.class,
 151    Capability.class);
 152  0 try {
 153  0 capability.addPostCondition((Axiom) container.peekFromStack(Axiom.class, Axiom.class));
 154    }
 155    catch (InvalidModelException e) {
 156  0 throw new WrappedInvalidModelException(e);
 157    }
 158    }
 159   
 160  0 public void outAPreconditionPrePostAssOrEff(APreconditionPrePostAssOrEff node) {
 161  0 Capability capability = (Capability) container.peekFromStack(TopEntity.class,
 162    Capability.class);
 163  0 try {
 164  0 capability.addPreCondition((Axiom) container.popFromStack(Axiom.class, Axiom.class));
 165    }
 166    catch (InvalidModelException e) {
 167  0 throw new WrappedInvalidModelException(e);
 168    }
 169    }
 170   
 171  0 public void outAAssumptionPrePostAssOrEff(AAssumptionPrePostAssOrEff node) {
 172  0 Capability capability = (Capability) container.peekFromStack(TopEntity.class,
 173    Capability.class);
 174  0 try {
 175  0 capability.addAssumption((Axiom) container.popFromStack(Axiom.class, Axiom.class));
 176    }
 177    catch (InvalidModelException e) {
 178  0 throw new WrappedInvalidModelException(e);
 179    }
 180    }
 181   
 182  0 public void outAEffectPrePostAssOrEff(AEffectPrePostAssOrEff node) {
 183  0 Capability capability = (Capability) container.peekFromStack(TopEntity.class,
 184    Capability.class);
 185  0 try {
 186  0 capability.addEffect((Axiom) container.popFromStack(Axiom.class, Axiom.class));
 187    }
 188    catch (InvalidModelException e) {
 189  0 throw new WrappedInvalidModelException(e);
 190    }
 191    }
 192   
 193  0 public void inASharedvardef(ASharedvardef node) {
 194  0 final Capability capability = (Capability) container.peekFromStack(TopEntity.class,
 195    Capability.class);
 196  0 if (node != null) {
 197  0 node.apply(new DepthFirstAdapter() {
 198  0 public void caseTVariable(TVariable var) {
 199  0 String str = var.getText().trim();
 200  0 try {
 201  0 capability.addSharedVariable(leFactory.createVariable(str));
 202    }
 203    catch (InvalidModelException ime) {
 204  0 throw new WrappedInvalidModelException(ime);
 205    }
 206    }
 207    } // close anonymous class
 208    );
 209    }
 210    }
 211   
 212  0 public void inAInterface(AInterface node) {
 213  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(),node.getTInterface());
 214  0 node.getId().apply(container.getNodeHandler(PId.class));
 215  0 IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 216  0 Interface iface = factory.createInterface(iri);
 217   
 218    // find if it's a child of WebService or Goal
 219  0 Stack entities = container.getStack(Entity.class);
 220  0 for (int i = entities.size() - 1; i >= 0; i--) {
 221  0 Entity entity = (Entity) entities.elementAt(i);
 222  0 if (entity instanceof WebService) {
 223  0 ((WebService) entity).addInterface(iface);
 224  0 break;
 225    }
 226  0 else if (entity instanceof Goal) {
 227  0 ((Goal) entity).addInterface(iface);
 228  0 break;
 229    }
 230    }
 231   
 232  0 copyNSAndAddToStacks(iface);
 233    }
 234   
 235  0 public void outAInterface(AInterface node) {
 236  0 container.popFromStack(Entity.class, Interface.class);
 237    }
 238   
 239  0 public void inAOrchestration(AOrchestration node) {
 240  0 Identifier id = null;
 241  0 if (node.getId() != null) {
 242  0 node.getId().apply(container.getNodeHandler(PId.class));
 243  0 id = (Identifier) container.popFromStack(Identifier.class, Identifier.class);
 244    }
 245    else {
 246  0 id = factory.createAnonymousID();
 247    }
 248  0 Interface iface = (Interface) container.peekFromStack(TopEntity.class, Interface.class);
 249  0 Orchestration orchestration = iface.createOrchestration(id);
 250  0 container.getStack(Orchestration.class).push(orchestration);
 251  0 container.getStack(Entity.class).push(orchestration);
 252    }
 253   
 254  0 public void outAOrchestration(AOrchestration node) {
 255  0 container.popFromStack(Orchestration.class, Orchestration.class);
 256  0 container.popFromStack(Entity.class, Orchestration.class);
 257    }
 258   
 259  0 public void inAChoreography(AChoreography node) {
 260  0 Identifier id = null;
 261  0 if (node.getId() != null) {
 262  0 node.getId().apply(container.getNodeHandler(PId.class));
 263  0 id = (Identifier) container.popFromStack(Identifier.class, Identifier.class);
 264    }
 265    else {
 266  0 id = factory.createAnonymousID();
 267    }
 268  0 Interface iface = (Interface) container.peekFromStack(TopEntity.class, Interface.class);
 269  0 Choreography choreography = iface.createChoreography(id);
 270  0 container.getStack(Choreography.class).push(choreography);
 271  0 container.getStack(Entity.class).push(choreography);
 272    }
 273   
 274  0 public void outAChoreography(AChoreography node) {
 275  0 container.popFromStack(Choreography.class, Choreography.class);
 276  0 container.popFromStack(Entity.class, Choreography.class);
 277    }
 278   
 279  0 private void copyNSAndAddToStacks(TopEntity entity) {
 280  0 TopEntityAnalysis.addNamespaceAndVariant(entity, container.getStack(Namespace.class),
 281    container.getStack(AWsmlvariant.class));
 282  0 container.getStack(TopEntity.class).push(entity);
 283  0 container.getStack(Entity.class).push(entity);
 284    }
 285   
 286  0 public static void copyNFP(Entity oldE, Entity newE) {
 287  0 for (Iterator i = oldE.listNFPValues().entrySet().iterator(); i.hasNext();) {
 288  0 Entry entry = (Entry) i.next();
 289  0 Iterator j = ((Set) entry.getValue()).iterator();
 290  0 try {
 291  0 while (j.hasNext()) {
 292  0 Object value = j.next();
 293  0 if (value instanceof Identifier) {
 294  0 newE.addNFPValue((IRI)entry.getKey(), (Identifier) value);
 295    }
 296  0 else if (value instanceof Value) {
 297  0 newE.addNFPValue((IRI)entry.getKey(), (Value) value);
 298    }
 299    }
 300    }
 301    catch (InvalidModelException ex) {
 302  0 throw new WrappedInvalidModelException(ex);
 303    }
 304    }
 305    }
 306    }
 307   
 308    /*
 309    * $Log$
 310    * Revision 1.11 2006/12/04 11:17:19 vassil_momtchev
 311    * wsmo4j parser always processe the choreography/orchestration; the extended parser will swap the implementation with the appropriate
 312    *
 313    * Revision 1.10 2006/10/25 07:05:49 vassil_momtchev
 314    * adapted to handle the node from the new grammar
 315    *
 316    * Revision 1.9 2006/06/21 07:46:29 vassil_momtchev
 317    * createVariable(String) method moved from WsmoFactory to LogicalExpressionFactory interface
 318    *
 319    * Revision 1.8 2006/04/24 08:04:58 holgerlausen
 320    * improved error handling in case of topentities without identifier
 321    * moved thomas unit test to "open" package, since it does not break expected behavior, but just document some derivations from the spec
 322    *
 323    * Revision 1.7 2006/04/11 16:06:58 holgerlausen
 324    * addressed RFE 1468651 ( http://sourceforge.net/tracker/index.php?func=detail&aid=1468651&group_id=113501&atid=665349)
 325    * currently the default behaviour of the parser is still as before
 326    *
 327    * Revision 1.6 2006/02/13 09:48:52 vassil_momtchev
 328    * the code to handle the topentities identifier validity refactored
 329    *
 330    * Revision 1.5 2006/02/10 14:37:25 vassil_momtchev
 331    * parser addapted to the grammar changes; unused class variables removed;
 332    *
 333    * Revision 1.4 2005/12/21 14:40:38 vassil_momtchev
 334    * choreography orchestration parsing added
 335    *
 336    * Revision 1.3 2005/12/07 09:12:10 vassil_momtchev
 337    * refactored the ServiceDescription check in inACapability method
 338    *
 339    * Revision 1.2 2005/12/07 09:03:54 vassil_momtchev
 340    * capabality was not assigned to the webservice
 341    *
 342    * Revision 1.1 2005/11/28 13:55:26 vassil_momtchev
 343    * AST analyses
 344    *
 345    */