Coverage Report - org.deri.wsmo4j.choreography.signature.StateSignatureRI
 
Classes in this File Line Coverage Branch Coverage Complexity
StateSignatureRI
0%
0/103
0%
0/46
0
 
 1  
 /*
 2  
  wsmo4j extension - a Choreography API and Reference Implementation
 3  
 
 4  
  Copyright (c) 2005, 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  
 
 19  
 package org.deri.wsmo4j.choreography.signature;
 20  
 
 21  
 import java.util.Collections;
 22  
 import java.util.HashSet;
 23  
 import java.util.Iterator;
 24  
 import java.util.LinkedHashMap;
 25  
 import java.util.LinkedHashSet;
 26  
 import java.util.Set;
 27  
 
 28  
 import org.omwg.ontology.Ontology;
 29  
 import org.wsmo.common.IRI;
 30  
 import org.wsmo.common.Identifier;
 31  
 import org.wsmo.mediator.OOMediator;
 32  
 import org.wsmo.service.signature.*;
 33  
 
 34  
 import com.ontotext.wsmo4j.common.EntityImpl;
 35  
 
 36  
 /**
 37  
  * Reference implementation for the State Signature.
 38  
  * 
 39  
  * <pre>
 40  
  *    Created on Jul 26, 2005
 41  
  *    Committed by $Author: vassil_momtchev $
 42  
  *    $Source$
 43  
  * </pre>
 44  
  * 
 45  
  * @author Thomas Haselwanter
 46  
  * @author James Scicluna
 47  
  * 
 48  
  * @version $Revision: 1844 $ $Date: 2006-10-24 17:11:48 +0300 (Tue, 24 Oct 2006) $
 49  
  */
 50  
 public class StateSignatureRI extends EntityImpl implements StateSignature {
 51  
 
 52  
     /**
 53  
      * @uml.property   name="inModeDefinition"
 54  
      * @uml.associationEnd   multiplicity="(0 -1)" elementType="org.wsmo.service.signature.In"
 55  
      */
 56  
     protected Set<In> inModeDefinition;
 57  
 
 58  
     /**
 59  
      * @uml.property   name="outModeDefinition"
 60  
      * @uml.associationEnd   multiplicity="(0 -1)" elementType="org.wsmo.service.signature.Out"
 61  
      */
 62  
     protected Set<Out> outModeDefinition;
 63  
 
 64  
     /**
 65  
      * @uml.property   name="sharedModeDefinition"
 66  
      * @uml.associationEnd   multiplicity="(0 -1)" elementType="org.wsmo.service.signature.Shared"
 67  
      */
 68  
     protected Set<Shared> sharedModeDefinition;
 69  
 
 70  
     /**
 71  
      * @uml.property   name="staticModeDefinition"
 72  
      * @uml.associationEnd   multiplicity="(0 -1)" elementType="org.wsmo.service.signature.Static"
 73  
      */
 74  
     protected Set<Static> staticModeDefinition;
 75  
 
 76  
     /**
 77  
      * @uml.property   name="controlledModeDefinition"
 78  
      * @uml.associationEnd   multiplicity="(0 -1)" elementType="org.wsmo.service.signature.Controlled"
 79  
      */
 80  
     protected Set<Controlled> controlledModeDefinition;
 81  
 
 82  
     private LinkedHashMap<Identifier, Ontology> ontologies;
 83  
     
 84  
     private LinkedHashMap<Identifier, OOMediator> mediators;
 85  
 
 86  
     /**
 87  
      * Constructor initializing a state signature with an IRI and empty sets of
 88  
      * modes
 89  
      * 
 90  
      * @param id
 91  
      *            An IRI object defining the identifier of the state signature
 92  
      */
 93  
     public StateSignatureRI(Identifier id) {
 94  0
         this(id, new HashSet<In>(), new HashSet<Out>(), new HashSet<Shared>(),
 95  
                 new HashSet<Static>(), new HashSet<Controlled>());
 96  0
         this.mediators = new LinkedHashMap<Identifier,OOMediator>();
 97  0
     }
 98  
 
 99  
     /**
 100  
      * Constructor initializing a state signature with an IRI and a set of modes
 101  
      * 
 102  
      * @param id
 103  
      *            An IRI object defining the identifier of the state signature
 104  
      * @param modes
 105  
      *            A Set of Mode objects which define the modes in the state
 106  
      *            signature.
 107  
      */
 108  
     public StateSignatureRI(Identifier id, Set<Mode> modes) {
 109  0
         this(id, new HashSet<In>(), new HashSet<Out>(), new HashSet<Shared>(),
 110  
                 new HashSet<Static>(), new HashSet<Controlled>());
 111  0
         for (Mode mode : modes)
 112  0
             addMode(mode);
 113  0
     }
 114  
 
 115  
     /**
 116  
      * Constructor initializing a state signature with an IRI and 5 sets of the
 117  
      * specific types of modes
 118  
      * 
 119  
      * @param id
 120  
      *            An IRI object defining the identifier of the state signature
 121  
      * @param inModeDefinition
 122  
      *            A Set of In mode definitions
 123  
      * @param outModeDefinition
 124  
      *            A Set of Out mode definitions
 125  
      * @param sharedModeDefinition
 126  
      *            A Set of Shared mode definitions
 127  
      * @param staticModeDefinition
 128  
      *            A Set of Static mode definitions
 129  
      * @param controlledModeDefinition
 130  
      *            A Set of Controlled mode definitions
 131  
      */
 132  
     public StateSignatureRI(Identifier id, Set<In> inModeDefinition, Set<Out> outModeDefinition,
 133  
             Set<Shared> sharedModeDefinition, Set<Static> staticModeDefinition,
 134  
             Set<Controlled> controlledModeDefinition) {
 135  0
         super(id);
 136  0
         if ((this.inModeDefinition = inModeDefinition) == null)
 137  0
             this.inModeDefinition = new HashSet<In>();
 138  0
         if ((this.outModeDefinition = outModeDefinition) == null)
 139  0
             this.outModeDefinition = new HashSet<Out>();
 140  0
         if ((this.sharedModeDefinition = sharedModeDefinition) == null)
 141  0
             this.sharedModeDefinition = new HashSet<Shared>();
 142  0
         if ((this.staticModeDefinition = staticModeDefinition) == null)
 143  0
             this.staticModeDefinition = new HashSet<Static>();
 144  0
         if ((this.controlledModeDefinition = controlledModeDefinition) == null)
 145  0
             this.controlledModeDefinition = new HashSet<Controlled>();
 146  0
         this.ontologies = new LinkedHashMap<Identifier, Ontology>();
 147  
         // this.setupModeSet();
 148  0
     }
 149  
 
 150  
     /*
 151  
      * (non-Javadoc)
 152  
      * 
 153  
      * @see org.wsmo.service.choreography.signature.StateSignature#listInModes()
 154  
      */
 155  
     public Set<In> listInModes() {
 156  0
         return Collections.unmodifiableSet(inModeDefinition);
 157  
     }
 158  
 
 159  
     /*
 160  
      * (non-Javadoc)
 161  
      * 
 162  
      * @see org.wsmo.service.choreography.signature.StateSignature#listOutModes()
 163  
      */
 164  
     public Set<Out> listOutModes() {
 165  0
         return Collections.unmodifiableSet(outModeDefinition);
 166  
     }
 167  
 
 168  
     /*
 169  
      * (non-Javadoc)
 170  
      * 
 171  
      * @see org.wsmo.service.choreography.signature.StateSignature#listSharedModes()
 172  
      */
 173  
     public Set<Shared> listSharedModes() {
 174  0
         return Collections.unmodifiableSet(sharedModeDefinition);
 175  
     }
 176  
 
 177  
     /*
 178  
      * (non-Javadoc)
 179  
      * 
 180  
      * @see org.wsmo.service.choreography.signature.StateSignature#listStaticModes()
 181  
      */
 182  
     public Set<Static> listStaticModes() {
 183  0
         return Collections.unmodifiableSet(staticModeDefinition);
 184  
     }
 185  
 
 186  
     /*
 187  
      * (non-Javadoc)
 188  
      * 
 189  
      * @see org.wsmo.service.choreography.signature.StateSignature#listControlledModes()
 190  
      */
 191  
     public Set<Controlled> listControlledModes() {
 192  0
         return Collections.unmodifiableSet(controlledModeDefinition);
 193  
     }
 194  
 
 195  
     /**
 196  
      * Adds a mode of type In
 197  
      * 
 198  
      * @param mode
 199  
      *            An In mode object
 200  
      */
 201  
     public void add(In mode) {
 202  0
         inModeDefinition.add(mode);
 203  0
     }
 204  
 
 205  
     /**
 206  
      * Removes an In mode from the state signature
 207  
      * 
 208  
      * @param mode
 209  
      *            An In mode object to be removed
 210  
      */
 211  
     public void remove(In mode) {
 212  0
         inModeDefinition.remove(mode);
 213  0
     }
 214  
 
 215  
     /**
 216  
      * Adds a mode of type Out
 217  
      * 
 218  
      * @param mode
 219  
      *            An Out mode object
 220  
      */
 221  
     public void add(Out mode) {
 222  0
         outModeDefinition.add(mode);
 223  0
     }
 224  
 
 225  
     /**
 226  
      * Removes an Out mode from the state signature
 227  
      * 
 228  
      * @param mode
 229  
      *            An Out mode object to be removed
 230  
      */
 231  
     public void remove(Out mode) {
 232  0
         outModeDefinition.remove(mode);
 233  0
     }
 234  
 
 235  
     /**
 236  
      * Adds a mode of type Shared
 237  
      * 
 238  
      * @param mode
 239  
      *            An Shared mode object
 240  
      */
 241  
     public void add(Shared mode) {
 242  0
         sharedModeDefinition.add(mode);
 243  0
     }
 244  
 
 245  
     /**
 246  
      * Removes an Out mode from the state signature
 247  
      * 
 248  
      * @param mode
 249  
      *            An Out mode object to be removed
 250  
      */
 251  
     public void remove(Shared mode) {
 252  0
         sharedModeDefinition.remove(mode);
 253  0
     }
 254  
 
 255  
     /**
 256  
      * Adds a mode of type Static
 257  
      * 
 258  
      * @param mode
 259  
      *            An Static mode object
 260  
      */
 261  
     public void add(Static mode) {
 262  0
         staticModeDefinition.add(mode);
 263  0
     }
 264  
 
 265  
     /**
 266  
      * Removes an Out mode from the state signature
 267  
      * 
 268  
      * @param mode
 269  
      *            An Out mode object to be removed
 270  
      */
 271  
     public void remove(Static mode) {
 272  0
         staticModeDefinition.remove(mode);
 273  0
     }
 274  
 
 275  
     /**
 276  
      * Adds a mode of type Controlled
 277  
      * 
 278  
      * @param mode
 279  
      *            An Controlled mode object
 280  
      */
 281  
     public void add(Controlled mode) {
 282  0
         controlledModeDefinition.add(mode);
 283  0
     }
 284  
 
 285  
     /**
 286  
      * Removes an Out mode from the state signature
 287  
      * 
 288  
      * @param mode
 289  
      *            An Out mode object to be removed
 290  
      */
 291  
     public void remove(Controlled mode) {
 292  0
         controlledModeDefinition.remove(mode);
 293  0
     }
 294  
 
 295  
     /*
 296  
      * (non-Javadoc)
 297  
      * 
 298  
      * @see org.wsmo.service.choreography.signature.StateSignature#add(org.wsmo.service.choreography.signature.Mode)
 299  
      */
 300  
     public void addMode(Mode mode) {
 301  0
         if (mode instanceof In)
 302  0
             add((In) mode);
 303  0
         if (mode instanceof Out)
 304  0
             add((Out) mode);
 305  0
         if (mode instanceof Shared)
 306  0
             add((Shared) mode);
 307  0
         if (mode instanceof Static)
 308  0
             add((Static) mode);
 309  0
         if (mode instanceof Controlled)
 310  0
             add((Controlled) mode);
 311  0
     }
 312  
 
 313  
     /*
 314  
      * (non-Javadoc)
 315  
      * 
 316  
      * @see org.wsmo.service.choreography.signature.StateSignature#removeMode(org.wsmo.service.choreography.signature.Mode)
 317  
      */
 318  
     public void removeMode(Mode mode) {
 319  0
         if (mode instanceof In)
 320  0
             remove((In) mode);
 321  0
         if (mode instanceof Out)
 322  0
             remove((Out) mode);
 323  0
         if (mode instanceof Shared)
 324  0
             remove((Shared) mode);
 325  0
         if (mode instanceof Static)
 326  0
             remove((Static) mode);
 327  0
         if (mode instanceof Controlled)
 328  0
             remove((Controlled) mode);
 329  
 
 330  0
     }
 331  
 
 332  
     /**
 333  
      * Adds a set of modes to the respective containers
 334  
      * 
 335  
      * @param modes
 336  
      *            A set of Mode objects to be added to the state signature
 337  
      */
 338  
     public void add(Set<Mode> modes) {
 339  0
         for (Mode mode : modes)
 340  0
             addMode(mode);
 341  0
     }
 342  
 
 343  
     /*
 344  
      * (non-Javadoc)
 345  
      * 
 346  
      * @see org.wsmo.service.choreography.signature.StateSignature#addOntology(org.omwg.ontology.Ontology)
 347  
      */
 348  
     public void addOntology(Ontology ontology) {
 349  0
         if (ontology == null) {
 350  0
             throw new IllegalArgumentException();
 351  
         }
 352  0
         ontologies.put(ontology.getIdentifier(), ontology);
 353  0
     }
 354  
 
 355  
     /*
 356  
      * (non-Javadoc)
 357  
      * 
 358  
      * @see org.wsmo.service.choreography.signature.StateSignature#removeOntology(org.wsmo.common.IRI)
 359  
      */
 360  
     public void removeOntology(IRI iri) {
 361  0
         if (iri == null) {
 362  0
             throw new IllegalArgumentException();
 363  
         }
 364  0
         ontologies.remove(iri);
 365  0
     }
 366  
 
 367  
     /*
 368  
      * (non-Javadoc)
 369  
      * 
 370  
      * @see org.wsmo.service.choreography.signature.StateSignature#removeOntology(org.omwg.ontology.Ontology)
 371  
      */
 372  
     public void removeOntology(Ontology ontology) {
 373  0
         if (ontology == null) {
 374  0
             throw new IllegalArgumentException();
 375  
         }
 376  0
         ontologies.remove(ontology.getIdentifier());
 377  0
     }
 378  
 
 379  
     /*
 380  
      * (non-Javadoc)
 381  
      * 
 382  
      * @see org.wsmo.service.choreography.signature.StateSignature#listOntologies()
 383  
      */
 384  
     public Set<Ontology> listOntologies() {
 385  0
         return new LinkedHashSet<Ontology>(ontologies.values());
 386  
     }
 387  
 
 388  
     public void addMediator(OOMediator mediator) {
 389  0
         if (mediator == null) {
 390  0
             throw new IllegalArgumentException();
 391  
         }
 392  0
         mediators.put(mediator.getIdentifier(), mediator);
 393  0
     }
 394  
 
 395  
     public void removeMediator(OOMediator mediator) {
 396  0
         if (mediator == null) {
 397  0
             throw new IllegalArgumentException();
 398  
         }
 399  0
         mediators.remove(mediator.getIdentifier());
 400  0
     }
 401  
 
 402  
     public void removeMediator(IRI iri) {
 403  0
         if (iri == null) {
 404  0
             throw new IllegalArgumentException();
 405  
         }
 406  0
         mediators.remove(iri);
 407  0
     }
 408  
 
 409  
 
 410  
     public Set listMediators() {
 411  0
         return new LinkedHashSet<OOMediator>(mediators.values());
 412  
     }
 413  
 
 414  
     public Iterator<Mode> iterator() {
 415  0
         HashSet<Mode> allModes = new HashSet<Mode>();
 416  0
         allModes.addAll(this.inModeDefinition);
 417  0
         allModes.addAll(this.outModeDefinition);
 418  0
         allModes.addAll(this.sharedModeDefinition);
 419  0
         allModes.addAll(this.staticModeDefinition);
 420  0
         allModes.addAll(this.controlledModeDefinition);
 421  0
         return allModes.iterator();
 422  
     }
 423  
 }