Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 292   Methods: 5
NCLOC: 205   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClearTopEntity.java 0% 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3   
 4    Copyright (c) 2006, University of Innsbruck, Austria
 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    package org.deri.wsmo4j.common;
 19   
 20    import java.util.*;
 21   
 22    import org.omwg.logicalexpression.*;
 23    import org.omwg.ontology.*;
 24    import org.wsmo.common.*;
 25    import org.wsmo.common.exception.*;
 26    import org.wsmo.mediator.*;
 27    import org.wsmo.service.*;
 28   
 29    /**
 30    * This utility class cleans a given TopEntity from all its
 31    * previous definitions (if any).
 32    *
 33    * <pre>
 34    * Created on 10.04.2006
 35    * Committed by $Author$
 36    * $Source$,
 37    * </pre>
 38    *
 39    * @author Holger Lausen (holger.lausen@deri.org)
 40    *
 41    * @version $Revision$ $Date$
 42    */
 43    public class ClearTopEntity {
 44   
 45   
 46  0 public static void clearTopEntity(Mediator m) throws SynchronisationException, InvalidModelException{
 47  0 if (m == null){
 48  0 return;
 49    }
 50  0 clearCommonElements(m);
 51  0 if (m.listSources()!=null){
 52  0 for (Iterator <IRI> mediatorI = new ArrayList <IRI>(m.listSources()).iterator(); mediatorI.hasNext();){
 53  0 m.removeSource(mediatorI.next());
 54    }
 55    }
 56  0 m.setTarget(null);
 57  0 m.setMediationService(null);
 58    }
 59   
 60  0 public static void clearTopEntity(ServiceDescription s) throws SynchronisationException, InvalidModelException{
 61  0 if (s == null){
 62  0 return;
 63    }
 64  0 clearCommonElements(s);
 65  0 if (s.listInterfaces() != null){
 66  0 for (Iterator <Interface> interfaceI = new ArrayList <Interface> (s.listInterfaces()).iterator(); interfaceI.hasNext();){
 67  0 Interface i = interfaceI.next();
 68  0 clearNfp(i.getChoreography());
 69  0 clearNfp(i.getOrchestration());
 70  0 i.setChoreography(null);
 71  0 i.setOrchestration(null);
 72   
 73  0 s.removeInterface(i);
 74    }
 75    }
 76  0 Capability cap = s.getCapability();
 77  0 if (cap==null){
 78  0 return;
 79    }
 80  0 clearCommonElements(cap);
 81    //shared Variables
 82  0 if (cap.listSharedVariables()!=null){
 83  0 for (Iterator <Variable> varI = new ArrayList <Variable>(cap.listSharedVariables()).iterator();varI.hasNext();){
 84  0 cap.removeSharedVariable(varI.next());
 85    }
 86    }
 87    //assumption
 88  0 if (cap.listAssumptions()!=null){
 89  0 for (Iterator <Axiom> i = new ArrayList <Axiom>(cap.listAssumptions()).iterator();i.hasNext();){
 90  0 Axiom a = i.next();
 91  0 clearNfp(a);
 92  0 cap.removeAssumption(a);
 93    }
 94    }
 95  0 if (cap.listEffects()!=null){
 96  0 for (Iterator <Axiom> i = new ArrayList <Axiom>(cap.listEffects()).iterator();i.hasNext();){
 97  0 Axiom a = i.next();
 98  0 clearNfp(a);
 99  0 cap.removeEffect(a);
 100    }
 101    }
 102  0 if (cap.listPostConditions()!=null){
 103  0 for (Iterator <Axiom> i = new ArrayList <Axiom>(cap.listPostConditions()).iterator();i.hasNext();){
 104  0 Axiom a = i.next();
 105  0 clearNfp(a);
 106  0 cap.removePostCondition(a);
 107    }
 108    }
 109  0 if (cap.listPreConditions()!=null){
 110  0 for (Iterator <Axiom> i = new ArrayList <Axiom>(cap.listPreConditions()).iterator();i.hasNext();){
 111  0 Axiom a = i.next();
 112  0 clearNfp(a);
 113  0 cap.removePreCondition(a);
 114    }
 115    }
 116  0 s.setCapability(null);
 117    }
 118   
 119  0 public static void clearTopEntity(Ontology ont) throws SynchronisationException, InvalidModelException{
 120  0 if (ont == null){
 121  0 return;
 122    }
 123    //clear concepts
 124  0 if (ont.listConcepts()!=null){
 125  0 for (Iterator <Concept> conceptI = new ArrayList <Concept>(ont.listConcepts()).iterator(); conceptI.hasNext(); ){
 126  0 Concept concept = conceptI.next();
 127  0 if (concept.listSuperConcepts()!=null){
 128  0 for (Iterator <Concept> superI = new ArrayList <Concept>(concept.listSuperConcepts()).iterator(); superI.hasNext(); ){
 129  0 concept.removeSuperConcept(superI.next());
 130    }
 131    }
 132  0 if (concept.listAttributes()!=null){
 133  0 for (Iterator <Attribute> attrI = new ArrayList <Attribute>(concept.listAttributes()).iterator(); attrI.hasNext(); ){
 134  0 Attribute attr = attrI.next();
 135  0 attr.setConstraining(false);
 136  0 attr.setInverseOf(null);
 137  0 attr.setReflexive(false);
 138  0 attr.setSymmetric(false);
 139  0 attr.setReflexive(false);
 140  0 attr.setTransitive(false);
 141  0 attr.setMaxCardinality(Integer.MAX_VALUE);
 142  0 attr.setMinCardinality(0);
 143  0 for (Iterator <Type> typesI = new ArrayList <Type>(attr.listTypes()).iterator(); typesI.hasNext();){
 144  0 attr.removeType(typesI.next());
 145    }
 146  0 concept.removeAttribute(attr);
 147  0 clearNfp(attr);
 148    }
 149    }
 150  0 clearNfp(concept);
 151  0 concept.setOntology(null);
 152    }
 153    }
 154    //clear instances
 155  0 if (ont.listInstances()!=null){
 156  0 for (Iterator <Instance> instanceI = new ArrayList <Instance>(ont.listInstances()).iterator(); instanceI.hasNext();){
 157  0 Instance instance = instanceI.next();
 158  0 if (instance.listConcepts()!=null){
 159  0 for (Iterator <Concept> memberOfI = new ArrayList <Concept>(instance.listConcepts()).iterator(); memberOfI.hasNext();){
 160  0 instance.removeConcept(memberOfI.next());
 161    }
 162    }
 163  0 if (instance.listAttributeValues()!=null){
 164  0 for (Iterator <Identifier> attributeI = new ArrayList <Identifier> (instance.listAttributeValues().keySet()).iterator(); attributeI.hasNext();){
 165  0 instance.removeAttributeValues(attributeI.next());
 166    }
 167    }
 168  0 clearNfp(instance);
 169  0 instance.setOntology(null);
 170    }
 171    }
 172   
 173    //clear RelationInstances
 174  0 if (ont.listRelationInstances()!=null){
 175  0 for (Iterator <RelationInstance> instanceI = new ArrayList <RelationInstance> (ont.listRelationInstances()).iterator();instanceI.hasNext();){
 176  0 RelationInstance instance = instanceI.next();
 177  0 if (instance.listParameterValues()!=null){
 178  0 for (byte i = (byte)(instance.listParameterValues().size()-1); i>=0; i--){
 179  0 instance.setParameterValue(i,null);
 180    }
 181    }
 182  0 clearNfp(instance);
 183  0 instance.setOntology(null);
 184    }
 185    }
 186   
 187    //clear Relations
 188  0 if (ont.listRelations()!=null){
 189  0 for (Iterator <Relation> relI = new ArrayList <Relation> (ont.listRelations()).iterator();relI.hasNext();){
 190  0 Relation rel = relI.next();
 191  0 if (rel.listParameters()!=null){
 192  0 for (byte i = (byte)(rel.listParameters().size()-1); i>=0; i--){
 193  0 rel.removeParameter(i);
 194    }
 195    }
 196  0 if (rel.listSuperRelations()!=null){
 197  0 for (Iterator <Relation> superI = new ArrayList <Relation> (rel.listSuperRelations()).iterator();superI.hasNext();){
 198  0 rel.removeSuperRelation(superI.next());
 199    }
 200    }
 201  0 if (rel.listRelationInstances()!= null) {
 202  0 for (Iterator <RelationInstance> relInstI = new ArrayList <RelationInstance> (rel.listRelationInstances()).iterator();relInstI.hasNext();) {
 203  0 rel.removeRelationInstance(relInstI.next());
 204    }
 205    }
 206  0 clearNfp(rel);
 207  0 rel.setOntology(null);
 208    }
 209    }
 210   
 211    //clearAxioms
 212  0 if(ont.listAxioms()!=null){
 213  0 for (Iterator <Axiom> axiomI = new ArrayList <Axiom> (ont.listAxioms()).iterator();axiomI.hasNext();){
 214  0 Axiom a = axiomI.next();
 215  0 for (Iterator <LogicalExpression> defI = new ArrayList <LogicalExpression> (a.listDefinitions()).iterator(); defI.hasNext();){
 216  0 a.removeDefinition(defI.next());
 217    }
 218  0 clearNfp(a);
 219  0 a.setOntology(null);
 220    }
 221    }
 222   
 223   
 224  0 clearCommonElements(ont);
 225    }
 226   
 227  0 private static void clearNfp(Entity e) throws SynchronisationException, InvalidModelException{
 228  0 if (e!=null && e.listNFPValues()!=null){
 229  0 for (Iterator <IRI> nfpI = new ArrayList <IRI> (e.listNFPValues().keySet()).iterator(); nfpI.hasNext(); ){
 230  0 e.removeNFP(nfpI.next());
 231    }
 232    }
 233   
 234    }
 235   
 236  0 private static void clearCommonElements(TopEntity te) throws SynchronisationException, InvalidModelException{
 237    //clear importsMediator
 238  0 if (te==null){
 239  0 return;
 240    }
 241  0 if (te.listMediators()!=null){
 242  0 for (Iterator <IRI> medI = new ArrayList <IRI> (te.listMediators()).iterator(); medI.hasNext();){
 243  0 te.removeMediator(medI.next());
 244    }
 245    }
 246    //clear namespace
 247  0 if (te.listNamespaces()!=null){
 248  0 for (Iterator <Namespace> nsI = new ArrayList <Namespace>(te.listNamespaces()).iterator(); nsI.hasNext();){
 249  0 te.removeNamespace(nsI.next());
 250    }
 251    }
 252    //clear importsOntology
 253  0 if(te.listOntologies()!=null){
 254  0 for (Iterator <Ontology> ontI = new ArrayList <Ontology> (te.listOntologies()).iterator(); ontI.hasNext();){
 255  0 te.removeOntology(ontI.next());
 256    }
 257    }
 258  0 te.setWsmlVariant(null);
 259  0 te.setDefaultNamespace((IRI)null);
 260  0 clearNfp(te);
 261    }
 262   
 263   
 264    }
 265   
 266   
 267    /*
 268    *$Log$
 269    *Revision 1.7 2007/04/02 12:13:28 morcen
 270    *Generics support added to wsmo-api, wsmo4j and wsmo-test
 271    *
 272    *Revision 1.6 2007/02/13 13:01:56 alex_simov
 273    *bugfix: cleaning webservices/goals did not remove the interfaces
 274    *
 275    *Revision 1.5 2006/12/04 09:01:59 alex_simov
 276    *bugfix: ConcurrentModificationException was caused in several FOR loops
 277    * using iterators
 278    *
 279    *Revision 1.4 2006/08/21 14:46:22 nathaliest
 280    *fixed invalid model exception
 281    *
 282    *Revision 1.3 2006/08/10 07:36:51 nathaliest
 283    *completed clearing of ontology objects
 284    *
 285    *Revision 1.2 2006/04/27 10:34:10 holgerlausen
 286    *fixed potential null pointer exceptions
 287    *
 288    *Revision 1.1 2006/04/11 16:06:59 holgerlausen
 289    *addressed RFE 1468651 ( http://sourceforge.net/tracker/index.php?func=detail&aid=1468651&group_id=113501&atid=665349)
 290    *currently the default behaviour of the parser is still as before
 291    *
 292    */