Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 299   Methods: 19
NCLOC: 187   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MediatorAnalysis.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   
 31    import org.deri.wsmo4j.common.*;
 32    import org.deri.wsmo4j.io.parser.*;
 33    import org.wsmo.common.*;
 34    import org.wsmo.common.exception.*;
 35    import org.wsmo.factory.*;
 36    import org.wsmo.mediator.*;
 37    import org.wsmo.wsml.*;
 38    import org.wsmo.wsml.compiler.node.*;
 39   
 40    import com.ontotext.wsmo4j.parser.*;
 41   
 42    public class MediatorAnalysis extends ASTAnalysis {
 43   
 44    private WsmoFactory factory;
 45   
 46    private ASTAnalysisContainer container;
 47   
 48    private boolean cleanOnParse=false;
 49   
 50  0 public MediatorAnalysis(ASTAnalysisContainer container, WsmoFactory factory) {
 51  0 if (container == null || factory == null) {
 52  0 throw new IllegalArgumentException();
 53    }
 54  0 this.factory = factory;
 55  0 this.container = container;
 56   
 57    // register the handled nodes
 58  0 container.registerNodeHandler(AOomediator.class, this);
 59  0 container.registerNodeHandler(AGgmediator.class, this);
 60  0 container.registerNodeHandler(AWgmediator.class, this);
 61  0 container.registerNodeHandler(AWwmediator.class, this);
 62  0 container.registerNodeHandler(ASource.class, this);
 63  0 container.registerNodeHandler(AMsources.class, this);
 64  0 container.registerNodeHandler(ATarget.class, this);
 65  0 container.registerNodeHandler(AUseService.class, this);
 66    }
 67   
 68  0 public void setCleanOnParse(boolean cleanOnParse){
 69  0 this.cleanOnParse=cleanOnParse;
 70    }
 71   
 72  0 private void cleanMediator(Mediator m){
 73    //clean previous contents of this mediator:
 74  0 try {
 75  0 ClearTopEntity.clearTopEntity(m);
 76    }
 77    catch (SynchronisationException e) {
 78    // should never happen
 79  0 throw new RuntimeException("Error During Cleaning TopEntity from previous defintions",e);
 80    }
 81    catch (InvalidModelException e) {
 82    // should never happen
 83  0 throw new RuntimeException("Error During Cleaning TopEntity from previous defintions",e);
 84    }
 85   
 86    }
 87   
 88  0 public void inAOomediator(AOomediator node) {
 89  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(),node.getTOomediator());
 90  0 node.getId().apply(container.getNodeHandler(PId.class));
 91  0 IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 92  0 Mediator mediator = factory.createOOMediator(iri);
 93  0 if (cleanOnParse){
 94  0 cleanMediator(mediator);
 95    }
 96  0 container.getStack(Entity.class).push(mediator);
 97  0 container.getStack(TopEntity.class).push(mediator);
 98   
 99  0 TopEntityAnalysis.addNamespaceAndVariant(mediator, container.getStack(Namespace.class),
 100    container.getStack(AWsmlvariant.class));
 101   
 102    }
 103   
 104  0 public void inAGgmediator(AGgmediator node) {
 105  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(),node.getTGgmediator());
 106  0 node.getId().apply(container.getNodeHandler(PId.class));
 107  0 IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 108  0 Mediator mediator = factory.createGGMediator(iri);
 109  0 if (cleanOnParse){
 110  0 cleanMediator(mediator);
 111    }
 112  0 container.getStack(Entity.class).push(mediator);
 113  0 container.getStack(TopEntity.class).push(mediator);
 114   
 115  0 TopEntityAnalysis.addNamespaceAndVariant(mediator, container.getStack(Namespace.class),
 116    container.getStack(AWsmlvariant.class));
 117    }
 118   
 119  0 public void inAWgmediator(AWgmediator node) {
 120  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(),node.getTWgmediator());
 121  0 node.getId().apply(container.getNodeHandler(PId.class));
 122  0 IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 123  0 Mediator mediator = factory.createWGMediator(iri);
 124  0 if (cleanOnParse){
 125  0 cleanMediator(mediator);
 126    }
 127  0 container.getStack(Entity.class).push(mediator);
 128  0 container.getStack(TopEntity.class).push(mediator);
 129   
 130  0 TopEntityAnalysis.addNamespaceAndVariant(mediator, container.getStack(Namespace.class),
 131    container.getStack(AWsmlvariant.class));
 132    }
 133   
 134  0 public void inAWwmediator(AWwmediator node) {
 135  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(),node.getTWwmediator());
 136  0 node.getId().apply(container.getNodeHandler(PId.class));
 137  0 IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 138  0 Mediator mediator = factory.createWWMediator(iri);
 139  0 if (cleanOnParse){
 140  0 cleanMediator(mediator);
 141    }
 142  0 container.getStack(Entity.class).push(mediator);
 143  0 container.getStack(TopEntity.class).push(mediator);
 144   
 145  0 TopEntityAnalysis.addNamespaceAndVariant(mediator, container.getStack(Namespace.class),
 146    container.getStack(AWsmlvariant.class));
 147    }
 148   
 149  0 public void outAOomediator(AOomediator node) {
 150  0 container.popFromStack(Entity.class, OOMediator.class);
 151    }
 152   
 153  0 public void outAGgmediator(AGgmediator node) {
 154  0 container.popFromStack(Entity.class, GGMediator.class);
 155    }
 156   
 157  0 public void outAWgmediator(AWgmediator node) {
 158  0 container.popFromStack(Entity.class, WGMediator.class);
 159    }
 160   
 161  0 public void outAWwmediator(AWwmediator node) {
 162  0 container.popFromStack(Entity.class, WWMediator.class);
 163    }
 164   
 165  0 public void inASource(ASource node) {
 166  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(),node.getTSource());
 167    }
 168   
 169  0 public void outASource(ASource node) {
 170  0 if (container.getStack(TopEntity.class).peek() instanceof Mediator == false) {
 171    // if it's unresolved ppMediator ignore it
 172  0 container.popFromStack(Identifier.class, IRI.class);
 173  0 return;
 174    }
 175  0 Mediator mediator = (Mediator) container.peekFromStack(TopEntity.class, Mediator.class);
 176  0 IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 177  0 try {
 178  0 mediator.addSource(iri);
 179    }
 180    catch (InvalidModelException e) {
 181  0 throw new WrappedInvalidModelException(e);
 182    }
 183    }
 184   
 185    private int idStackSize;
 186   
 187  0 public void inAMsources(AMsources node) {
 188  0 Stack identifierStack = container.getStack(Identifier.class);
 189  0 idStackSize = identifierStack.size();
 190    }
 191   
 192  0 public void outAMsources(AMsources node) {
 193  0 Mediator mediator = (Mediator) container.peekFromStack(TopEntity.class, Mediator.class);
 194  0 Stack identifierStack = container.getStack(Identifier.class);
 195  0 while (identifierStack.size() > idStackSize) {
 196  0 Identifier id = (Identifier) identifierStack.remove(idStackSize);
 197  0 if (id instanceof IRI == false) {
 198  0 ParserException pe = new ParserException("Anonymous sources "
 199    + "are not supported!", null);
 200  0 pe.setExpectedToken("IRI");
 201  0 pe.setFoundToken(id.toString());
 202  0 pe.setErrorLine(node.getLbrace().getLine());
 203  0 pe.setErrorPos(node.getLbrace().getPos());
 204  0 throw new WrappedParsingException(pe);
 205    }
 206   
 207  0 try {
 208  0 mediator.addSource((IRI) id);
 209    }
 210    catch (InvalidModelException e) {
 211  0 throw new WrappedInvalidModelException(e);
 212    }
 213    }
 214    }
 215   
 216  0 public void inATarget(ATarget node) {
 217  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(),node.getTTarget());
 218    }
 219   
 220  0 public void outATarget(ATarget node) {
 221  0 if (container.getStack(TopEntity.class).peek() instanceof Mediator == false) {
 222    // if it's unresolved ppMediator ignore it
 223  0 container.popFromStack(Identifier.class, IRI.class);
 224  0 return;
 225    }
 226  0 Mediator mediator = (Mediator) container.peekFromStack(TopEntity.class, Mediator.class);
 227  0 IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 228   
 229  0 try {
 230  0 mediator.setTarget(iri);
 231    }
 232    catch (InvalidModelException e) {
 233  0 throw new WrappedInvalidModelException(e);
 234    }
 235    }
 236   
 237  0 public void inAUseService(AUseService node) {
 238  0 TopEntityAnalysis.isValidTopEntityIdentifier(node.getId(),node.getTUseservice());
 239    }
 240   
 241  0 public void outAUseService(AUseService node) {
 242  0 if (container.getStack(TopEntity.class).peek() instanceof Mediator == false) {
 243    // if it's unresolved ppMediator ignore it
 244  0 container.popFromStack(Identifier.class, IRI.class);
 245  0 return;
 246    }
 247  0 Mediator mediator = (Mediator) container.peekFromStack(TopEntity.class, Mediator.class);
 248  0 IRI iri = (IRI) container.popFromStack(Identifier.class, IRI.class);
 249   
 250  0 try {
 251  0 mediator.setMediationService(iri);
 252    }
 253    catch (InvalidModelException e) {
 254  0 throw new WrappedInvalidModelException(e);
 255    }
 256    }
 257    }
 258   
 259    /*
 260    * $Log$
 261    * Revision 1.12 2006/10/25 07:06:06 vassil_momtchev
 262    * ignore source, target and useservice when ppmediator are not resolved
 263    *
 264    * Revision 1.11 2006/04/24 08:04:58 holgerlausen
 265    * improved error handling in case of topentities without identifier
 266    * moved thomas unit test to "open" package, since it does not break expected behavior, but just document some derivations from the spec
 267    *
 268    * Revision 1.10 2006/04/11 16:06:58 holgerlausen
 269    * addressed RFE 1468651 ( http://sourceforge.net/tracker/index.php?func=detail&aid=1468651&group_id=113501&atid=665349)
 270    * currently the default behaviour of the parser is still as before
 271    *
 272    * Revision 1.9 2006/03/29 08:51:40 vassil_momtchev
 273    * mediator reference source/target by IRI (changed from TopEntity); mediator reference mediationService by IRI (changed from Identifier); new checks to not allow anonymous id added
 274    *
 275    * Revision 1.8 2006/03/07 13:49:41 alex_simov
 276    * source/target possible types corrected according to D.29.02
 277    *
 278    * Revision 1.7 2006/03/07 13:25:46 vassil_momtchev
 279    * parser probes all allowed top entity types for a mediator source/target
 280    *
 281    * Revision 1.6 2006/02/13 09:48:52 vassil_momtchev
 282    * the code to handle the topentities identifier validity refactored
 283    *
 284    * Revision 1.5 2005/12/07 14:46:10 vassil_momtchev
 285    * change method signature outAUserService -> outAUseService (spell error)
 286    *
 287    * Revision 1.4 2005/12/07 14:14:25 vassil_momtchev
 288    * bugfix; multiple mediator sources are not ignored
 289    *
 290    * Revision 1.3 2005/12/06 15:51:39 alex_simov
 291    * System.out.println's removed
 292    *
 293    * Revision 1.2 2005/12/02 14:33:44 holgerlausen
 294    * fixed parsing bug due to type when overwriting method, fixed but related to multiple source of mediators during reparsing
 295    *
 296    * Revision 1.1 2005/11/28 13:55:26 vassil_momtchev
 297    * AST analyses
 298    *
 299    */