Coverage Report - org.argouml.model.mdr.ModelManagementFactoryMDRImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ModelManagementFactoryMDRImpl
31%
21/66
20%
5/24
2.412
 
 1  
 /* $Id: ModelManagementFactoryMDRImpl.java 18766 2010-09-18 23:18:13Z tfmorris $
 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  
  *    thn
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2005-2009 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 javax.jmi.reflect.InvalidObjectException;
 42  
 
 43  
 import org.apache.log4j.Logger;
 44  
 import org.argouml.model.ModelManagementFactory;
 45  
 import org.omg.uml.foundation.core.ModelElement;
 46  
 import org.omg.uml.foundation.core.Namespace;
 47  
 import org.omg.uml.foundation.core.Stereotype;
 48  
 import org.omg.uml.modelmanagement.ElementImport;
 49  
 import org.omg.uml.modelmanagement.Model;
 50  
 import org.omg.uml.modelmanagement.ModelManagementPackage;
 51  
 import org.omg.uml.modelmanagement.Subsystem;
 52  
 import org.omg.uml.modelmanagement.UmlPackage;
 53  
 
 54  
 /**
 55  
  * The ModelManagementFactory.<p>
 56  
  *
 57  
  * @since ARGO0.19.5
 58  
  * @author Ludovic Ma&icirc;tre
 59  
  * @author Tom Morris
 60  
  * derived from NSUML implementation by:
 61  
  * @author Linus Tolke
 62  
  */
 63  968
 final class ModelManagementFactoryMDRImpl extends
 64  
         AbstractUmlModelFactoryMDR implements ModelManagementFactory {
 65  
 
 66  
     /**
 67  
      * Logger.
 68  
      */
 69  900
     private static final Logger LOG =
 70  
         Logger.getLogger(ModelManagementFactoryMDRImpl.class);
 71  
 
 72  
     /**
 73  
      * The model.
 74  
      */
 75  
     private Object theRootModel;
 76  
 
 77  
     /**
 78  
      * The model implementation.
 79  
      */
 80  
     private MDRModelImplementation modelImpl;
 81  
 
 82  
     /**
 83  
      * Constructor.
 84  
      *
 85  
      * @param mi
 86  
      *            The MDRModelImplementation.
 87  
      */
 88  900
     public ModelManagementFactoryMDRImpl(MDRModelImplementation mi) {
 89  900
         modelImpl = mi;
 90  900
     }
 91  
 
 92  
 
 93  
     public Model createModel() {
 94  968
         ModelManagementPackage mmp = getModelManagementPackage();
 95  968
         if (mmp == null) {
 96  
             // Normally the extent should exist already, but in the case of
 97  
             // making an empty project, we may not have an extent yet, so 
 98  
             // create a default extent
 99  0
             modelImpl.createDefaultExtent();
 100  
         }
 101  968
         Model myModel = getModelManagementPackage().getModel().createModel();
 102  968
         super.initialize(myModel);
 103  968
         return myModel;
 104  
     }
 105  
 
 106  
     private ModelManagementPackage getModelManagementPackage() {
 107  1936
         org.omg.uml.UmlPackage umlPackage = modelImpl.getUmlPackage();
 108  1936
         if (umlPackage == null) {
 109  0
             return null;
 110  
         }
 111  
         try {
 112  1936
             return umlPackage.getModelManagement();
 113  0
         } catch (InvalidObjectException e) {
 114  0
             return null;
 115  
         }
 116  
     }
 117  
     
 118  
     @Deprecated
 119  
     public void setRootModel(Object rootModel) {
 120  2904
         if (rootModel != null && !(rootModel instanceof Model)) {
 121  0
             throw new IllegalArgumentException(
 122  
                     "The rootModel supplied must be a Model. Got a "
 123  
                             + rootModel.getClass().getName());
 124  
         }
 125  2904
         theRootModel = rootModel;
 126  2904
     }
 127  
 
 128  
 
 129  
     @Deprecated
 130  
     public Object getRootModel() {
 131  1936
         return theRootModel;
 132  
     }
 133  
 
 134  
 
 135  
     public ElementImport createElementImport() {
 136  0
         ElementImport myElementImport =
 137  
             getModelManagementPackage().getElementImport().createElementImport();
 138  0
         super.initialize(myElementImport);
 139  0
         return myElementImport;
 140  
     }
 141  
 
 142  
 
 143  
     public ElementImport buildElementImport(Object pack, Object me) {
 144  0
         if (pack instanceof UmlPackage && me instanceof ModelElement) {
 145  0
             ElementImport ei = createElementImport();
 146  0
             ei.setImportedElement((ModelElement) me);
 147  0
             ei.setUmlPackage((UmlPackage) pack);
 148  0
             return ei;
 149  
         }
 150  0
         throw new IllegalArgumentException(
 151  
                 "To build an ElementImport we need a "
 152  
                 + "Package and a ModelElement.");
 153  
     }
 154  
 
 155  
     public UmlPackage createPackage() {
 156  0
         UmlPackage myUmlPackage =
 157  
             getModelManagementPackage().getUmlPackage().createUmlPackage();
 158  0
         super.initialize(myUmlPackage);
 159  0
         return myUmlPackage;
 160  
     }
 161  
 
 162  
     public Model createProfile() {
 163  14
         Model profile = createModel();
 164  
         // apply <<profile>> stereotype to make it a "profile" (our convention)
 165  
         // (hack: create that stereotype instead using the UML 1.4 profile)
 166  14
         Stereotype stereo =
 167  
             (Stereotype)modelImpl.getExtensionMechanismsFactory()
 168  
                 .buildStereotype("profile", profile);
 169  14
         profile.getStereotype().add(stereo);
 170  14
         return profile;
 171  
     }
 172  
 
 173  
     public Object buildPackage(String name) {
 174  0
         UmlPackage pkg = createPackage();
 175  0
         pkg.setName(name);
 176  0
         return pkg;
 177  
     }
 178  
     
 179  
     public Object createSubsystem() {
 180  0
         Subsystem mySubsystem =
 181  
             getModelManagementPackage().getSubsystem().createSubsystem();
 182  0
         super.initialize(mySubsystem);
 183  0
         return mySubsystem;
 184  
     }
 185  
 
 186  
 
 187  
     public Object copyPackage(Object source, Object ns) {
 188  0
         if (!(source instanceof UmlPackage)) {
 189  0
             throw new IllegalArgumentException("source");
 190  
         }
 191  0
         if (!(ns instanceof Namespace)) {
 192  0
             throw new IllegalArgumentException("namespace");
 193  
         }
 194  
 
 195  0
         UmlPackage p = createPackage();
 196  0
         ((Namespace) ns).getOwnedElement().add(p);
 197  0
         doCopyPackage((UmlPackage) source, p);
 198  0
         return p;
 199  
     }
 200  
 
 201  
     /**
 202  
      * Used by the copy functions. Do not call this function directly.
 203  
      *
 204  
      * @param source
 205  
      *            The source package.
 206  
      * @param target
 207  
      *            The target package.
 208  
      */
 209  
     private void doCopyPackage(UmlPackage source, UmlPackage target) {
 210  0
         ((CoreFactoryMDRImpl) modelImpl.getCoreFactory())
 211  
             .doCopyNamespace(source, target);
 212  0
     }
 213  
 
 214  
     /**
 215  
      * @param elem
 216  
      *            to be deleted
 217  
      */
 218  
     void deleteElementImport(Object elem) {
 219  0
         if (!(elem instanceof ElementImport)) {
 220  0
             throw new IllegalArgumentException();
 221  
         }
 222  
 
 223  0
     }
 224  
 
 225  
     /**
 226  
      * @param elem
 227  
      *            to be deleted
 228  
      */
 229  
     void deleteModel(Object elem) {
 230  0
         if (!(elem instanceof Model)) {
 231  0
             throw new IllegalArgumentException();
 232  
         }
 233  
 
 234  0
     }
 235  
 
 236  
     /**
 237  
      * @param elem
 238  
      *            to be deleted
 239  
      */
 240  
     void deletePackage(Object elem) {
 241  0
         if (!(elem instanceof UmlPackage)) {
 242  0
             throw new IllegalArgumentException();
 243  
         }
 244  
 
 245  0
     }
 246  
 
 247  
     /**
 248  
      * @param elem
 249  
      *            to be deleted
 250  
      */
 251  
     void deleteSubsystem(Object elem) {
 252  0
         if (!(elem instanceof Subsystem)) {
 253  0
             throw new IllegalArgumentException();
 254  
         }
 255  
 
 256  0
     }
 257  
 
 258  
 }