Coverage Report - org.argouml.model.mdr.UmlFactoryMDRImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
UmlFactoryMDRImpl
30%
199/645
19%
100/524
11.125
 
 1  
 /* $Id: UmlFactoryMDRImpl.java 18677 2010-08-20 15:16:44Z bobtarling $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009-2010 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  
  *    Bob Tarling
 11  
  *    Luis Sergio Oliveira (euluis)
 12  
  *****************************************************************************
 13  
  *
 14  
  * Some portions of this file was previously release using the BSD License:
 15  
  */
 16  
 
 17  
 // Copyright (c) 1996-2009 The Regents of the University of California. All
 18  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 19  
 // software and its documentation without fee, and without a written
 20  
 // agreement is hereby granted, provided that the above copyright notice
 21  
 // and this paragraph appear in all copies.  This software program and
 22  
 // documentation are copyrighted by The Regents of the University of
 23  
 // California. The software program and documentation are supplied "AS
 24  
 // IS", without any accompanying services from The Regents. The Regents
 25  
 // does not warrant that the operation of the program will be
 26  
 // uninterrupted or error-free. The end-user understands that the program
 27  
 // was developed for research purposes and is advised not to rely
 28  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 29  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 30  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 31  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 32  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 33  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 34  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 35  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 36  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 37  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 38  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 39  
 
 40  
 package org.argouml.model.mdr;
 41  
 
 42  
 import java.util.ArrayList;
 43  
 import java.util.Collection;
 44  
 import java.util.HashMap;
 45  
 import java.util.HashSet;
 46  
 import java.util.List;
 47  
 import java.util.Map;
 48  
 import java.util.Set;
 49  
 
 50  
 import javax.jmi.reflect.InvalidObjectException;
 51  
 import javax.jmi.reflect.RefObject;
 52  
 
 53  
 import org.apache.log4j.Logger;
 54  
 import org.argouml.model.DummyModelCommand;
 55  
 import org.argouml.model.IllegalModelElementConnectionException;
 56  
 import org.argouml.model.InvalidElementException;
 57  
 import org.argouml.model.MetaTypes;
 58  
 import org.argouml.model.Model;
 59  
 import org.argouml.model.UmlFactory;
 60  
 import org.omg.uml.behavioralelements.activitygraphs.ActionState;
 61  
 import org.omg.uml.behavioralelements.activitygraphs.ActivityGraph;
 62  
 import org.omg.uml.behavioralelements.activitygraphs.CallState;
 63  
 import org.omg.uml.behavioralelements.activitygraphs.ClassifierInState;
 64  
 import org.omg.uml.behavioralelements.activitygraphs.ObjectFlowState;
 65  
 import org.omg.uml.behavioralelements.activitygraphs.Partition;
 66  
 import org.omg.uml.behavioralelements.activitygraphs.SubactivityState;
 67  
 import org.omg.uml.behavioralelements.collaborations.AssociationEndRole;
 68  
 import org.omg.uml.behavioralelements.collaborations.AssociationRole;
 69  
 import org.omg.uml.behavioralelements.collaborations.ClassifierRole;
 70  
 import org.omg.uml.behavioralelements.collaborations.Collaboration;
 71  
 import org.omg.uml.behavioralelements.collaborations.CollaborationInstanceSet;
 72  
 import org.omg.uml.behavioralelements.collaborations.Interaction;
 73  
 import org.omg.uml.behavioralelements.collaborations.InteractionInstanceSet;
 74  
 import org.omg.uml.behavioralelements.collaborations.Message;
 75  
 import org.omg.uml.behavioralelements.commonbehavior.Action;
 76  
 import org.omg.uml.behavioralelements.commonbehavior.ActionSequence;
 77  
 import org.omg.uml.behavioralelements.commonbehavior.Argument;
 78  
 import org.omg.uml.behavioralelements.commonbehavior.AttributeLink;
 79  
 import org.omg.uml.behavioralelements.commonbehavior.CallAction;
 80  
 import org.omg.uml.behavioralelements.commonbehavior.ComponentInstance;
 81  
 import org.omg.uml.behavioralelements.commonbehavior.CreateAction;
 82  
 import org.omg.uml.behavioralelements.commonbehavior.DataValue;
 83  
 import org.omg.uml.behavioralelements.commonbehavior.DestroyAction;
 84  
 import org.omg.uml.behavioralelements.commonbehavior.Instance;
 85  
 import org.omg.uml.behavioralelements.commonbehavior.Link;
 86  
 import org.omg.uml.behavioralelements.commonbehavior.LinkEnd;
 87  
 import org.omg.uml.behavioralelements.commonbehavior.LinkObject;
 88  
 import org.omg.uml.behavioralelements.commonbehavior.NodeInstance;
 89  
 import org.omg.uml.behavioralelements.commonbehavior.Reception;
 90  
 import org.omg.uml.behavioralelements.commonbehavior.ReturnAction;
 91  
 import org.omg.uml.behavioralelements.commonbehavior.SendAction;
 92  
 import org.omg.uml.behavioralelements.commonbehavior.Signal;
 93  
 import org.omg.uml.behavioralelements.commonbehavior.Stimulus;
 94  
 import org.omg.uml.behavioralelements.commonbehavior.SubsystemInstance;
 95  
 import org.omg.uml.behavioralelements.commonbehavior.TerminateAction;
 96  
 import org.omg.uml.behavioralelements.commonbehavior.UmlException;
 97  
 import org.omg.uml.behavioralelements.commonbehavior.UninterpretedAction;
 98  
 import org.omg.uml.behavioralelements.statemachines.CallEvent;
 99  
 import org.omg.uml.behavioralelements.statemachines.ChangeEvent;
 100  
 import org.omg.uml.behavioralelements.statemachines.CompositeState;
 101  
 import org.omg.uml.behavioralelements.statemachines.Event;
 102  
 import org.omg.uml.behavioralelements.statemachines.FinalState;
 103  
 import org.omg.uml.behavioralelements.statemachines.Guard;
 104  
 import org.omg.uml.behavioralelements.statemachines.Pseudostate;
 105  
 import org.omg.uml.behavioralelements.statemachines.SignalEvent;
 106  
 import org.omg.uml.behavioralelements.statemachines.SimpleState;
 107  
 import org.omg.uml.behavioralelements.statemachines.State;
 108  
 import org.omg.uml.behavioralelements.statemachines.StateMachine;
 109  
 import org.omg.uml.behavioralelements.statemachines.StateVertex;
 110  
 import org.omg.uml.behavioralelements.statemachines.StubState;
 111  
 import org.omg.uml.behavioralelements.statemachines.SubmachineState;
 112  
 import org.omg.uml.behavioralelements.statemachines.SynchState;
 113  
 import org.omg.uml.behavioralelements.statemachines.TimeEvent;
 114  
 import org.omg.uml.behavioralelements.statemachines.Transition;
 115  
 import org.omg.uml.behavioralelements.usecases.Actor;
 116  
 import org.omg.uml.behavioralelements.usecases.Extend;
 117  
 import org.omg.uml.behavioralelements.usecases.ExtensionPoint;
 118  
 import org.omg.uml.behavioralelements.usecases.Include;
 119  
 import org.omg.uml.behavioralelements.usecases.UseCase;
 120  
 import org.omg.uml.behavioralelements.usecases.UseCaseInstance;
 121  
 import org.omg.uml.foundation.core.Abstraction;
 122  
 import org.omg.uml.foundation.core.Artifact;
 123  
 import org.omg.uml.foundation.core.AssociationClass;
 124  
 import org.omg.uml.foundation.core.AssociationEnd;
 125  
 import org.omg.uml.foundation.core.Attribute;
 126  
 import org.omg.uml.foundation.core.BehavioralFeature;
 127  
 import org.omg.uml.foundation.core.Binding;
 128  
 import org.omg.uml.foundation.core.Classifier;
 129  
 import org.omg.uml.foundation.core.Comment;
 130  
 import org.omg.uml.foundation.core.Component;
 131  
 import org.omg.uml.foundation.core.Constraint;
 132  
 import org.omg.uml.foundation.core.DataType;
 133  
 import org.omg.uml.foundation.core.Dependency;
 134  
 import org.omg.uml.foundation.core.Element;
 135  
 import org.omg.uml.foundation.core.ElementResidence;
 136  
 import org.omg.uml.foundation.core.Enumeration;
 137  
 import org.omg.uml.foundation.core.EnumerationLiteral;
 138  
 import org.omg.uml.foundation.core.Feature;
 139  
 import org.omg.uml.foundation.core.Flow;
 140  
 import org.omg.uml.foundation.core.GeneralizableElement;
 141  
 import org.omg.uml.foundation.core.Generalization;
 142  
 import org.omg.uml.foundation.core.Interface;
 143  
 import org.omg.uml.foundation.core.Method;
 144  
 import org.omg.uml.foundation.core.ModelElement;
 145  
 import org.omg.uml.foundation.core.Namespace;
 146  
 import org.omg.uml.foundation.core.Node;
 147  
 import org.omg.uml.foundation.core.Operation;
 148  
 import org.omg.uml.foundation.core.Parameter;
 149  
 import org.omg.uml.foundation.core.Permission;
 150  
 import org.omg.uml.foundation.core.PresentationElement;
 151  
 import org.omg.uml.foundation.core.Primitive;
 152  
 import org.omg.uml.foundation.core.ProgrammingLanguageDataType;
 153  
 import org.omg.uml.foundation.core.Relationship;
 154  
 import org.omg.uml.foundation.core.Stereotype;
 155  
 import org.omg.uml.foundation.core.StructuralFeature;
 156  
 import org.omg.uml.foundation.core.TagDefinition;
 157  
 import org.omg.uml.foundation.core.TaggedValue;
 158  
 import org.omg.uml.foundation.core.TemplateArgument;
 159  
 import org.omg.uml.foundation.core.TemplateParameter;
 160  
 import org.omg.uml.foundation.core.UmlAssociation;
 161  
 import org.omg.uml.foundation.core.UmlClass;
 162  
 import org.omg.uml.foundation.core.Usage;
 163  
 import org.omg.uml.modelmanagement.ElementImport;
 164  
 import org.omg.uml.modelmanagement.Subsystem;
 165  
 import org.omg.uml.modelmanagement.UmlPackage;
 166  
 
 167  
 /**
 168  
  * Root factory for UML model element instance creation.<p>
 169  
  *
 170  
  * @since ARGO0.19.5
 171  
  * @author Ludovic Ma&icirc;tre
 172  
  * based on NSUML implementation by:
 173  
  * @author Thierry Lach
 174  
  */
 175  
 class UmlFactoryMDRImpl extends AbstractUmlModelFactoryMDR implements
 176  
         UmlFactory {
 177  
 
 178  
     /**
 179  
      * The logger.
 180  
      */
 181  900
     private static final Logger LOG = Logger.getLogger(UmlFactoryMDRImpl.class);
 182  
 
 183  
     /**
 184  
      * The model implementation.
 185  
      */
 186  
     private MDRModelImplementation modelImpl;
 187  
 
 188  
     /**
 189  
      * The meta types factory.
 190  
      */
 191  
     private MetaTypes metaTypes;
 192  
 
 193  
     /**
 194  
      * A map of valid connections keyed by the connection type. The constructor
 195  
      * builds this from the data in the VALID_CONNECTIONS array
 196  
      */
 197  900
     private Map<Class<?>, List<Class<?>[]>> validConnectionMap =
 198  
         new HashMap<Class<?>, List<Class<?>[]>>();
 199  
     
 200  
     /**
 201  
      * A map of the valid model elements that are valid to be contained 
 202  
      * by other model elements.
 203  
      */
 204  900
     private HashMap<Class<?>, Class<?>[]> validContainmentMap = 
 205  
         new HashMap<Class<?>, Class<?>[]>();
 206  
 
 207  
     /**
 208  
      * The instance that we are deleting.
 209  
      */
 210  900
     private Set<RefObject> elementsToBeDeleted = new HashSet<RefObject>();
 211  
 
 212  
     /**
 213  
      * Ordered list of elements to be deleted.
 214  
      */
 215  900
     private List<RefObject> elementsInDeletionOrder = 
 216  
         new ArrayList<RefObject>();
 217  
 
 218  
     /**
 219  
      * The top object is the first object given to the UmlFactory when calling
 220  
      * the delete method.
 221  
      */
 222  
     private Object top;
 223  
 
 224  
     /**
 225  
      * The mutex for this class.
 226  
      */
 227  900
     private Object lock = new Byte[0];
 228  
 
 229  
     /**
 230  
      * An array of valid connections, the combination of connecting class and
 231  
      * node classes must exist as a row in this list to be considered valid.
 232  
      * <ul>
 233  
      * <li>The 1st column is the connecting element.
 234  
      * <li>The 2nd column is the "from" element type.
 235  
      * <li>The 3rd column is the "to" element type.
 236  
      * The 3rd column is optional, if not given then it is assumed to be
 237  
      * the same as the "from" element.
 238  
      * <li>The existence of a 4th column indicates that the connection is valid
 239  
      * in one direction only.
 240  
      * </ul>
 241  
      * TODO: This encodes not only what is legal in UML, but also what ArgoUML
 242  
      * knows how to create, so not all legal connections are included. Probably
 243  
      * should be split into two pieces: 1) legal UML (here) and 2) supported (in
 244  
      * ArgoUML application someplace) - tfm - 20060325<p>
 245  
      * See also issue 3863.<p>
 246  
      *
 247  
      * Most of these are subtypes of Relationship which includes Association,
 248  
      * Dependency, Flow, Generalization, Extend, and Include. Dependency
 249  
      * includes Binding, Abstraction, Usage, and Permission. AssociationRole and
 250  
      * AssociationClass are Associations. The remaining items (Link, Transition,
 251  
      * AssociationEnd, Message) are non-Relationship types which ArgoUML treats
 252  
      * as connections/edges.
 253  
      */
 254  
     // TODO: This should be built by reflection from the metamodel - tfm
 255  
     //       Update for UML 1.4 metamodel if not replaced by reflection
 256  900
     private static final Class<?>[][] VALID_CONNECTIONS = {
 257  
         {Generalization.class,   GeneralizableElement.class, },
 258  
         {Dependency.class,       ModelElement.class, },
 259  
         // Although Usage & Permission are Dependencies, they need to
 260  
         // be include separately because of the way lookup works
 261  
         {Usage.class,            ModelElement.class, },
 262  
         {Permission.class,       ModelElement.class, },
 263  
         // The following is specifically for Realizations
 264  
         {Abstraction.class, UmlClass.class, Interface.class, null, },
 265  
         // The next 3 restrictions for Abstraction seem to be Argo specific
 266  
         // not something the UML spec requires - tfm - 20070215
 267  
         {Abstraction.class, UmlClass.class, UmlClass.class, null, },
 268  
         {Abstraction.class, UmlPackage.class, UmlPackage.class, null, },
 269  
         {Abstraction.class, Component.class, Interface.class, null, },
 270  
         {UmlAssociation.class,     Classifier.class, }, 
 271  
         {AssociationRole.class,  ClassifierRole.class, },
 272  
         {Extend.class,           UseCase.class, },
 273  
         {Include.class,          UseCase.class, },
 274  
         {Link.class, Instance.class, }, 
 275  
         {Transition.class,       StateVertex.class, },
 276  
         {AssociationClass.class, UmlClass.class, }, 
 277  
         {AssociationEnd.class, Classifier.class, UmlAssociation.class, },
 278  
         {Message.class, ClassifierRole.class },
 279  
     };
 280  
 
 281  
     /**
 282  
      * Package-private constructor.
 283  
      *
 284  
      * @param implementation
 285  
      *            To get other helpers and factories.
 286  
      */
 287  900
     UmlFactoryMDRImpl(MDRModelImplementation implementation) {
 288  900
         modelImpl = implementation;
 289  900
         metaTypes = modelImpl.getMetaTypes();
 290  
 
 291  900
         buildValidConnectionMap();
 292  
         
 293  900
         buildValidContainmentMap();
 294  900
     }
 295  
 
 296  
     private void buildValidConnectionMap() {
 297  
         // A list of valid connections between elements, the
 298  
         // connection type first and then the elements to be connected
 299  
 
 300  16200
         for (int i = 0; i < VALID_CONNECTIONS.length; ++i) {
 301  15300
             final Class<?> connection = VALID_CONNECTIONS[i][0];
 302  15300
             List<Class<?>[]> validItems = validConnectionMap.get(connection);
 303  15300
             if (validItems == null) {
 304  12600
                 validItems = new ArrayList<Class<?>[]>();
 305  12600
                 validConnectionMap.put(connection, validItems);
 306  
             }
 307  15300
             if (VALID_CONNECTIONS[i].length < 3) {
 308  
                 // If there isn't a 3rd column then this represents a connection
 309  
                 // of elements of the same type.
 310  10800
                 Class<?>[] modeElementPair = new Class[2];
 311  10800
                 modeElementPair[0] = VALID_CONNECTIONS[i][1];
 312  10800
                 modeElementPair[1] = VALID_CONNECTIONS[i][1];
 313  10800
                 validItems.add(modeElementPair);
 314  10800
             } else {
 315  
                 // If there is a 3rd column then this represents a connection
 316  
                 // of between 2 different types of element.
 317  4500
                 Class<?>[] modeElementPair = new Class[2];
 318  4500
                 modeElementPair[0] = VALID_CONNECTIONS[i][1];
 319  4500
                 modeElementPair[1] = VALID_CONNECTIONS[i][2];
 320  4500
                 validItems.add(modeElementPair);
 321  
                 // If the array hasn't been flagged to indicate otherwise
 322  
                 // swap elements the elements and add again.
 323  4500
                 if (VALID_CONNECTIONS[i].length < 4) {
 324  900
                     Class<?>[] reversedModeElementPair = new Class[2];
 325  900
                     reversedModeElementPair[0] = VALID_CONNECTIONS[i][2];
 326  900
                     reversedModeElementPair[1] = VALID_CONNECTIONS[i][1];
 327  900
                     validItems.add(reversedModeElementPair);
 328  
                 }
 329  
             }
 330  
         }
 331  900
     }
 332  
     
 333  
     /**
 334  
      * Initializes the validContainmentMap based on the rules for 
 335  
      * valid containment of elements.
 336  
      * 
 337  
      * @author Scott Roberts
 338  
      */
 339  
     private void buildValidContainmentMap() {
 340  
        
 341  900
         validContainmentMap.clear();
 342  
 
 343  900
         validContainmentMap.put(ModelElement.class,
 344  
                 new Class<?>[] {
 345  
                     TemplateParameter.class
 346  
                 });
 347  
         
 348  
         // specifies valid elements for a Model to contain 
 349  900
         validContainmentMap.put(org.omg.uml.modelmanagement.Model.class,
 350  
             new Class<?>[] {
 351  
                 TemplateParameter.class,
 352  
                 ComponentInstance.class, NodeInstance.class
 353  
             });
 354  
 
 355  
         // specifies valid elements for a Model to contain 
 356  900
         validContainmentMap.put(AssociationEnd.class,
 357  
             new Class<?>[] {
 358  
                 Attribute.class
 359  
             });
 360  
 
 361  
         // specifies valid elements for a Package to contain
 362  900
         validContainmentMap.put(UmlPackage.class, 
 363  
             new Class<?>[] { 
 364  
                 TemplateParameter.class,
 365  
                 UmlPackage.class, Actor.class,
 366  
                 UseCase.class, UmlClass.class,
 367  
                 Interface.class, Component.class,
 368  
                 Node.class, Stereotype.class,
 369  
                 Enumeration.class, DataType.class,
 370  
                 UmlException.class, Signal.class
 371  
             });
 372  
                 
 373  
         // specifies valid elements for a class to contain
 374  900
         validContainmentMap.put(UmlClass.class, 
 375  
             new Class<?>[] { 
 376  
                 TemplateParameter.class,
 377  
                 Attribute.class, Operation.class,
 378  
                 UmlClass.class, Reception.class
 379  
             });
 380  
         
 381  
         // specifies valid elements for a classifier to contain
 382  900
         validContainmentMap.put(Classifier.class, 
 383  
             new Class<?>[] { 
 384  
                 TemplateParameter.class
 385  
             });
 386  
         
 387  
         // specifies valid elements for an Interface to contain
 388  900
         validContainmentMap.put(Interface.class, 
 389  
                 new Class<?>[] { 
 390  
                     TemplateParameter.class,
 391  
                     Operation.class, Reception.class
 392  
                 });
 393  
         
 394  
         // specifies valid elements for a Signal to contain
 395  900
         validContainmentMap.put(Signal.class, 
 396  
                 new Class<?>[] { 
 397  
                     TemplateParameter.class,
 398  
                     Operation.class, Attribute.class
 399  
                 });
 400  
         
 401  
         // specifies valid elements for an Actor to contain
 402  900
         validContainmentMap.put(Actor.class, 
 403  
                 new Class<?>[] { 
 404  
                     TemplateParameter.class,
 405  
                     Operation.class,
 406  
                     Reception.class
 407  
                 });
 408  
         
 409  
         // specifies valid elements for a Use Case to contain
 410  900
         validContainmentMap.put(UseCase.class, 
 411  
                 new Class<?>[] { 
 412  
                     TemplateParameter.class,
 413  
                     ExtensionPoint.class, Attribute.class, 
 414  
                     Operation.class, Reception.class
 415  
                 });
 416  
         
 417  
         // specifies valid elements for a Use Case to contain
 418  900
         validContainmentMap.put(Extend.class, 
 419  
                 new Class<?>[] { 
 420  
                     TemplateParameter.class,
 421  
                     ExtensionPoint.class
 422  
                 });
 423  
         
 424  
         // specifies valid elements for a Component to contain
 425  900
         validContainmentMap.put(Component.class, 
 426  
                 new Class<?>[] { 
 427  
                     TemplateParameter.class,
 428  
                     Reception.class,
 429  
                     Operation.class
 430  
                 });
 431  
         
 432  
         // specifies valid elements for a Node to contain
 433  900
         validContainmentMap.put(Node.class, 
 434  
                 new Class<?>[] { 
 435  
                     TemplateParameter.class,
 436  
                     Operation.class,
 437  
                     Reception.class
 438  
                 });
 439  
         
 440  
         // specifies valid elements for a Enumeration to contain
 441  900
         validContainmentMap.put(Enumeration.class, 
 442  
                 new Class<?>[] { 
 443  
                     TemplateParameter.class,
 444  
                     EnumerationLiteral.class, Operation.class 
 445  
                 });
 446  
         
 447  
         // specifies valid elements for a DataType to contain
 448  900
         validContainmentMap.put(DataType.class, 
 449  
                 new Class<?>[] { 
 450  
                     TemplateParameter.class,
 451  
                     Operation.class,
 452  
                     Reception.class
 453  
                 });
 454  
         
 455  
         // specifies valid elements for a Operation to contain
 456  900
         validContainmentMap.put(Operation.class, 
 457  
                 new Class<?>[] { 
 458  
                     TemplateParameter.class,
 459  
                     Parameter.class,
 460  
                     Signal.class,
 461  
                     Method.class
 462  
                 });
 463  
         
 464  
         // specifies valid elements for an Event to contain
 465  900
         validContainmentMap.put(Event.class, 
 466  
                 new Class<?>[] { 
 467  
                     TemplateParameter.class,
 468  
                     Parameter.class
 469  
                 });
 470  
         
 471  
         // specifies valid elements for an ObjectFlowState to contain
 472  900
         validContainmentMap.put(ObjectFlowState.class, 
 473  
                 new Class<?>[] { 
 474  
                     TemplateParameter.class,
 475  
                     Parameter.class
 476  
                 });
 477  
         
 478  
         // specifies valid elements for an AssociationRole to contain
 479  900
         validContainmentMap.put(AssociationRole.class, 
 480  
                 new Class<?>[] { 
 481  
                     TemplateParameter.class,
 482  
                     Message.class
 483  
                 });
 484  
         
 485  
         // specifies valid elements for an AssociationRole to contain
 486  900
         validContainmentMap.put(CallAction.class, 
 487  
                 new Class<?>[] { 
 488  
                     TemplateParameter.class,
 489  
                     Argument.class
 490  
                 });
 491  
         
 492  
         // specifies valid elements for an AssociationRole to contain
 493  900
         validContainmentMap.put(UninterpretedAction.class, 
 494  
                 new Class<?>[] { 
 495  
                     TemplateParameter.class,
 496  
                     Argument.class
 497  
                 });
 498  
         
 499  
         // specifies valid elements for an AssociationRole to contain
 500  900
         validContainmentMap.put(ReturnAction.class, 
 501  
                 new Class<?>[] { 
 502  
                     TemplateParameter.class,
 503  
                     Argument.class
 504  
                 });
 505  
         
 506  
         // specifies valid elements for an AssociationRole to contain
 507  900
         validContainmentMap.put(DestroyAction.class, 
 508  
                 new Class<?>[] { 
 509  
                     TemplateParameter.class,
 510  
                     Argument.class
 511  
                 });
 512  
         
 513  
         // specifies valid elements for an AssociationRole to contain
 514  900
         validContainmentMap.put(SendAction.class, 
 515  
                 new Class<?>[] { 
 516  
                     TemplateParameter.class,
 517  
                     Argument.class
 518  
                 });
 519  
         
 520  
         // specifies valid elements for an AssociationRole to contain
 521  900
         validContainmentMap.put(TerminateAction.class, 
 522  
                 new Class<?>[] { 
 523  
                     TemplateParameter.class,
 524  
                     Argument.class
 525  
                 });
 526  
         
 527  
         // specifies valid elements for an AssociationRole to contain
 528  900
         validContainmentMap.put(ActionSequence.class, 
 529  
                 new Class<?>[] { 
 530  
                     TemplateParameter.class, Argument.class,
 531  
                     CallAction.class, ReturnAction.class, CreateAction.class,
 532  
                     DestroyAction.class, SendAction.class,
 533  
                     TerminateAction.class, UninterpretedAction.class,
 534  
                     ActionSequence.class,
 535  
                 });
 536  
         
 537  
         // specifies valid elements for an AssociationRole to contain
 538  900
         validContainmentMap.put(Transition.class, 
 539  
                 new Class<?>[] { 
 540  
                     TemplateParameter.class,
 541  
                     Guard.class,
 542  
                     CallAction.class, ReturnAction.class,
 543  
                     CreateAction.class, DestroyAction.class, SendAction.class, TerminateAction.class, UninterpretedAction.class, ActionSequence.class,
 544  
                     CallEvent.class, ChangeEvent.class, SignalEvent.class, TimeEvent.class
 545  
                 });
 546  
         
 547  
         // specifies valid elements for an AssociationRole to contain
 548  900
         validContainmentMap.put(SignalEvent.class, 
 549  
                 new Class<?>[] { 
 550  
                     Signal.class
 551  
                 });
 552  
         
 553  
         // specifies valid elements for an AssociationRole to contain
 554  900
         validContainmentMap.put(Reception.class, 
 555  
                 new Class<?>[] { 
 556  
                     Parameter.class,
 557  
                     TemplateParameter.class
 558  
                 });
 559  
         
 560  
         // specifies valid elements for an State to contain
 561  900
         validContainmentMap.put(State.class, 
 562  
                 new Class<?>[] { 
 563  
                     CallEvent.class, ChangeEvent.class, SignalEvent.class,
 564  
                     TimeEvent.class
 565  
                 });
 566  
         
 567  
         // specifies valid elements for an CallState to contain
 568  900
         validContainmentMap.put(CallState.class, 
 569  
                 new Class<?>[] { 
 570  
                     CallAction.class,
 571  
                     CallEvent.class, ChangeEvent.class, SignalEvent.class,
 572  
                     TimeEvent.class
 573  
                 });
 574  
         
 575  
         // specifies valid elements for an SimpleState to contain
 576  900
         validContainmentMap.put(SimpleState.class, 
 577  
                 new Class<?>[] { 
 578  
                     Transition.class,
 579  
                     CallAction.class, CreateAction.class, DestroyAction.class,
 580  
                     ReturnAction.class, SendAction.class, 
 581  
                     TerminateAction.class,
 582  
                     UninterpretedAction.class, ActionSequence.class,
 583  
                     CallEvent.class, ChangeEvent.class, SignalEvent.class, 
 584  
                     TimeEvent.class
 585  
                 });
 586  
         
 587  
         // specifies valid elements for an SimpleState to contain
 588  900
         validContainmentMap.put(FinalState.class, 
 589  
                 new Class<?>[] { 
 590  
                     Transition.class,
 591  
                     CallAction.class, CreateAction.class, DestroyAction.class, 
 592  
                     ReturnAction.class, SendAction.class, TerminateAction.class,
 593  
                     UninterpretedAction.class, ActionSequence.class
 594  
                 });
 595  
         
 596  
         // specifies valid elements for an SubactivityState to contain
 597  900
         validContainmentMap.put(SubactivityState.class, 
 598  
                 new Class<?>[] { 
 599  
                     Transition.class,
 600  
                     CallAction.class, CreateAction.class, DestroyAction.class, 
 601  
                     ReturnAction.class, SendAction.class, TerminateAction.class, 
 602  
                     UninterpretedAction.class, ActionSequence.class,
 603  
                     CallEvent.class, ChangeEvent.class, SignalEvent.class, 
 604  
                     TimeEvent.class
 605  
                 });
 606  
         
 607  
         // specifies valid elements for an ActionState to contain
 608  900
         validContainmentMap.put(ActionState.class, 
 609  
                 new Class<?>[] { 
 610  
                     CallAction.class, CreateAction.class, DestroyAction.class, 
 611  
                     ReturnAction.class, SendAction.class, TerminateAction.class, 
 612  
                     UninterpretedAction.class, ActionSequence.class,
 613  
                     CallEvent.class, ChangeEvent.class, SignalEvent.class, 
 614  
                     TimeEvent.class
 615  
                 });
 616  
         
 617  
         // specifies valid elements for an ActionState to contain
 618  900
         validContainmentMap.put(CompositeState.class, 
 619  
                 new Class<?>[] {
 620  
                     Transition.class,
 621  
                     Pseudostate.class, SynchState.class, StubState.class, 
 622  
                     CompositeState.class, SimpleState.class,
 623  
                     FinalState.class, 
 624  
                     SubmachineState.class,
 625  
                     CallAction.class, CreateAction.class, DestroyAction.class,
 626  
                     ReturnAction.class, SendAction.class, 
 627  
                     TerminateAction.class, 
 628  
                     UninterpretedAction.class, ActionSequence.class
 629  
                 });
 630  
         
 631  900
     }
 632  
     
 633  
     public Object buildConnection(Object elementType, Object fromElement,
 634  
             Object fromStyle, Object toElement, Object toStyle,
 635  
             Object unidirectional, Object namespace)
 636  
         throws IllegalModelElementConnectionException {
 637  
 
 638  0
         if (!isConnectionValid(elementType, fromElement, toElement, true)) {
 639  0
             throw new IllegalModelElementConnectionException("Cannot make a "
 640  
                     + elementType.getClass().getName() + " between a "
 641  
                     + fromElement.getClass().getName() + " and a "
 642  
                     + toElement.getClass().getName());
 643  
         }
 644  
 
 645  0
         Object connection = null;
 646  0
         boolean uni = (unidirectional instanceof Boolean) 
 647  
             ? ((Boolean) unidirectional).booleanValue() : false;
 648  0
         if (elementType == metaTypes.getAssociation()) {
 649  0
             connection =
 650  
                 getCore().buildAssociation(fromElement,
 651  
                     fromStyle, toElement,
 652  
                     toStyle, uni);
 653  0
         } else if (elementType == metaTypes.getAssociationEnd()) {
 654  0
             if (fromElement instanceof UmlAssociation) {
 655  0
                 connection =
 656  
                     getCore().buildAssociationEnd(toElement, fromElement);
 657  0
             } else if (fromElement instanceof Classifier) {
 658  0
                 connection =
 659  
                     getCore().buildAssociationEnd(fromElement, toElement);
 660  
             }
 661  0
         } else if (elementType
 662  
                 == metaTypes.getAssociationClass()) {
 663  0
             connection =
 664  
                 getCore().buildAssociationClass(fromElement, toElement);
 665  0
         } else if (elementType == metaTypes.getAssociationRole()) {
 666  0
             connection =
 667  
                 getCollaborations().buildAssociationRole(fromElement,
 668  
                     fromStyle, toElement, toStyle,
 669  
                     ((Boolean) unidirectional).booleanValue());
 670  0
         } else if (elementType == metaTypes.getGeneralization()) {
 671  0
             connection = getCore().buildGeneralization(fromElement, toElement);
 672  0
         } else if (elementType == metaTypes.getPackageImport()) {
 673  0
             connection = getCore().buildPackageImport(fromElement, toElement);
 674  0
         } else if (elementType == metaTypes.getUsage()) {
 675  0
             connection = getCore().buildUsage(fromElement, toElement);
 676  0
         } else if (elementType == metaTypes.getGeneralization()) {
 677  0
             connection = getCore().buildGeneralization(fromElement, toElement);
 678  0
         } else if (elementType == metaTypes.getDependency()) {
 679  0
             connection = getCore().buildDependency(fromElement, toElement);
 680  0
         } else if (elementType == metaTypes.getAbstraction()) {
 681  0
             connection =
 682  
                 getCore().buildRealization(fromElement, toElement, namespace);
 683  0
         } else if (elementType == metaTypes.getLink()) {
 684  0
             connection = getCommonBehavior().buildLink(fromElement, toElement);
 685  0
         } else if (elementType == metaTypes.getExtend()) {
 686  
             // Extend, but only between two use cases. Remember we draw from the
 687  
             // extension port to the base port.
 688  0
             connection = getUseCases().buildExtend(toElement, fromElement);
 689  0
         } else if (elementType == metaTypes.getInclude()) {
 690  0
             connection = getUseCases().buildInclude(fromElement, toElement);
 691  0
         } else if (elementType == metaTypes.getTransition()) {
 692  0
             connection =
 693  
                 getStateMachines().buildTransition(fromElement, toElement);
 694  
         }
 695  
 
 696  0
         if (connection == null) {
 697  0
             throw new IllegalModelElementConnectionException("Cannot make a "
 698  
                     + elementType.getClass().getName() + " between a "
 699  
                     + fromElement.getClass().getName() + " and a "
 700  
                     + toElement.getClass().getName());
 701  
         }
 702  
 
 703  0
         return connection;
 704  
     }
 705  
 
 706  
 
 707  
     public Object buildNode(Object elementType) {
 708  0
         if (elementType == metaTypes.getActor()) {
 709  0
             return getUseCases().createActor();
 710  0
         } else if (elementType == metaTypes.getUseCase()) {
 711  0
             return getUseCases().createUseCase();
 712  0
         } else if (elementType == metaTypes.getUMLClass()) {
 713  0
             return getCore().buildClass();
 714  0
         } else if (elementType == metaTypes.getInterface()) {
 715  0
             return getCore().buildInterface();
 716  0
         } else if (elementType == metaTypes.getDataType()) {
 717  0
             return getCore().createDataType();
 718  0
         } else if (elementType == metaTypes.getPackage()) {
 719  0
             return getModelManagement().createPackage();
 720  0
         } else if (elementType == metaTypes.getModel()) {
 721  0
             return getModelManagement().createModel();
 722  0
         } else if (elementType == metaTypes.getInstance()) {
 723  0
             throw new IllegalArgumentException(
 724  
                     "Attempt to instantiate abstract type");
 725  0
         } else if (elementType == metaTypes.getSubsystem()) {
 726  0
             return getModelManagement().createSubsystem();
 727  0
         } else if (elementType == metaTypes.getCallState()) {
 728  0
             return getActivityGraphs().createCallState();
 729  0
         } else if (elementType == metaTypes.getSimpleState()) {
 730  0
             return getStateMachines().createSimpleState();
 731  0
         } else if (elementType == metaTypes.getFinalState()) {
 732  0
             return getStateMachines().createFinalState();
 733  0
         } else if (elementType == metaTypes.getPseudostate()) {
 734  0
             return getStateMachines().createPseudostate();
 735  0
         } else if (elementType == metaTypes.getObjectFlowState()) {
 736  0
             return getActivityGraphs().createObjectFlowState();
 737  0
         } else if (elementType == metaTypes.getActionState()) {
 738  0
             return getActivityGraphs().createActionState();
 739  0
         } else if (elementType == metaTypes.getSubactivityState()) {
 740  0
             return getActivityGraphs().createSubactivityState();
 741  0
         } else if (elementType == metaTypes.getPartition()) {
 742  0
             return getActivityGraphs().createPartition();
 743  0
         } else if (elementType == metaTypes.getStubState()) {
 744  0
             return getStateMachines().createStubState();
 745  0
         } else if (elementType == metaTypes.getSubmachineState()) {
 746  0
             return getStateMachines().createSubmachineState();
 747  0
         } else if (elementType == metaTypes.getCompositeState()) {
 748  0
             return getStateMachines().createCompositeState();
 749  0
         } else if (elementType == metaTypes.getSynchState()) {
 750  0
             return getStateMachines().createSynchState();
 751  0
         } else if (elementType == metaTypes.getState()) {
 752  0
             throw new IllegalArgumentException(
 753  
                     "Attempt to instantiate abstract type");
 754  0
         } else if (elementType == modelImpl.getMetaTypes().getSimpleState()) {
 755  0
             return getStateMachines().createSimpleState();
 756  0
         } else if (elementType == metaTypes.getClassifierRole()) {
 757  0
             return getCollaborations().createClassifierRole();
 758  0
         } else if (elementType == metaTypes.getComponent()) {
 759  0
             return getCore().createComponent();
 760  0
         } else if (elementType == metaTypes.getComponentInstance()) {
 761  0
             return getCommonBehavior().createComponentInstance();
 762  0
         } else if (elementType == metaTypes.getNode()) {
 763  0
             return getCore().createNode();
 764  0
         } else if (elementType == metaTypes.getNodeInstance()) {
 765  0
             return getCommonBehavior().createNodeInstance();
 766  0
         } else if (elementType == metaTypes.getObject()) {
 767  0
             return getCommonBehavior().createObject();
 768  0
         } else if (elementType == metaTypes.getComment()) {
 769  0
             return getCore().createComment();
 770  0
         } else if (elementType == metaTypes.getNamespace()) {
 771  0
             throw new IllegalArgumentException(
 772  
                     "Attempt to instantiate abstract type");
 773  0
         } else if (elementType == metaTypes.getOperation()) {
 774  0
             return getCore().createOperation();
 775  0
         } else if (elementType == metaTypes.getEnumeration()) {
 776  0
             return getCore().createEnumeration();
 777  0
         } else if (elementType == metaTypes.getStereotype()) {
 778  0
             return getExtensionMechanisms().createStereotype();
 779  0
         } else if (elementType == metaTypes.getAttribute()) {
 780  0
             return getCore().buildAttribute();
 781  0
         } else if (elementType == metaTypes.getSignal()) {
 782  0
             return getCommonBehavior().createSignal();
 783  0
         } else if (elementType == metaTypes.getException()) {
 784  0
             return getCommonBehavior().createException();
 785  0
         } else if (elementType == metaTypes.getTransition()) {
 786  0
             return getStateMachines().createTransition();
 787  0
         } else if (elementType == metaTypes.getTransition()) {
 788  0
             return getStateMachines().createTransition();
 789  
         }
 790  
             
 791  0
         throw new IllegalArgumentException(
 792  
                 "Attempted to create unsupported model element type: " 
 793  
                 + elementType);
 794  
     }
 795  
 
 796  
     public Object buildNode(Object elementType, Object container, String properyName) {
 797  
         
 798  19
         Object element = null;
 799  
         
 800  
         // if this is a feature get the owner of that feature
 801  
         // TODO: Does anything actually make use of this? It can
 802  
         // cause unexpected behaviour.
 803  19
         if (this.modelImpl.getFacade().isAFeature(container)
 804  
                 && elementType != metaTypes.getParameter()
 805  
                 && elementType != metaTypes.getMethod()
 806  
                 && elementType != metaTypes.getSignal()) {
 807  0
             container = this.modelImpl.getFacade().getOwner(container);
 808  
         }
 809  
         
 810  
         // supports implementation of some special elements not 
 811  
         // supported by buildNode
 812  19
         if (elementType == this.metaTypes.getAttribute()) {
 813  0
             element = getCore().buildAttribute2(container, null);   
 814  19
         } else if (elementType == this.metaTypes.getOperation()) {
 815  0
             element = getCore().buildOperation(container, null);
 816  19
         } else if (elementType == this.metaTypes.getReception()) {
 817  0
             element = this.modelImpl.getCommonBehaviorFactory().buildReception(container);
 818  19
         } else if (elementType == this.metaTypes.getEnumerationLiteral()) {
 819  0
             element = getCore().buildEnumerationLiteral(null, container);
 820  19
         } else if (elementType == this.metaTypes.getExtensionPoint()) {
 821  0
             element = this.modelImpl.getUseCasesFactory().
 822  
                 buildExtensionPoint(container);            
 823  19
         } else if (elementType == this.metaTypes.getTemplateParameter()) {
 824  
             // TODO: the type of the model element used in a type parameter
 825  
             // (ie the formal) needs to match the actual parameter that it
 826  
             // gets replaced with later.  This code is going to restrict that
 827  
             // to always being a Parameter which doesn't seem right, but I
 828  
             // don't have time to debug it right now. - tfm - 20090608
 829  0
             Parameter param = getCore().createParameter();
 830  0
             param.setName("T"); // default parameter name
 831  0
             element = 
 832  
                 modelImpl.getCoreFactory().buildTemplateParameter(container, 
 833  
                         param, null);
 834  0
         } else if (elementType == metaTypes.getParameter()) {
 835  0
             element = getCore().buildParameter(container, null);
 836  19
         } else if (elementType == metaTypes.getSignal()) {
 837  0
             element = modelImpl.getCommonBehaviorFactory().buildSignal(container);
 838  19
         } else if (elementType == metaTypes.getMethod()) {
 839  0
             final Operation op = (Operation) container;
 840  0
             element = getCore().buildMethod(op.getName());
 841  0
             modelImpl.getCoreHelper().addMethod(op, element);
 842  0
             modelImpl.getCoreHelper().addFeature(
 843  
                     modelImpl.getFacade().getOwner(op), element);
 844  0
         } else if (elementType == metaTypes.getMessage()) {
 845  0
             Object collaboration = Model.getFacade().getNamespace(container);
 846  0
             element =
 847  
                 Model.getCollaborationsFactory()
 848  
                     .buildMessage(collaboration, container);
 849  0
         } else if (elementType == metaTypes.getArgument()) {
 850  0
             element = Model.getCommonBehaviorFactory().createArgument();
 851  0
             Model.getCommonBehaviorHelper().addActualArgument(container, element);
 852  19
         } else if (elementType == metaTypes.getGuard()) {
 853  0
             element = Model.getStateMachinesFactory().buildGuard(container);
 854  19
         } else if (elementType == metaTypes.getCreateAction()) {
 855  0
             element = Model.getCommonBehaviorFactory().createCreateAction();
 856  0
             setNewAction(container, (Action) element, properyName);
 857  19
         } else if (elementType == metaTypes.getCallAction()) {
 858  0
             element = Model.getCommonBehaviorFactory().createCallAction();
 859  0
             setNewAction(container, (Action) element, properyName);
 860  19
         } else if (elementType == metaTypes.getReturnAction()) {
 861  0
             element = Model.getCommonBehaviorFactory().createReturnAction();
 862  0
             setNewAction(container, (Action) element, properyName);
 863  19
         } else if (elementType == metaTypes.getDestroyAction()) {
 864  0
             element = Model.getCommonBehaviorFactory().createDestroyAction();
 865  0
             setNewAction(container, (Action) element, properyName);
 866  19
         } else if (elementType == metaTypes.getSendAction()) {
 867  0
             element = Model.getCommonBehaviorFactory().createSendAction();
 868  0
             setNewAction(container, (Action) element, properyName);
 869  19
         } else if (elementType == metaTypes.getTerminateAction()) {
 870  0
             element = Model.getCommonBehaviorFactory().createTerminateAction();
 871  0
             setNewAction(container, (Action) element, properyName);
 872  19
         } else if (elementType == metaTypes.getUninterpretedAction()) {
 873  0
             element = Model.getCommonBehaviorFactory().createUninterpretedAction();
 874  0
             setNewAction(container, (Action) element, properyName);
 875  19
         } else if (elementType == metaTypes.getActionSequence()) {
 876  0
             element = Model.getCommonBehaviorFactory().createActionSequence();
 877  0
             setNewAction(container, (Action) element, properyName);
 878  19
         } else if (elementType == metaTypes.getCallEvent()) {
 879  0
             element = Model.getStateMachinesFactory().createCallEvent();
 880  0
             if (container instanceof Transition) {
 881  0
                 setNewTrigger((Transition) container, (Event) element);
 882  0
             } else if (container instanceof State) {
 883  0
                 setNewDeferrableEvent((State) container, (Event) element);
 884  
             }
 885  19
         } else if (elementType == metaTypes.getChangeEvent()) {
 886  0
             element = Model.getStateMachinesFactory().createChangeEvent();
 887  0
             if (container instanceof Transition) {
 888  0
                 setNewTrigger((Transition) container, (Event) element);
 889  0
             } else if (container instanceof State) {
 890  0
                 setNewDeferrableEvent((State) container, (Event) element);
 891  
             }
 892  19
         } else if (elementType == metaTypes.getSignalEvent()) {
 893  0
             element = Model.getStateMachinesFactory().createSignalEvent();
 894  0
             if (container instanceof Transition) {
 895  0
                 setNewTrigger((Transition) container, (Event) element);
 896  0
             } else if (container instanceof State) {
 897  0
                 setNewDeferrableEvent((State) container, (Event) element);
 898  
             }
 899  19
         } else if (elementType == metaTypes.getTimeEvent()) {
 900  0
             element = Model.getStateMachinesFactory().createTimeEvent();
 901  0
             if (container instanceof Transition) {
 902  0
                 setNewTrigger((Transition) container, (Event) element);
 903  0
             } else if (container instanceof State) {
 904  0
                 setNewDeferrableEvent((State) container, (Event) element);
 905  
             }
 906  19
         } else if (elementType == metaTypes.getSignal()) {
 907  0
             element = Model.getStateMachinesFactory().buildSignalEvent(container);
 908  19
         } else if (elementType == metaTypes.getPseudostate() && container instanceof CompositeState) {
 909  0
             element = Model.getStateMachinesFactory().buildPseudoState(container);
 910  19
         } else if (elementType == metaTypes.getSynchState() && container instanceof CompositeState) {
 911  0
             element = Model.getStateMachinesFactory().buildSynchState(container);
 912  19
         } else if (elementType == metaTypes.getStubState() && container instanceof CompositeState) {
 913  0
             element = Model.getStateMachinesFactory().buildStubState(container);
 914  19
         } else if (elementType == metaTypes.getCompositeState() && container instanceof CompositeState) {
 915  0
             element = Model.getStateMachinesFactory().buildCompositeState(container);
 916  19
         } else if (elementType == metaTypes.getSimpleState() && container instanceof CompositeState) {
 917  0
             element = Model.getStateMachinesFactory().buildSimpleState(container);
 918  19
         } else if (elementType == metaTypes.getFinalState() && container instanceof CompositeState) {
 919  0
             element = Model.getStateMachinesFactory().buildFinalState(container);
 920  19
         } else if (elementType == metaTypes.getSubmachineState() && container instanceof CompositeState) {
 921  0
             element = Model.getStateMachinesFactory().buildSubmachineState(container);
 922  19
         } else if (elementType == metaTypes.getTransition() && container instanceof State) {
 923  0
             element = Model.getStateMachinesFactory().buildInternalTransition(container);
 924  19
         } else if (elementType == metaTypes.getActivity()) {
 925  19
             element = Model.getActivityGraphsFactory().buildActivityGraph(container);
 926  
         } else {
 927  
             // build all other elements using existing buildNode
 928  0
             element = buildNode(elementType);
 929  
             
 930  0
             if (container instanceof Namespace 
 931  
                     && element instanceof Namespace) {
 932  0
                 ((Namespace) element).setNamespace(
 933  
                         ((Namespace) container).getNamespace());
 934  
             }
 935  
             
 936  0
             this.modelImpl.getCoreHelper().addOwnedElement(container, element);
 937  
         }
 938  
         
 939  19
         return element;
 940  
     }
 941  
     
 942  
     private void setNewAction(Object container, Action action, String propertyName) {
 943  0
         if (container instanceof Transition) {
 944  0
             ((Transition) container).setEffect(action);
 945  0
         } else if (container instanceof State) {
 946  0
             if ("exit".equals(propertyName)) {
 947  0
                 ((State) container).setExit(action);
 948  0
             } else if ("doActivity".equals(propertyName)) {
 949  0
                 ((State) container).setDoActivity(action);
 950  
             } else {
 951  0
                 ((State) container).setEntry(action);
 952  
             }
 953  0
         } else if (container instanceof ActionSequence) {
 954  0
             ((ActionSequence) container).getAction().add(action);
 955  
         } else {
 956  0
             throw new IllegalArgumentException("Did not expect a " + container);
 957  
         }
 958  0
     }
 959  
 
 960  
     public Object buildNode(Object elementType, Object container) {
 961  19
         return buildNode(elementType, container, null);
 962  
     }
 963  
     
 964  
     
 965  
     /**
 966  
      * Add a newly created event to a trigger
 967  
      * @param transition
 968  
      * @param event
 969  
      */
 970  
     private void setNewTrigger(Transition transition, Event event) {
 971  0
         transition.setTrigger(event);
 972  0
         event.setName("");
 973  0
         final StateMachine statemachine = transition.getStateMachine();
 974  0
         final Namespace namespace = statemachine.getNamespace();
 975  0
         event.setNamespace(namespace);
 976  0
     }
 977  
     
 978  
     /**
 979  
      * Add a newly created event to a trigger
 980  
      * @param transition
 981  
      * @param event
 982  
      */
 983  
     private void setNewDeferrableEvent(final State state, final Event event) {
 984  0
         ((State) state).getDeferrableEvent().add((Event) event);
 985  0
         event.setName("");
 986  0
         Object parent = state;
 987  
         do {
 988  0
             parent = ((RefObject) parent).refImmediateComposite();
 989  0
         } while (!(parent instanceof Namespace));
 990  
         
 991  0
         event.setNamespace((Namespace) parent);
 992  0
     }
 993  
     
 994  
     public boolean isConnectionType(Object connectionType) {
 995  
         // If our map has any entries for this type, it's a connection type
 996  0
         return (validConnectionMap.get(connectionType) != null);
 997  
     }
 998  
 
 999  
 
 1000  
     public boolean isConnectionValid(Object connectionType, Object fromElement,
 1001  
             Object toElement, boolean checkWFR) {
 1002  0
         if (Model.getModelManagementHelper().isReadOnly(fromElement)) {
 1003  
             // Don't allow connections to be created from a read only
 1004  
             // model element to any other
 1005  
             // TODO: This should be considered a workaround.  It only works
 1006  
             // because, by default, we place newly created relationships in
 1007  
             // the namespace of the fromElement.  The correct behavior in
 1008  
             // the presence of read-only elements really depends on the type of
 1009  
             // connection as well as the writeability of both ends.
 1010  0
             return false;
 1011  
         }
 1012  
         // Get the list of valid model item pairs for the given connection type
 1013  0
         List<Class<?>[]> validItems = validConnectionMap.get(connectionType);
 1014  0
         if (validItems == null) {
 1015  0
             return false;
 1016  
         }
 1017  
         // See if there's a pair in this list that match the given
 1018  
         // model elements
 1019  0
         for (Class<?>[] modeElementPair : validItems) {
 1020  0
             if (modeElementPair[0].isInstance(fromElement)
 1021  
                     && modeElementPair[1].isInstance(toElement)) {
 1022  0
                 if (checkWFR) {
 1023  0
                     return isConnectionWellformed(
 1024  
                             (Class<?>) connectionType,
 1025  
                             (ModelElement) fromElement,
 1026  
                             (ModelElement) toElement);
 1027  
                 } else {
 1028  0
                     return true;
 1029  
                 }
 1030  
             }
 1031  
         }
 1032  0
         return false;
 1033  
     }
 1034  
     
 1035  
     public boolean isContainmentValid(Object metaType, Object container) {
 1036  
         
 1037  
         // find the passed in container in validContainmentMap
 1038  0
         for (Class<?> containerType : validContainmentMap.keySet()) {
 1039  
             
 1040  0
             if (containerType.isInstance(container)) {
 1041  
                 // determine if metaType is a valid element for container
 1042  0
                 Class<?>[] validElements = 
 1043  
                     validContainmentMap.get(containerType);
 1044  
                 
 1045  0
                 for (int eIter = 0; eIter < validElements.length; ++eIter) {
 1046  
                     
 1047  0
                     if (metaType == validElements[eIter]) {
 1048  0
                         return true;
 1049  
                     }
 1050  
                 }
 1051  0
             }
 1052  
         }
 1053  
         
 1054  0
         return false;
 1055  
     }
 1056  
     
 1057  
     /**
 1058  
      * Run through any well formedness rules we wish to enforce for a
 1059  
      * connection.
 1060  
      * @param connectionType
 1061  
      * @param fromElement
 1062  
      * @param toElement
 1063  
      * @return true if the connection satisfies the wellformedness rules
 1064  
      */
 1065  
     private boolean isConnectionWellformed(
 1066  
             Class<?> connectionType,
 1067  
             ModelElement fromElement,
 1068  
             ModelElement toElement) {
 1069  
         
 1070  0
         if (fromElement == null || toElement == null) {
 1071  0
             return false;
 1072  
         }
 1073  
             
 1074  0
         if (connectionType == Generalization.class) {
 1075  
             /*
 1076  
              * UML 1.4.2 Spec section 4.5.3.20 [5]
 1077  
              * A GeneralizableElement may only be a child of
 1078  
              * GeneralizableElement of the same kind.
 1079  
              */
 1080  0
             if (fromElement.getClass() != toElement.getClass()) {
 1081  0
                 return false;
 1082  
             }
 1083  
         }
 1084  
         
 1085  0
         return true;
 1086  
     }
 1087  
 
 1088  
     /**
 1089  
      * Returns the package factory for the UML package
 1090  
      * Foundation::ExtensionMechanisms.
 1091  
      *
 1092  
      * @return the ExtensionMechanisms factory instance.
 1093  
      */
 1094  
     private ExtensionMechanismsFactoryMDRImpl getExtensionMechanisms() {
 1095  0
         return (ExtensionMechanismsFactoryMDRImpl) modelImpl.
 1096  
                 getExtensionMechanismsFactory();
 1097  
     }
 1098  
 
 1099  
     /**
 1100  
      * Returns the package factory for the UML package Foundation::Core.
 1101  
      *
 1102  
      * @return the Core factory instance.
 1103  
      */
 1104  
     private CoreFactoryMDRImpl getCore() {
 1105  4
         return (CoreFactoryMDRImpl) modelImpl.getCoreFactory();
 1106  
     }
 1107  
 
 1108  
     /**
 1109  
      * Returns the package factory for the UML package
 1110  
      * BehavioralElements::CommonBehavior.
 1111  
      *
 1112  
      * @return the CommonBehavior factory instance.
 1113  
      */
 1114  
     private CommonBehaviorFactoryMDRImpl getCommonBehavior() {
 1115  0
         return (CommonBehaviorFactoryMDRImpl) modelImpl.
 1116  
                 getCommonBehaviorFactory();
 1117  
     }
 1118  
 
 1119  
     /**
 1120  
      * Returns the package factory for the UML package
 1121  
      * BehavioralElements::UseCases.
 1122  
      *
 1123  
      * @return the UseCases factory instance.
 1124  
      */
 1125  
     private UseCasesFactoryMDRImpl getUseCases() {
 1126  0
         return (UseCasesFactoryMDRImpl) modelImpl.getUseCasesFactory();
 1127  
     }
 1128  
 
 1129  
     /**
 1130  
      * Returns the package factory for the UML package
 1131  
      * BehavioralElements::StateMachines.
 1132  
      *
 1133  
      * @return the StateMachines factory instance.
 1134  
      */
 1135  
     private StateMachinesFactoryMDRImpl getStateMachines() {
 1136  4
         return (StateMachinesFactoryMDRImpl) modelImpl
 1137  
                 .getStateMachinesFactory();
 1138  
     }
 1139  
 
 1140  
     /**
 1141  
      * Returns the package factory for the UML package
 1142  
      * BehavioralElements::Collaborations.
 1143  
      *
 1144  
      * @return the Collaborations factory instance.
 1145  
      */
 1146  
     private CollaborationsFactoryMDRImpl getCollaborations() {
 1147  0
         return (CollaborationsFactoryMDRImpl) modelImpl.
 1148  
                 getCollaborationsFactory();
 1149  
     }
 1150  
 
 1151  
     /**
 1152  
      * Returns the package factory for the UML package
 1153  
      * BehavioralElements::ActivityGraphs.
 1154  
      *
 1155  
      * @return the ActivityGraphs factory instance.
 1156  
      */
 1157  
     private ActivityGraphsFactoryMDRImpl getActivityGraphs() {
 1158  0
         return (ActivityGraphsFactoryMDRImpl) modelImpl.
 1159  
                 getActivityGraphsFactory();
 1160  
     }
 1161  
 
 1162  
     /**
 1163  
      * Returns the package factory for the UML package ModelManagement.
 1164  
      *
 1165  
      * @return the ModelManagement factory instance.
 1166  
      */
 1167  
     private ModelManagementFactoryMDRImpl getModelManagement() {
 1168  0
         return (ModelManagementFactoryMDRImpl) modelImpl.
 1169  
                 getModelManagementFactory();
 1170  
     }
 1171  
 
 1172  
     /*
 1173  
      * Delete a model element.  Implements 'cascading delete' to make sure
 1174  
      * model is still valid after element has been deleted.<p>
 1175  
      *
 1176  
      * The actual deletion is delegated to delete methods in the rest of the
 1177  
      * factories. For example: a method deleteClass exists on CoreHelper. Delete
 1178  
      * methods as deleteClass should only do those extra actions that are
 1179  
      * necessary for the deletion of the modelelement itself. I.e. deleteClass
 1180  
      * should only take care of things specific to UmlClass.<p>
 1181  
      *
 1182  
      * The delete methods in the UML Factories should not be called directly
 1183  
      * throughout the code! Calls should always refer to this method and never
 1184  
      * call the deleteXXX method on XXXFactory directly. The reason that it is
 1185  
      * possible to call the deleteXXX methods directly is a pure implementation
 1186  
      * detail.<p>
 1187  
      *
 1188  
      * The implementation of this method uses a quite complicated if/then/else
 1189  
      * tree. This is done to provide optimal performance and full compliance to
 1190  
      * the UML 1.4 metamodel. The last remark refers to the fact that the
 1191  
      * UML 1.4 model uses multiple inheritance in several places.
 1192  
      * This has to be taken into account.<p>
 1193  
      *
 1194  
      * TODO: The requirements of the metamodel could probably be better
 1195  
      * determined by reflection on the metamodel.  Then each association
 1196  
      * that a deleted element participates in could be reviewed to make sure
 1197  
      * that it meets the requirements and, if not, be deleted. - tfm<p>
 1198  
      *
 1199  
      * Extensions and its children are not taken into account here. They do not
 1200  
      * require extra cleanup actions. Not in the form of a call to the remove
 1201  
      * method as is normal for all children of MBase and not in the form of
 1202  
      * other behaviour we want to implement via this operation.
 1203  
      *
 1204  
      * @param elem
 1205  
      *            The element to be deleted
 1206  
      *            
 1207  
      * @see org.argouml.model.UmlFactory#delete(java.lang.Object)
 1208  
      */
 1209  
     public void delete(Object elem) {
 1210  2
         if (elem == null) {
 1211  0
             throw new IllegalArgumentException("Element may not be null "
 1212  
                     + "in delete");
 1213  
         }
 1214  
 
 1215  
         // TODO: Hold lock for entire recursive traversal?
 1216  2
         synchronized (lock) {
 1217  2
             if (elementsToBeDeleted.contains(elem)) {
 1218  0
                 return;
 1219  
             }
 1220  2
             if (top == null) {
 1221  1
                 top = elem;
 1222  
             }
 1223  2
             elementsToBeDeleted.add((RefObject) elem);
 1224  2
         }
 1225  
 
 1226  2
         if (LOG.isDebugEnabled()) {
 1227  0
             if (top == elem) {
 1228  0
                 LOG.debug("Set top for cascade delete to " + elem);
 1229  
             }
 1230  0
             LOG.debug("Deleting " + elem);
 1231  
         }
 1232  
 
 1233  
         // Begin a transaction - we'll do a bunch of reads first
 1234  
         // to collect a set of elements to delete - then delete them all
 1235  2
         modelImpl.getRepository().beginTrans(false);
 1236  
         try {
 1237  
             // TODO: Encountering a deleted object during
 1238  
             // any part of this traversal will
 1239  
             // abort the rest of the traversal.
 1240  
             // We probably should do the whole traversal
 1241  
             // in a single MDR transaction.
 1242  2
             if (elem instanceof Element) {
 1243  2
                 getCore().deleteElement(elem);
 1244  2
                 if (elem instanceof ModelElement) {
 1245  2
                     getCore().deleteModelElement(elem);
 1246  
                     // no else here to make sure Classifier with
 1247  
                     // its double inheritance goes ok
 1248  
 
 1249  2
                     if (elem instanceof GeneralizableElement) {
 1250  0
                         GeneralizableElement ge = (GeneralizableElement) elem;
 1251  0
                         getCore().deleteGeneralizableElement(ge);
 1252  0
                         if (elem instanceof Stereotype) {
 1253  0
                             Stereotype s = (Stereotype) elem;
 1254  0
                             getExtensionMechanisms().deleteStereotype(s);
 1255  
                         }
 1256  
                     } // no else here to make sure AssociationClass goes ok
 1257  
 
 1258  2
                     if (elem instanceof Parameter) {
 1259  0
                         getCore().deleteParameter(elem);
 1260  2
                     } else if (elem instanceof Constraint) {
 1261  0
                         getCore().deleteConstraint(elem);
 1262  2
                     } else if (elem instanceof Relationship) {
 1263  0
                         deleteRelationship((Relationship) elem);
 1264  2
                     } else if (elem instanceof AssociationEnd) {
 1265  0
                         getCore().deleteAssociationEnd(elem);
 1266  0
                         if (elem instanceof AssociationEndRole) {
 1267  0
                             getCollaborations().deleteAssociationEndRole(elem);
 1268  
                         }
 1269  2
                     } else if (elem instanceof Comment) {
 1270  0
                         getCore().deleteComment(elem);
 1271  2
                     } else if (elem instanceof Action) {
 1272  0
                         deleteAction(elem);
 1273  2
                     } else if (elem instanceof AttributeLink) {
 1274  0
                         getCommonBehavior().deleteAttributeLink(elem);
 1275  2
                     } else if (elem instanceof Instance) {
 1276  0
                         deleteInstance((Instance) elem);
 1277  2
                     } else if (elem instanceof Stimulus) {
 1278  0
                         getCommonBehavior().deleteStimulus(elem);
 1279  
                     } // no else to handle multiple inheritance of linkobject
 1280  
 
 1281  2
                     if (elem instanceof Link) {
 1282  0
                         getCommonBehavior().deleteLink(elem);
 1283  2
                     } else if (elem instanceof LinkEnd) {
 1284  0
                         getCommonBehavior().deleteLinkEnd(elem);
 1285  2
                     } else if (elem instanceof Interaction) {
 1286  0
                         getCollaborations().deleteInteraction(elem);
 1287  2
                     } else if (elem instanceof InteractionInstanceSet) {
 1288  0
                         getCollaborations().deleteInteractionInstanceSet(elem);
 1289  2
                     } else if (elem instanceof CollaborationInstanceSet) {
 1290  0
                         getCollaborations()
 1291  
                                 .deleteCollaborationInstanceSet(elem);
 1292  2
                     } else if (elem instanceof Message) {
 1293  0
                         getCollaborations().deleteMessage(elem);
 1294  2
                     } else if (elem instanceof ExtensionPoint) {
 1295  0
                         getUseCases().deleteExtensionPoint(elem);
 1296  2
                     } else if (elem instanceof StateVertex) {
 1297  1
                         deleteStateVertex((StateVertex) elem);
 1298  
                     }
 1299  
 
 1300  2
                     if (elem instanceof StateMachine) {
 1301  1
                         getStateMachines().deleteStateMachine(elem);
 1302  1
                         if (elem instanceof ActivityGraph) {
 1303  0
                             getActivityGraphs().deleteActivityGraph(elem);
 1304  
                         }
 1305  1
                     } else if (elem instanceof Transition) {
 1306  0
                         getStateMachines().deleteTransition(elem);
 1307  1
                     } else if (elem instanceof Guard) {
 1308  0
                         getStateMachines().deleteGuard(elem);
 1309  1
                     } else if (elem instanceof TaggedValue) {
 1310  0
                         getExtensionMechanisms().deleteTaggedValue(elem);
 1311  1
                     } else if (elem instanceof TagDefinition) {
 1312  0
                         getExtensionMechanisms().deleteTagDefinition(elem);
 1313  
                     }
 1314  
                     // else if (elem instanceof MEvent) {
 1315  
                     //
 1316  
                     // }
 1317  0
                 } else if (elem instanceof PresentationElement) {
 1318  0
                     getCore().deletePresentationElement(elem);
 1319  
                 }
 1320  0
             } else if (elem instanceof TemplateParameter) {
 1321  0
                 getCore().deleteTemplateParameter(elem);
 1322  0
             } else if (elem instanceof TemplateArgument) {
 1323  0
                 getCore().deleteTemplateArgument(elem);
 1324  0
             } else if (elem instanceof ElementImport) {
 1325  0
                 getModelManagement().deleteElementImport(elem);
 1326  0
             } else if (elem instanceof ElementResidence) {
 1327  0
                 getCore().deleteElementResidence(elem);
 1328  
             } 
 1329  
 
 1330  2
             if (elem instanceof Partition) {
 1331  0
                 getActivityGraphs().deletePartition(elem);
 1332  
             }
 1333  
 
 1334  2
             if (elem instanceof Feature) {
 1335  0
                 deleteFeature((Feature) elem);
 1336  2
             } else if (elem instanceof Namespace) {
 1337  0
                 deleteNamespace((Namespace) elem);
 1338  
             }
 1339  0
         } catch (InvalidObjectException e) {
 1340  
             // If we get this with the repository locked, it means our root
 1341  
             // model element was already deleted.  Nothing to do...
 1342  0
             LOG.error("Encountered deleted object during delete of " + elem);
 1343  0
         } catch (InvalidElementException e) {
 1344  
             // Our wrapped version of the same error
 1345  0
             LOG.error("Encountered deleted object during delete of " + elem);
 1346  
         } finally {
 1347  
             // end our transaction
 1348  2
             modelImpl.getRepository().endTrans();
 1349  2
         }
 1350  
 
 1351  2
         synchronized (lock) {
 1352  
             // Elements which will be deleted when their container is deleted
 1353  
             // don't get added to the list of elements to be deleted
 1354  
             // (but we still want to traverse them looking for other elements
 1355  
             //  to be deleted)
 1356  
             try {
 1357  2
                 Object container = ((RefObject) elem).refImmediateComposite();
 1358  2
                 if (container == null
 1359  
                         || !elementsToBeDeleted.contains(container)
 1360  
                         // There is a bug in the version of MDR (20050711) that 
 1361  
                         // we use  that causes it to fail to delete aggregate 
 1362  
                         // elements which are single valued and where the 
 1363  
                         // aggregate end is listed second in the association
 1364  
                         // defined in the metamodel. For the UML 1.4 metamodel,
 1365  
                         // this affects a StateMachine's top StateVertex and
 1366  
                         // a Transition's Guard.  See issue 4948 & 5227 - tfm 
 1367  
                         // 20080713
 1368  
                         || (container instanceof StateMachine 
 1369  
                                 && elem instanceof StateVertex)
 1370  
                         || (container instanceof Transition 
 1371  
                                 && elem instanceof Guard)) {
 1372  2
                     elementsInDeletionOrder.add((RefObject) elem);
 1373  
                 }
 1374  0
             } catch (InvalidObjectException e) {
 1375  0
                 LOG.debug("Object already deleted " + elem);
 1376  2
             }
 1377  
 
 1378  2
             if (elem == top) {
 1379  1
                 for (RefObject o : elementsInDeletionOrder) {
 1380  
                     // TODO: This doesn't belong here, but it's not a good time
 1381  
                     // to move it.  Find someplace less obtrusive than this
 1382  
                     // inner loop. - tfm
 1383  2
                     if (o instanceof CompositeState) {
 1384  
                         // This enforces the following well-formedness rule.
 1385  
                         // <p>Well formedness rule 4.12.3.1 CompositeState
 1386  
                         // [4] There have to be at least two composite
 1387  
                         // substates in a concurrent composite state.<p>
 1388  
                         // If this is broken by deletion of substate then we
 1389  
                         // change the parent composite substate to be not
 1390  
                         // concurrent.
 1391  1
                         CompositeState deletedCompositeState = 
 1392  
                             (CompositeState) o;
 1393  
                         try {
 1394  1
                             CompositeState containingCompositeState =
 1395  
                                 deletedCompositeState.getContainer();
 1396  1
                             if (containingCompositeState != null
 1397  
                                     && containingCompositeState.
 1398  
                                     isConcurrent()
 1399  
                                     && containingCompositeState.getSubvertex().
 1400  
                                         size() == 1) {
 1401  0
                                 containingCompositeState.setConcurrent(false);
 1402  
                             }
 1403  0
                         } catch (InvalidObjectException e) {
 1404  0
                             LOG.debug("Object already deleted " + o);
 1405  1
                         }
 1406  
                     }
 1407  
                     try {
 1408  2
                         o.refDelete();
 1409  0
                     } catch (InvalidObjectException e) {
 1410  0
                         LOG.debug("Object already deleted " + o);
 1411  2
                     }
 1412  2
                     elementsToBeDeleted.remove(o);
 1413  
                 }
 1414  1
                 top = null;
 1415  1
                 elementsInDeletionOrder.clear();
 1416  1
                 if (!elementsToBeDeleted.isEmpty()) {
 1417  0
                     LOG.debug("**Skipped deleting "
 1418  
                             + elementsToBeDeleted.size()
 1419  
                             + " elements (probably in a deleted container");
 1420  0
                     elementsToBeDeleted.clear();
 1421  
                 }
 1422  
             }
 1423  2
         }
 1424  
         
 1425  2
         Model.execute(new DummyModelCommand());
 1426  2
     }
 1427  
 
 1428  
 
 1429  
     public boolean isRemoved(Object o) {
 1430  387148
         if (!(o instanceof RefObject)) {
 1431  0
             throw new IllegalArgumentException(
 1432  
                     "Expected JMI RefObject, received " + o);
 1433  
         }
 1434  
         try {
 1435  
             // We don't care about the value - just want to see if it throws
 1436  387148
             ((RefObject) o).refImmediateComposite();
 1437  387147
             return false;
 1438  1
         } catch (InvalidObjectException e) {
 1439  1
             return true;
 1440  
         }
 1441  
     }
 1442  
 
 1443  
     /**
 1444  
      * Delete a Feature.
 1445  
      *
 1446  
      * @param elem feature to be deleted
 1447  
      */
 1448  
     private void deleteFeature(Feature elem) {
 1449  0
         getCore().deleteFeature(elem);
 1450  0
         if (elem instanceof BehavioralFeature) {
 1451  0
             getCore().deleteBehavioralFeature(elem);
 1452  0
             if (elem instanceof Operation) {
 1453  0
                 getCore().deleteOperation(elem);
 1454  0
             } else if (elem instanceof Method) {
 1455  0
                 getCore().deleteMethod(elem);
 1456  0
             } else if (elem instanceof Reception) {
 1457  0
                 getCommonBehavior().deleteReception(elem);
 1458  
             }
 1459  0
         } else if (elem instanceof StructuralFeature) {
 1460  0
             getCore().deleteStructuralFeature(elem);
 1461  0
             if (elem instanceof Attribute) {
 1462  0
                 getCore().deleteAttribute(elem);
 1463  
             }
 1464  
         }
 1465  0
     }
 1466  
 
 1467  
     /**
 1468  
      * Delete a Namespace.
 1469  
      *
 1470  
      * @param elem namespace to be deleted
 1471  
      */
 1472  
     private void deleteNamespace(Namespace elem) {
 1473  0
         getCore().deleteNamespace(elem);
 1474  0
         if (elem instanceof Classifier) {
 1475  0
             getCore().deleteClassifier(elem);
 1476  0
             if (elem instanceof UmlClass) {
 1477  0
                 getCore().deleteClass(elem);
 1478  0
                 if (elem instanceof AssociationClass) {
 1479  0
                     getCore().deleteAssociationClass(elem);
 1480  
                 }
 1481  0
             } else if (elem instanceof Interface) {
 1482  0
                 getCore().deleteInterface(elem);
 1483  0
             } else if (elem instanceof DataType) {
 1484  0
                 getCore().deleteDataType(elem);
 1485  0
                 if (elem instanceof Primitive) {
 1486  0
                     getCore().deletePrimitive(elem);
 1487  0
                 } else if (elem instanceof Enumeration) {
 1488  
                     // TODO: Add EnumerationLiteral someplace
 1489  0
                     getCore().deleteEnumeration(elem);
 1490  0
                 } else if (elem instanceof ProgrammingLanguageDataType) {
 1491  0
                     getCore().deleteProgrammingLanguageDataType(elem);
 1492  
                 }
 1493  0
             } else if (elem instanceof Node) {
 1494  0
                 getCore().deleteNode(elem);
 1495  0
             } else if (elem instanceof Component) {
 1496  0
                 getCore().deleteComponent(elem);
 1497  0
             } else if (elem instanceof Artifact) {
 1498  0
                 getCore().deleteArtifact(elem);
 1499  0
             } else if (elem instanceof Signal) {
 1500  0
                 getCommonBehavior().deleteSignal(elem);
 1501  0
                 if (elem instanceof Exception) {
 1502  0
                     getCommonBehavior().deleteException(elem);
 1503  
                 }
 1504  0
             } else if (elem instanceof ClassifierRole) {
 1505  0
                 getCollaborations().deleteClassifierRole(elem);
 1506  0
             } else if (elem instanceof UseCase) {
 1507  0
                 getUseCases().deleteUseCase(elem);
 1508  0
             } else if (elem instanceof Actor) {
 1509  0
                 getUseCases().deleteActor(elem);
 1510  0
             } else if (elem instanceof ClassifierInState) {
 1511  0
                 getActivityGraphs().deleteClassifierInState(elem);
 1512  
             }
 1513  0
         } else if (elem instanceof Collaboration) {
 1514  0
             getCollaborations().deleteCollaboration(elem);
 1515  0
         } else if (elem instanceof UmlPackage) {
 1516  0
             getModelManagement().deletePackage(elem);
 1517  0
             if (elem instanceof org.omg.uml.modelmanagement.Model) {
 1518  0
                 getModelManagement().deleteModel(elem);
 1519  0
             } else if (elem instanceof Subsystem) {
 1520  0
                 getModelManagement().deleteSubsystem(elem);
 1521  
             }
 1522  
         }
 1523  0
     }
 1524  
 
 1525  
     /**
 1526  
      * Delete a Relationship.
 1527  
      *
 1528  
      * @param elem Relationship to be deleted
 1529  
      */
 1530  
     private void deleteRelationship(Relationship elem) {
 1531  0
         getCore().deleteRelationship(elem);
 1532  0
         if (elem instanceof Flow) {
 1533  0
             getCore().deleteFlow(elem);
 1534  0
         } else if (elem instanceof Generalization) {
 1535  0
             getCore().deleteGeneralization(elem);
 1536  0
         } else if (elem instanceof UmlAssociation) {
 1537  0
             getCore().deleteAssociation(elem);
 1538  0
             if (elem instanceof AssociationRole) {
 1539  0
                 getCollaborations().deleteAssociationRole(elem);
 1540  
             }
 1541  0
         } else if (elem instanceof Dependency) {
 1542  0
             getCore().deleteDependency(elem);
 1543  0
             if (elem instanceof Abstraction) {
 1544  0
                 getCore().deleteAbstraction(elem);
 1545  0
             } else if (elem instanceof Binding) {
 1546  0
                 getCore().deleteBinding(elem);
 1547  0
             } else if (elem instanceof Usage) {
 1548  0
                 getCore().deleteUsage(elem);
 1549  0
             } else if (elem instanceof Permission) {
 1550  0
                 getCore().deletePermission(elem);
 1551  
             }
 1552  0
         } else if (elem instanceof Include) {
 1553  0
             getUseCases().deleteInclude(elem);
 1554  0
         } else if (elem instanceof Extend) {
 1555  0
             getUseCases().deleteExtend(elem);
 1556  
         }
 1557  0
     }
 1558  
 
 1559  
     /**
 1560  
      * Delete an Action.
 1561  
      *
 1562  
      * @param elem the Action to be deleted
 1563  
      */
 1564  
     private void deleteAction(Object elem) {
 1565  0
         getCommonBehavior().deleteAction(elem);
 1566  0
         if (elem instanceof ActionSequence) {
 1567  0
             getCommonBehavior().deleteActionSequence(elem);
 1568  0
         } else if (elem instanceof CreateAction) {
 1569  0
             getCommonBehavior().deleteCreateAction(elem);
 1570  0
         } else if (elem instanceof CallAction) {
 1571  0
             getCommonBehavior().deleteCallAction(elem);
 1572  0
         } else if (elem instanceof ReturnAction) {
 1573  0
             getCommonBehavior().deleteReturnAction(elem);
 1574  0
         } else if (elem instanceof SendAction) {
 1575  0
             getCommonBehavior().deleteSendAction(elem);
 1576  0
         } else if (elem instanceof TerminateAction) {
 1577  0
             getCommonBehavior().deleteTerminateAction(elem);
 1578  0
         } else if (elem instanceof UninterpretedAction) {
 1579  0
             getCommonBehavior().deleteUninterpretedAction(elem);
 1580  0
         } else if (elem instanceof DestroyAction) {
 1581  0
             getCommonBehavior().deleteDestroyAction(elem);
 1582  
         }
 1583  0
     }
 1584  
 
 1585  
     /**
 1586  
      * Delete an Instance.
 1587  
      *
 1588  
      * @param elem the Instance to be deleted.
 1589  
      */
 1590  
     private void deleteInstance(Instance elem) {
 1591  0
         getCommonBehavior().deleteInstance(elem);
 1592  0
         if (elem instanceof DataValue) {
 1593  0
             getCommonBehavior().deleteDataValue(elem);
 1594  0
         } else if (elem instanceof ComponentInstance) {
 1595  0
             getCommonBehavior().deleteComponentInstance(elem);
 1596  0
         } else if (elem instanceof NodeInstance) {
 1597  0
             getCommonBehavior().deleteNodeInstance(elem);
 1598  0
         } else if (elem
 1599  
                 instanceof
 1600  
                 org.omg.uml.behavioralelements.commonbehavior.Object) {
 1601  0
             getCommonBehavior().deleteObject(elem);
 1602  0
             if (elem instanceof LinkObject) {
 1603  0
                 getCommonBehavior().deleteLinkObject(elem);
 1604  
             }
 1605  0
         } else if (elem instanceof SubsystemInstance) {
 1606  0
             getCommonBehavior().deleteSubsystemInstance(elem);
 1607  
         }
 1608  0
         if (elem instanceof UseCaseInstance) {
 1609  0
             getUseCases().deleteUseCaseInstance(elem);
 1610  
         }
 1611  0
     }
 1612  
 
 1613  
     /**
 1614  
      * Delete a StateVertex.
 1615  
      *
 1616  
      * @param elem the StateVertex to be deleted
 1617  
      */
 1618  
     private void deleteStateVertex(StateVertex elem) {
 1619  1
         getStateMachines().deleteStateVertex(elem);
 1620  1
         if (elem instanceof Pseudostate) {
 1621  0
             getStateMachines().deletePseudostate(elem);
 1622  1
         } else if (elem instanceof SynchState) {
 1623  0
             getStateMachines().deleteSynchState(elem);
 1624  1
         } else if (elem instanceof StubState) {
 1625  0
             getStateMachines().deleteStubState(elem);
 1626  1
         } else if (elem instanceof State) {
 1627  1
             getStateMachines().deleteState(elem);
 1628  1
             if (elem instanceof CompositeState) {
 1629  1
                 getStateMachines().deleteCompositeState(elem);
 1630  1
                 if (elem instanceof SubmachineState) {
 1631  0
                     getStateMachines().deleteSubmachineState(elem);
 1632  0
                     if (elem instanceof SubactivityState) {
 1633  0
                         getActivityGraphs().deleteSubactivityState(elem);
 1634  
                     }
 1635  
                 }
 1636  0
             } else if (elem instanceof SimpleState) {
 1637  0
                 getStateMachines().deleteSimpleState(elem);
 1638  0
                 if (elem instanceof ActionState) {
 1639  0
                     getActivityGraphs().deleteActionState(elem);
 1640  0
                     if (elem instanceof CallState) {
 1641  0
                         getActivityGraphs().deleteCallState(elem);
 1642  
                     }
 1643  0
                 } else if (elem instanceof ObjectFlowState) {
 1644  0
                     getActivityGraphs().deleteObjectFlowState(elem);
 1645  
                 }
 1646  0
             } else if (elem instanceof FinalState) {
 1647  0
                 getStateMachines().deleteFinalState(elem);
 1648  
             }
 1649  
         }
 1650  1
     }
 1651  
 
 1652  
     public void deleteExtent(Object element) {
 1653  
         try {
 1654  68
             org.omg.uml.UmlPackage extent = 
 1655  
                 (org.omg.uml.UmlPackage) ((RefObject) element)
 1656  
                     .refOutermostPackage();
 1657  68
             LOG.debug("Removing extent " + extent);
 1658  68
             modelImpl.deleteExtent(extent);
 1659  0
         } catch (InvalidObjectException e) {
 1660  0
             throw new InvalidElementException(e);
 1661  68
         }
 1662  68
     }
 1663  
     
 1664  
     public Collection getExtentPackages(String name) {
 1665  900
         org.omg.uml.UmlPackage pkg = modelImpl.getExtent(name);
 1666  900
         if (pkg == null) {
 1667  900
             return null;
 1668  
         }
 1669  0
         Collection<Object> packages = pkg.getModelManagement().getUmlPackage().
 1670  
             refAllOfType();
 1671  0
         Collection<Object> topLevelPackages = new ArrayList<Object>();
 1672  0
         for (Object pack : packages) {
 1673  0
             if (Model.getFacade().getNamespace(pack) == null) {
 1674  0
                 topLevelPackages.add(pack);
 1675  
             }
 1676  
         }
 1677  0
         return topLevelPackages;
 1678  
     }
 1679  
 
 1680  
 }