Coverage Report - org.argouml.model.mdr.UseCasesFactoryMDRImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
UseCasesFactoryMDRImpl
2%
3/101
0%
0/40
2.778
 
 1  
 /* $Id: UseCasesFactoryMDRImpl.java 18135 2010-03-22 18:29:43Z bobtarling $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    tfmorris
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2007 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.model.mdr;
 40  
 
 41  
 import java.util.Collection;
 42  
 import java.util.Iterator;
 43  
 
 44  
 import org.argouml.model.UseCasesFactory;
 45  
 import org.omg.uml.behavioralelements.usecases.Actor;
 46  
 import org.omg.uml.behavioralelements.usecases.Extend;
 47  
 import org.omg.uml.behavioralelements.usecases.ExtensionPoint;
 48  
 import org.omg.uml.behavioralelements.usecases.Include;
 49  
 import org.omg.uml.behavioralelements.usecases.UseCase;
 50  
 import org.omg.uml.behavioralelements.usecases.UseCaseInstance;
 51  
 import org.omg.uml.foundation.core.Namespace;
 52  
 
 53  
 /**
 54  
  * Factory to create UML classes for the UML BehaviorialElements::UseCases
 55  
  * package.
 56  
  * <p>
 57  
  * @since ARGO0.19.3
 58  
  * @author Thierry Lach & Bob Tarling
 59  
  * @author Ludovic Ma&icirc;tre
 60  
  * @author Tom Morris
 61  
  */
 62  0
 class UseCasesFactoryMDRImpl extends AbstractUmlModelFactoryMDR
 63  
         implements UseCasesFactory {
 64  
 
 65  
     /**
 66  
      * The model implementation.
 67  
      */
 68  
     private MDRModelImplementation modelImpl;
 69  
 
 70  
     /**
 71  
      * Don't allow instantiation.
 72  
      * 
 73  
      * @param implementation
 74  
      *            To get other helpers and factories.
 75  
      */
 76  900
     UseCasesFactoryMDRImpl(MDRModelImplementation implementation) {
 77  900
         modelImpl = implementation;
 78  900
     }
 79  
 
 80  
 
 81  
     public Extend createExtend() {
 82  0
         Extend myExtend = modelImpl.getUmlPackage().getUseCases().getExtend().
 83  
             createExtend();
 84  0
         super.initialize(myExtend);
 85  0
         return myExtend;
 86  
     }
 87  
 
 88  
 
 89  
     public ExtensionPoint createExtensionPoint() {
 90  0
         ExtensionPoint myExtensionPoint = modelImpl.getUmlPackage().
 91  
             getUseCases().getExtensionPoint().createExtensionPoint();
 92  0
         super.initialize(myExtensionPoint);
 93  0
         return myExtensionPoint;
 94  
     }
 95  
 
 96  
 
 97  
     public Actor createActor() {
 98  0
         Actor myActor = modelImpl.getUmlPackage().getUseCases().getActor().
 99  
             createActor();
 100  0
         super.initialize(myActor);
 101  0
         return myActor;
 102  
     }
 103  
 
 104  
 
 105  
     public Include createInclude() {
 106  0
         Include myInclude = modelImpl.getUmlPackage().getUseCases()
 107  
                 .getInclude().createInclude();
 108  0
         super.initialize(myInclude);
 109  0
         return myInclude;
 110  
     }
 111  
 
 112  
 
 113  
     public UseCase createUseCase() {
 114  0
         UseCase myUseCase = modelImpl.getUmlPackage().getUseCases()
 115  
                 .getUseCase().createUseCase();
 116  0
         super.initialize(myUseCase);
 117  0
         return myUseCase;
 118  
 
 119  
     }
 120  
 
 121  
 
 122  
     public Extend buildExtend(Object abase, Object anextension) {
 123  0
         return buildExtend(abase, anextension, null);
 124  
     }
 125  
 
 126  
 
 127  
     public Extend buildExtend(Object abase, Object anextension, Object apoint) {
 128  0
         UseCase base = (UseCase) abase;
 129  0
         UseCase extension = (UseCase) anextension;
 130  0
         ExtensionPoint point = (ExtensionPoint) apoint;
 131  0
         if (base == null || extension == null) {
 132  0
             throw new IllegalArgumentException("Either the base usecase or "
 133  
                     + "the extension usecase is " + "null");
 134  
         }
 135  0
         if (base.equals(extension)) {
 136  0
             throw new IllegalArgumentException("The base usecase and "
 137  
                     + "the extension usecase must be different");
 138  
         }
 139  0
         if (point != null) {
 140  0
             if (!base.getExtensionPoint().contains(point)) {
 141  0
                 throw new IllegalArgumentException("The extensionpoint is not "
 142  
                         + "part of the base " + "usecase");
 143  
             }
 144  
         } else {
 145  0
             point = buildExtensionPoint(base);
 146  
         }
 147  0
         Extend extend = createExtend();
 148  0
         extend.setBase(base);
 149  0
         extend.setExtension(extension);
 150  0
         extend.getExtensionPoint().add(point);
 151  0
         return extend;
 152  
     }
 153  
 
 154  
 
 155  
     public ExtensionPoint buildExtensionPoint(Object modelElement) {
 156  
         final ExtensionPoint extensionPoint;
 157  0
         if (modelElement instanceof UseCase) {
 158  0
             UseCase useCase = (UseCase) modelElement;
 159  0
             extensionPoint = createExtensionPoint();
 160  0
             extensionPoint.setUseCase(useCase);
 161  0
         } else if (modelElement instanceof Extend) {
 162  0
             Extend extend = (Extend) modelElement;
 163  0
             extensionPoint = createExtensionPoint();
 164  0
             extend.getExtensionPoint().add(extensionPoint);
 165  0
         } else {
 166  0
             throw new IllegalArgumentException("An extension point can only "
 167  
                     + "be built on a use case or an Extend");
 168  
         }
 169  
 
 170  
         // For consistency with attribute and operation, give it a default
 171  
         // name and location
 172  0
         extensionPoint.setName("newEP");
 173  0
         extensionPoint.setLocation("loc");
 174  0
         return extensionPoint;
 175  
     }
 176  
 
 177  
 
 178  
     public Include buildInclude(Object abase, Object anaddition) {
 179  0
         UseCase base = (UseCase) abase;
 180  0
         UseCase addition = (UseCase) anaddition;
 181  0
         Include include = createInclude();
 182  
 
 183  0
         include.setAddition(addition);
 184  0
         include.setBase(base);
 185  
 
 186  
         // Set the namespace to that of the base as first choice, or that of
 187  
         // the addition as second choice.
 188  
 
 189  0
         if (base.getNamespace() != null) {
 190  0
             include.setNamespace(base.getNamespace());
 191  0
         } else if (addition.getNamespace() != null) {
 192  0
             include.setNamespace(addition.getNamespace());
 193  
         }
 194  0
         return include;
 195  
     }
 196  
 
 197  
     /**
 198  
      * Builds an actor in the given namespace.
 199  
      * 
 200  
      * @param ns
 201  
      *            the given namespace
 202  
      * @param model
 203  
      *            model to use for namespace if namespace is null
 204  
      * @return The newly build Actor.
 205  
      */
 206  
     private Actor buildActor(Namespace ns, Object model) {
 207  0
         if (ns == null) {
 208  0
             ns = (Namespace) model;
 209  
         }
 210  0
         Actor actor = createActor();
 211  0
         actor.setNamespace(ns);
 212  0
         actor.setLeaf(false);
 213  0
         actor.setRoot(false);
 214  0
         return actor;
 215  
     }
 216  
 
 217  
 
 218  
     public Actor buildActor(Object actor, Object model) {
 219  0
         if (actor instanceof Actor) {
 220  0
             return buildActor(((Actor) actor).getNamespace(), model);
 221  
         }
 222  0
         throw new IllegalArgumentException();
 223  
     }
 224  
 
 225  
     /**
 226  
      * @param elem
 227  
      *            the UML element to be deleted
 228  
      */
 229  
     void deleteActor(Object elem) {
 230  0
         if (!(elem instanceof Actor)) {
 231  0
             throw new IllegalArgumentException();
 232  
         }
 233  
 
 234  0
     }
 235  
 
 236  
     /**
 237  
      * @param elem
 238  
      *            the UML element to be deleted
 239  
      */
 240  
     void deleteExtend(Object elem) {
 241  0
         if (!(elem instanceof Extend)) {
 242  0
             throw new IllegalArgumentException();
 243  
         }
 244  
 
 245  0
         modelImpl.getUmlHelper().deleteCollection(
 246  
                 ((Extend) elem).getExtensionPoint());
 247  0
     }
 248  
 
 249  
     /**
 250  
      * @param elem
 251  
      *            the UML element to be deleted
 252  
      */
 253  
     void deleteExtensionPoint(Object elem) {
 254  0
         if (!(elem instanceof ExtensionPoint)) {
 255  0
             throw new IllegalArgumentException();
 256  
         }
 257  
         // Delete Extends which have this as their only ExtensionPoint
 258  0
         ExtensionPoint ep = (ExtensionPoint) elem;
 259  0
         Collection xtends = ((org.omg.uml.UmlPackage) ep.refOutermostPackage())
 260  
                 .getUseCases().getAExtensionPointExtend().getExtend(ep);
 261  0
         for (Iterator it = xtends.iterator(); it.hasNext(); ) {
 262  0
             Extend extend = (Extend) it.next();
 263  0
             Collection eps = extend.getExtensionPoint();
 264  0
             if (eps.size() == 1 && eps.contains(elem)) {
 265  0
                 modelImpl.getUmlFactory().delete(extend);
 266  
             }
 267  0
         }
 268  0
     }
 269  
 
 270  
     /**
 271  
      * @param elem
 272  
      *            the UML element to be deleted
 273  
      */
 274  
     void deleteInclude(Object elem) {
 275  0
         if (!(elem instanceof Include)) {
 276  0
             throw new IllegalArgumentException();
 277  
         }
 278  
 
 279  0
     }
 280  
 
 281  
     /**
 282  
      * @param elem
 283  
      *            the UML element to be deleted
 284  
      */
 285  
     void deleteUseCase(Object elem) {
 286  0
         if (!(elem instanceof UseCase)) {
 287  0
             throw new IllegalArgumentException();
 288  
         }
 289  
 
 290  0
         UseCase useCase = ((UseCase) elem);
 291  0
         modelImpl.getUmlHelper().deleteCollection(useCase.getExtend());
 292  0
         modelImpl.getUmlHelper().deleteCollection(useCase.getInclude());
 293  
         // delete Extends where this is the base
 294  0
         modelImpl.getUmlHelper().deleteCollection(
 295  
                 ((org.omg.uml.UmlPackage) useCase.refOutermostPackage())
 296  
                         .getUseCases().getABaseExtender().getExtender(useCase));
 297  
         // delete Includes where this is the addition
 298  0
         modelImpl.getUmlHelper().deleteCollection(
 299  
                 ((org.omg.uml.UmlPackage) useCase.refOutermostPackage())
 300  
                         .getUseCases().getAIncluderAddition().getIncluder(
 301  
                                 useCase));
 302  0
     }
 303  
 
 304  
     /**
 305  
      * @param elem
 306  
      *            the UML element to be deleted
 307  
      */
 308  
     void deleteUseCaseInstance(Object elem) {
 309  0
         if (!(elem instanceof UseCaseInstance)) {
 310  0
             throw new IllegalArgumentException();
 311  
         }
 312  0
     }
 313  
 }