Coverage Report - org.argouml.model.euml.UseCasesFactoryEUMLImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
UseCasesFactoryEUMLImpl
0%
0/43
0%
0/26
2.615
UseCasesFactoryEUMLImpl$1
0%
0/12
0%
0/2
2.615
UseCasesFactoryEUMLImpl$2
0%
0/6
N/A
2.615
 
 1  
 // $Id: UseCasesFactoryEUMLImpl.java 18220 2010-04-08 20:37:15Z tfmorris $
 2  
 /*******************************************************************************
 3  
  * Copyright (c) 2007,2010 Tom Morris and other contributors
 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  
  *    Tom Morris - initial framework
 11  
  *    Bogdan Pistol - Initial implementation 
 12  
  *******************************************************************************/
 13  
 package org.argouml.model.euml;
 14  
 
 15  
 import org.argouml.model.AbstractModelFactory;
 16  
 import org.argouml.model.UseCasesFactory;
 17  
 import org.eclipse.uml2.uml.Actor;
 18  
 import org.eclipse.uml2.uml.Extend;
 19  
 import org.eclipse.uml2.uml.ExtensionPoint;
 20  
 import org.eclipse.uml2.uml.Include;
 21  
 import org.eclipse.uml2.uml.Namespace;
 22  
 import org.eclipse.uml2.uml.UMLFactory;
 23  
 import org.eclipse.uml2.uml.UseCase;
 24  
 
 25  
 /**
 26  
  * The implementation of the UseCasesFactory for EUML2.
 27  
  */
 28  0
 class UseCasesFactoryEUMLImpl implements UseCasesFactory, AbstractModelFactory {
 29  
 
 30  
     /**
 31  
      * The model implementation.
 32  
      */
 33  
     private EUMLModelImplementation modelImpl;
 34  
 
 35  
     /**
 36  
      * Constructor.
 37  
      * 
 38  
      * @param implementation
 39  
      *            The ModelImplementation.
 40  
      */
 41  0
     public UseCasesFactoryEUMLImpl(EUMLModelImplementation implementation) {
 42  0
         modelImpl = implementation;
 43  0
     }
 44  
 
 45  
     public Actor buildActor(Object actor, Object model) {
 46  0
         if (!(actor instanceof Actor)) {
 47  0
             throw new IllegalArgumentException();
 48  
         }
 49  0
         if (((Actor) actor).getNamespace() == null
 50  
                 && !(model instanceof Namespace)) {
 51  0
             throw new IllegalArgumentException();
 52  
         }
 53  0
         Namespace ns = ((Actor) actor).getNamespace();
 54  0
         if (ns == null) {
 55  0
             ns = (Namespace) model;
 56  
         }
 57  0
         Actor ret = createActor();
 58  0
         modelImpl.getCoreHelper().addOwnedElement(
 59  
                 ns, ret, "Create the actor # in the namespace #", ret, ns);
 60  
 //        ret.setIsLeaf(false);
 61  
 //        ret.setIsRoot(false);
 62  0
         return ret;
 63  
     }
 64  
 
 65  
     public Extend buildExtend(Object abase, Object anextension) {
 66  0
         return buildExtend(abase, anextension, null);
 67  
     }
 68  
 
 69  
     public Extend buildExtend(final Object extendedCase,
 70  
             final Object extension, final Object extensionLocation) {
 71  0
         if (!(extendedCase instanceof UseCase)
 72  
                 || !(extension instanceof UseCase)) {
 73  0
             throw new IllegalArgumentException();
 74  
         }
 75  0
         if (extensionLocation != null
 76  
                 && !(extensionLocation instanceof ExtensionPoint)) {
 77  0
             throw new IllegalArgumentException();
 78  
         }
 79  0
         if (extensionLocation != null
 80  
                 && !((ExtensionPoint) extensionLocation).getUseCase().equals(
 81  
                         extendedCase)) {
 82  0
             throw new IllegalArgumentException(
 83  
                     "extensionLocation must belong to " + extendedCase); //$NON-NLS-1$
 84  
         }
 85  0
         RunnableClass run = new RunnableClass() {
 86  
             public void run() {
 87  
                 ExtensionPoint ep;
 88  0
                 if (extensionLocation == null) {
 89  0
                     ep = createExtensionPoint();
 90  0
                     ((UseCase) extendedCase).getExtensionPoints().add(ep);
 91  
                 } else {
 92  0
                     ep = (ExtensionPoint) extensionLocation;
 93  
                 }
 94  0
                 Extend extend = createExtend();
 95  0
                 extend.setExtendedCase((UseCase) extendedCase);
 96  0
                 extend.setExtension((UseCase) extension);
 97  0
                 extend.getExtensionLocations().add(ep);
 98  0
                 getParams().add(extend);
 99  0
                 getParams().add(ep);
 100  0
             }
 101  
         };
 102  0
         ChangeCommand cmd = new ChangeCommand(
 103  
                 modelImpl, run,
 104  
                 "Create the extend # for the case # that extends the case # through #");
 105  0
         modelImpl.getEditingDomain().getCommandStack().execute(cmd);
 106  0
         cmd.setObjects(
 107  
                 run.getParams().get(0), extension, extendedCase,
 108  
                 run.getParams().get(1));
 109  
 
 110  0
         return (Extend) run.getParams().get(0);
 111  
     }
 112  
 
 113  
     public ExtensionPoint buildExtensionPoint(Object modelElement) {
 114  0
         if (!(modelElement instanceof UseCase)) {
 115  0
             throw new IllegalArgumentException();
 116  
         }
 117  0
         ExtensionPoint ep = createExtensionPoint();
 118  0
         modelImpl.getCoreHelper().addOwnedElement(
 119  
                 modelElement, ep,
 120  
                 "Create the extension point # for the case #", ep,
 121  
                 modelElement);
 122  0
         return ep;
 123  
     }
 124  
 
 125  
     public Include buildInclude(final Object addition,
 126  
             final Object includingCase) {
 127  0
         if (!(addition instanceof UseCase)
 128  
                 || !(includingCase instanceof UseCase)) {
 129  0
             throw new IllegalArgumentException();
 130  
         }
 131  0
         RunnableClass run = new RunnableClass() {
 132  
             public void run() {
 133  0
                 Include include = createInclude();
 134  0
                 include.setAddition((UseCase) addition);
 135  0
                 include.setIncludingCase((UseCase) includingCase);
 136  0
                 getParams().add(include);
 137  0
             }
 138  
         };
 139  0
         ChangeCommand cmd = new ChangeCommand(
 140  
                 modelImpl, run,
 141  
                 "Create the include # of the including case # that include the case #");
 142  0
         modelImpl.getEditingDomain().getCommandStack().execute(cmd);
 143  0
         cmd.setObjects(run.getParams().get(0), includingCase, addition);
 144  
 
 145  0
         return (Include) run.getParams().get(0);
 146  
     }
 147  
 
 148  
     public Actor createActor() {
 149  0
         return UMLFactory.eINSTANCE.createActor();
 150  
     }
 151  
 
 152  
     public Extend createExtend() {
 153  0
         return UMLFactory.eINSTANCE.createExtend();
 154  
     }
 155  
 
 156  
     public ExtensionPoint createExtensionPoint() {
 157  0
         return UMLFactory.eINSTANCE.createExtensionPoint();
 158  
     }
 159  
 
 160  
     public Include createInclude() {
 161  0
         return UMLFactory.eINSTANCE.createInclude();
 162  
     }
 163  
     
 164  
     public UseCase createUseCase() {
 165  0
         return UMLFactory.eINSTANCE.createUseCase();
 166  
     }
 167  
 
 168  
 
 169  
 }