Coverage Report - org.argouml.model.euml.ModelManagementFactoryEUMLImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ModelManagementFactoryEUMLImpl
0%
0/43
0%
0/20
1.765
ModelManagementFactoryEUMLImpl$1
0%
0/6
N/A
1.765
ModelManagementFactoryEUMLImpl$2
0%
0/6
0%
0/2
1.765
ModelManagementFactoryEUMLImpl$3
0%
0/3
N/A
1.765
ModelManagementFactoryEUMLImpl$4
0%
0/3
N/A
1.765
ModelManagementFactoryEUMLImpl$5
0%
0/3
N/A
1.765
ModelManagementFactoryEUMLImpl$6
0%
0/3
N/A
1.765
 
 1  
 // $Id: ModelManagementFactoryEUMLImpl.java 18916 2010-12-11 17:59:42Z thn $
 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 implementation
 11  
  *    Bogdan Pistol - Undo support
 12  
  *    thn
 13  
  *****************************************************************************/
 14  
 
 15  
 package org.argouml.model.euml;
 16  
 
 17  
 import java.util.ArrayList;
 18  
 import java.util.List;
 19  
 
 20  
 import org.argouml.model.AbstractModelFactory;
 21  
 import org.argouml.model.ModelManagementFactory;
 22  
 import org.argouml.model.NotImplementedException;
 23  
 import org.eclipse.emf.ecore.EObject;
 24  
 import org.eclipse.emf.ecore.resource.Resource;
 25  
 import org.eclipse.emf.ecore.util.EcoreUtil;
 26  
 import org.eclipse.emf.edit.domain.EditingDomain;
 27  
 import org.eclipse.uml2.common.edit.command.ChangeCommand;
 28  
 import org.eclipse.uml2.uml.ElementImport;
 29  
 import org.eclipse.uml2.uml.Model;
 30  
 import org.eclipse.uml2.uml.Namespace;
 31  
 import org.eclipse.uml2.uml.PackageableElement;
 32  
 import org.eclipse.uml2.uml.Profile;
 33  
 import org.eclipse.uml2.uml.UMLFactory;
 34  
 
 35  
 
 36  
 /**
 37  
  * The implementation of the ModelManagementFactory for EUML2.
 38  
  */
 39  0
 class ModelManagementFactoryEUMLImpl implements ModelManagementFactory,
 40  
         AbstractModelFactory {
 41  
 
 42  
     /**
 43  
      * The model implementation.
 44  
      */
 45  
     private EUMLModelImplementation modelImpl;
 46  
     
 47  
     private EditingDomain editingDomain;
 48  
     
 49  
     private org.eclipse.uml2.uml.Package theRootModel;
 50  
 
 51  
     /**
 52  
      * Constructor.
 53  
      * 
 54  
      * @param implementation
 55  
      *            The ModelImplementation.
 56  
      */
 57  
     public ModelManagementFactoryEUMLImpl(
 58  0
             EUMLModelImplementation implementation) {
 59  0
         modelImpl = implementation;
 60  0
         editingDomain = implementation.getEditingDomain();
 61  0
     }
 62  
 
 63  
     public ElementImport buildElementImport(final Object pack, 
 64  
             final Object me) {
 65  0
         UMLUtil.checkArgs(new Object[] {pack, me}, 
 66  
                 new Class[] {Namespace.class, PackageableElement.class});
 67  
         
 68  0
         RunnableClass run = new RunnableClass() {
 69  
             public void run() {
 70  0
                 ElementImport elementImport = createElementImport();
 71  0
                 elementImport.setImportingNamespace((Namespace) pack);
 72  0
                 elementImport.setImportedElement((PackageableElement) me);
 73  0
                 getParams().add(elementImport);
 74  0
             }
 75  
         };
 76  0
         editingDomain.getCommandStack().execute(
 77  
                 new ChangeCommand(editingDomain, run));
 78  
 
 79  0
         return (ElementImport) run.getParams().get(0);
 80  
     }
 81  
 
 82  
 
 83  
     public org.eclipse.uml2.uml.Package buildPackage(final String name) {
 84  0
         RunnableClass run = new RunnableClass() {
 85  
             public void run() {
 86  0
                 org.eclipse.uml2.uml.Package pkg =
 87  
                     (org.eclipse.uml2.uml.Package) createPackage();
 88  0
         if (name != null) {
 89  0
             pkg.setName(name);
 90  
         }
 91  0
             getParams().add(pkg);
 92  0
             }
 93  
         };
 94  0
         editingDomain.getCommandStack().execute(
 95  
                 new ChangeCommand(editingDomain, run));
 96  0
         return (org.eclipse.uml2.uml.Package) run.getParams().get(0);
 97  
     }
 98  
     
 99  
     public Object copyPackage(Object source, Object ns) {
 100  
         // TODO: Auto-generated method stub
 101  0
         return null;
 102  
     }
 103  
 
 104  
     public ElementImport createElementImport() {
 105  0
        RunnableClass run = new RunnableClass() {
 106  
             public void run() {
 107  0
                 getParams().add(UMLFactory.eINSTANCE.createElementImport());
 108  0
             }
 109  
         };
 110  0
         editingDomain.getCommandStack().execute(
 111  
                 new ChangeCommand(editingDomain, run));
 112  0
         return (ElementImport) run.getParams().get(0);
 113  
     }
 114  
 
 115  
     public Model createModel() {
 116  
         // TODO: Check for Resource to hold this and create if necessary?
 117  
         // This is a discrepancy between MDR which does it here and eUML which
 118  
         // does it as part of setRootModel
 119  0
         RunnableClass run = new RunnableClass() {
 120  
             public void run() {
 121  0
                 getParams().add(UMLFactory.eINSTANCE.createModel());
 122  0
             }
 123  
         };
 124  0
         editingDomain.getCommandStack().execute(
 125  
                 new ChangeCommand(editingDomain, run));
 126  0
         return (Model) run.getParams().get(0);
 127  
     }
 128  
 
 129  
     public org.eclipse.uml2.uml.Package createPackage() {
 130  0
         RunnableClass run = new RunnableClass() {
 131  
             public void run() {
 132  0
                 getParams().add(UMLFactory.eINSTANCE.createPackage());
 133  0
             }
 134  
         };
 135  0
         editingDomain.getCommandStack().execute(
 136  
                 new ChangeCommand(editingDomain, run));
 137  0
         return (org.eclipse.uml2.uml.Package) run.getParams().get(0);
 138  
     }
 139  
 
 140  
     public Profile createProfile() {
 141  0
         RunnableClass run = new RunnableClass() {
 142  
             public void run() {
 143  0
                 getParams().add(UMLFactory.eINSTANCE.createProfile());
 144  0
             }
 145  
         };
 146  0
         editingDomain.getCommandStack().execute(
 147  
                 new ChangeCommand(editingDomain, run));
 148  0
         return (Profile) run.getParams().get(0);
 149  
     }
 150  
 
 151  
     @Deprecated
 152  
     public Object createSubsystem() {
 153  
         // Removed from UML 2
 154  0
         throw new NotImplementedException();
 155  
     }
 156  
 
 157  
     // TODO: get/setRootModel aren't specific to the Model implementation
 158  
     // they could probably be moved elsewhere - tfm - 20070530
 159  
     @Deprecated
 160  
     public void setRootModel(Object rootModel) {
 161  
         // TODO: Hook this creating of a new resource in to someplace more
 162  
         // more appropriate (perhaps createModel() ?)
 163  
         // Better yet add a new method to Model API to create a new top level 
 164  
         // project/model/xmi file so we don't depend on side effects
 165  0
         if (rootModel != null 
 166  
                 && !(rootModel instanceof org.eclipse.uml2.uml.Package)) {
 167  0
             throw new IllegalArgumentException(
 168  
                     "The rootModel supplied must be a Package. Got a " //$NON-NLS-1$
 169  
                     + rootModel.getClass().getName());
 170  
         }
 171  0
         List<EObject> restoreList = new ArrayList<EObject>();
 172  0
         if (theRootModel != null && theRootModel.eResource() != null) {
 173  0
             if (theRootModel.eResource().getContents().contains(theRootModel)
 174  
                     && rootModel == theRootModel) {
 175  0
                 for (EObject o : theRootModel.eResource().getContents()) {
 176  0
                     if (o != theRootModel) {
 177  0
                         restoreList.add(o);
 178  
                     }
 179  
                 }
 180  
             }
 181  0
             EcoreUtil.remove(theRootModel);
 182  
         }
 183  0
         theRootModel = (org.eclipse.uml2.uml.Package) rootModel;
 184  0
         if (rootModel != null && theRootModel.eResource() == null) {
 185  0
             restoreList.add(0, theRootModel);
 186  0
             Resource r = UMLUtil.getResource(modelImpl, UMLUtil.DEFAULT_URI, 
 187  
                     Boolean.FALSE);
 188  0
             r.getContents().addAll(restoreList);
 189  
         }
 190  0
         modelImpl.getModelEventPump().setRootContainer(theRootModel);
 191  0
     }
 192  
 
 193  
     @Deprecated
 194  
     public org.eclipse.uml2.uml.Package getRootModel() {
 195  0
         return theRootModel;
 196  
     }
 197  
 
 198  
 }