Coverage Report - org.argouml.model.mdr.StateMachinesFactoryMDRImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
StateMachinesFactoryMDRImpl
16%
46/272
8%
10/114
2.818
 
 1  
 /* $Id: StateMachinesFactoryMDRImpl.java 18451 2010-06-21 11:57:41Z mvw $
 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  
  *    tfmorris
 11  
  *    mvw
 12  
  *****************************************************************************
 13  
  *
 14  
  * Some portions of this file was previously release using the BSD License:
 15  
  */
 16  
 
 17  
 // Copyright (c) 1996-2008 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.Collection;
 43  
 
 44  
 import org.apache.log4j.Logger;
 45  
 import org.argouml.model.StateMachinesFactory;
 46  
 import org.omg.uml.behavioralelements.statemachines.CallEvent;
 47  
 import org.omg.uml.behavioralelements.statemachines.ChangeEvent;
 48  
 import org.omg.uml.behavioralelements.statemachines.CompositeState;
 49  
 import org.omg.uml.behavioralelements.statemachines.Event;
 50  
 import org.omg.uml.behavioralelements.statemachines.FinalState;
 51  
 import org.omg.uml.behavioralelements.statemachines.Guard;
 52  
 import org.omg.uml.behavioralelements.statemachines.Pseudostate;
 53  
 import org.omg.uml.behavioralelements.statemachines.SignalEvent;
 54  
 import org.omg.uml.behavioralelements.statemachines.SimpleState;
 55  
 import org.omg.uml.behavioralelements.statemachines.State;
 56  
 import org.omg.uml.behavioralelements.statemachines.StateMachine;
 57  
 import org.omg.uml.behavioralelements.statemachines.StateMachinesPackage;
 58  
 import org.omg.uml.behavioralelements.statemachines.StateVertex;
 59  
 import org.omg.uml.behavioralelements.statemachines.StubState;
 60  
 import org.omg.uml.behavioralelements.statemachines.SubmachineState;
 61  
 import org.omg.uml.behavioralelements.statemachines.SynchState;
 62  
 import org.omg.uml.behavioralelements.statemachines.TimeEvent;
 63  
 import org.omg.uml.behavioralelements.statemachines.Transition;
 64  
 import org.omg.uml.foundation.core.BehavioralFeature;
 65  
 import org.omg.uml.foundation.core.ModelElement;
 66  
 import org.omg.uml.foundation.core.Namespace;
 67  
 import org.omg.uml.foundation.core.Operation;
 68  
 import org.omg.uml.foundation.core.UmlClass;
 69  
 import org.omg.uml.foundation.datatypes.BooleanExpression;
 70  
 import org.omg.uml.foundation.datatypes.PseudostateKindEnum;
 71  
 import org.omg.uml.foundation.datatypes.TimeExpression;
 72  
 
 73  
 /**
 74  
  * Factory to create UML classes for the UML BehaviorialElements::StateMachines
 75  
  * package.<p>
 76  
  *
 77  
  * Abstract metatypes from the UML metamodel do not have create methods.<p>
 78  
  *
 79  
  * @since ARGO0.19.3
 80  
  * @author Bob Tarling
 81  
  * @author Ludovic Ma&icirc;tre
 82  
  * @author Tom Morris
 83  
  */
 84  997
 class StateMachinesFactoryMDRImpl extends AbstractUmlModelFactoryMDR
 85  
         implements StateMachinesFactory {
 86  
 
 87  
     /**
 88  
      * Logger
 89  
      */
 90  900
     private Logger LOG = Logger.getLogger(StateMachinesFactoryMDRImpl.class);
 91  
         
 92  
     /**
 93  
      * The model implementation.
 94  
      */
 95  
     private MDRModelImplementation modelImpl;
 96  
 
 97  
     /**
 98  
      * Package-private constructor.
 99  
      *
 100  
      * @param implementation
 101  
      *            To get other helpers and factories.
 102  
      */
 103  900
     StateMachinesFactoryMDRImpl(MDRModelImplementation implementation) {
 104  900
         modelImpl = implementation;
 105  900
     }
 106  
     
 107  
     private StateMachinesPackage getSmPackage() {
 108  97
         return modelImpl.getUmlPackage().getStateMachines();
 109  
     }
 110  
 
 111  
 
 112  
     public CallEvent createCallEvent() {
 113  0
         CallEvent myCallEvent = getSmPackage().getCallEvent().createCallEvent();
 114  0
         super.initialize(myCallEvent);
 115  0
         return myCallEvent;
 116  
     }
 117  
 
 118  
 
 119  
     public ChangeEvent createChangeEvent() {
 120  0
         ChangeEvent myChangeEvent = getSmPackage().getChangeEvent()
 121  
                 .createChangeEvent();
 122  0
         super.initialize(myChangeEvent);
 123  0
         return myChangeEvent;
 124  
     }
 125  
 
 126  
 
 127  
     public CompositeState createCompositeState() {
 128  58
         CompositeState myCompositeState = getSmPackage().getCompositeState()
 129  
                 .createCompositeState();
 130  58
         super.initialize(myCompositeState);
 131  58
         return myCompositeState;
 132  
     }
 133  
 
 134  
 
 135  
     public FinalState createFinalState() {
 136  0
         FinalState myFinalState = getSmPackage().getFinalState().createFinalState();
 137  0
         super.initialize(myFinalState);
 138  0
         return myFinalState;
 139  
     }
 140  
 
 141  
 
 142  
     public Guard createGuard() {
 143  0
         Guard myGuard = getSmPackage().getGuard().createGuard();
 144  0
         super.initialize(myGuard);
 145  0
         return myGuard;
 146  
     }
 147  
 
 148  
 
 149  
     public Pseudostate createPseudostate() {
 150  0
         Pseudostate myPseudostate = getSmPackage().getPseudostate()
 151  
                 .createPseudostate();
 152  0
         super.initialize(myPseudostate);
 153  0
         return myPseudostate;
 154  
     }
 155  
 
 156  
 
 157  
     public SignalEvent createSignalEvent() {
 158  0
         SignalEvent mySignalEvent = getSmPackage().getSignalEvent()
 159  
                 .createSignalEvent();
 160  0
         super.initialize(mySignalEvent);
 161  0
         return mySignalEvent;
 162  
     }
 163  
 
 164  
 
 165  
     public SimpleState createSimpleState() {
 166  0
         SimpleState mySimpleState = getSmPackage().getSimpleState()
 167  
                 .createSimpleState();
 168  0
         super.initialize(mySimpleState);
 169  0
         return mySimpleState;
 170  
     }
 171  
 
 172  
 
 173  
     public StateMachine createStateMachine() {
 174  39
         StateMachine myStateMachine = getSmPackage().getStateMachine()
 175  
                 .createStateMachine();
 176  39
         super.initialize(myStateMachine);
 177  39
         return myStateMachine;
 178  
     }
 179  
 
 180  
 
 181  
     public StubState createStubState() {
 182  0
         StubState myStubState = getSmPackage().getStubState().createStubState();
 183  0
         super.initialize(myStubState);
 184  0
         return myStubState;
 185  
     }
 186  
 
 187  
 
 188  
     public SubmachineState createSubmachineState() {
 189  0
         SubmachineState mySubmachineState = getSmPackage().getSubmachineState()
 190  
                 .createSubmachineState();
 191  0
         super.initialize(mySubmachineState);
 192  0
         return mySubmachineState;
 193  
     }
 194  
 
 195  
 
 196  
     public SynchState createSynchState() {
 197  0
         SynchState mySynchState = getSmPackage().getSynchState().createSynchState();
 198  0
         super.initialize(mySynchState);
 199  0
         return mySynchState;
 200  
     }
 201  
 
 202  
 
 203  
     public TimeEvent createTimeEvent() {
 204  0
         TimeEvent myTimeEvent = getSmPackage().getTimeEvent().createTimeEvent();
 205  0
         super.initialize(myTimeEvent);
 206  0
         return myTimeEvent;
 207  
     }
 208  
 
 209  
 
 210  
     public Transition createTransition() {
 211  0
         Transition myTransition = getSmPackage().getTransition().createTransition();
 212  0
         super.initialize(myTransition);
 213  0
         return myTransition;
 214  
     }
 215  
 
 216  
 
 217  
     public CompositeState buildCompositeStateOnStateMachine(
 218  
             Object statemachine) {
 219  58
         if (statemachine instanceof StateMachine) {
 220  58
             StateMachine sm = (StateMachine) statemachine;
 221  58
             CompositeState top = createCompositeState();
 222  58
             top.setStateMachine(sm);
 223  58
             top.setName("top");
 224  58
             sm.setTop(top);
 225  58
             assert top.equals(sm.getTop());
 226  58
             return top;
 227  
         }
 228  0
         throw new IllegalArgumentException("statemachine");
 229  
     }
 230  
 
 231  
 
 232  
     public StateMachine buildStateMachine(Object oContext) {
 233  0
         if (oContext != null
 234  
                 && (modelImpl.getStateMachinesHelper().
 235  
                         isAddingStatemachineAllowed(oContext))) {
 236  
             
 237  0
             StateMachine machine = createStateMachine();
 238  0
             ModelElement modelelement = (ModelElement) oContext;
 239  0
             machine.setContext(modelelement);
 240  
             
 241  0
             if (modelelement instanceof BehavioralFeature) {
 242  0
                 modelelement = ((BehavioralFeature) modelelement).getOwner();
 243  
             }
 244  0
             if (modelelement instanceof Namespace) {
 245  0
                 Namespace namespace = (Namespace) modelelement;
 246  
                 /* Follow well-formedness rule for a Class [2].
 247  
                  * See issue 4282. Do not use a class 
 248  
                  * as the namespace for a statemachine: */
 249  0
                 while (namespace instanceof UmlClass) {
 250  0
                     Namespace pns = namespace.getNamespace();
 251  0
                     if (pns == null) break;
 252  0
                     namespace = pns;
 253  0
                 }
 254  0
                 machine.setNamespace(namespace);
 255  
             }
 256  
 
 257  0
             State top = buildCompositeStateOnStateMachine(machine);
 258  0
             assert top.equals(machine.getTop());
 259  0
             return machine;
 260  
         }
 261  0
         throw new IllegalArgumentException("In buildStateMachine: "
 262  
                 + "context null or not legal");
 263  
     }
 264  
 
 265  
 
 266  
     public Transition buildTransition(Object owningState, Object source, 
 267  
             Object dest) {
 268  0
         if (!(owningState instanceof CompositeState)) {
 269  0
             throw new IllegalArgumentException("owningState");
 270  
         }
 271  0
         if (!(source instanceof StateVertex)) {
 272  0
             throw new IllegalArgumentException("source");
 273  
         }
 274  0
         if (!(dest instanceof StateVertex)) {
 275  0
             throw new IllegalArgumentException("dest");
 276  
         }
 277  
 
 278  0
         CompositeState compositeState = (CompositeState) owningState;
 279  0
         if (compositeState.getSubvertex().contains(source)
 280  
                 && compositeState.getSubvertex().contains(dest)) {
 281  0
                 Transition trans = createTransition();
 282  0
                 compositeState.getInternalTransition().add(trans);
 283  0
                 trans.setSource((StateVertex) source);
 284  0
                 trans.setTarget((StateVertex) dest);
 285  0
                 return trans;
 286  
 
 287  
               }
 288  0
         throw new IllegalArgumentException("In buildTransition: "
 289  
                 + "arguments not legal");
 290  
     }
 291  
 
 292  
 
 293  
     public Pseudostate buildPseudoState(Object compositeState) {
 294  0
         if (compositeState instanceof CompositeState) {
 295  0
             Pseudostate state = createPseudostate();
 296  0
             state.setKind(PseudostateKindEnum.PK_CHOICE);
 297  0
             state.setContainer((CompositeState) compositeState);
 298  0
             ((CompositeState) compositeState).getSubvertex().add(state);
 299  0
             return state;
 300  
         }
 301  0
         throw new IllegalArgumentException(
 302  
                 "Argument must be a CompositeState");
 303  
     }
 304  
 
 305  
 
 306  
     public SynchState buildSynchState(Object compositeState) {
 307  0
         if (compositeState instanceof CompositeState) {
 308  0
             SynchState state = createSynchState();
 309  0
             state.setBound(0);
 310  0
             state.setContainer((CompositeState) compositeState);
 311  0
             return state;
 312  
         }
 313  0
         throw new IllegalArgumentException(
 314  
                 "Argument must be a CompositeState");
 315  
     }
 316  
 
 317  
 
 318  
     public StubState buildStubState(Object compositeState) {
 319  0
         if (compositeState instanceof CompositeState) {
 320  0
             StubState state = createStubState();
 321  0
             state.setReferenceState("");
 322  0
             state.setContainer((CompositeState) compositeState);
 323  0
             return state;
 324  
         }
 325  0
         throw new IllegalArgumentException(
 326  
                 "Argument must be a CompositeState");
 327  
     }
 328  
 
 329  
 
 330  
     public CompositeState buildCompositeState(Object compositeState) {
 331  0
         if (compositeState instanceof CompositeState) {
 332  0
             CompositeState state = createCompositeState();
 333  0
             state.setConcurrent(false);
 334  0
             state.setContainer((CompositeState) compositeState);
 335  0
             return state;
 336  
         }
 337  0
         throw new IllegalArgumentException(
 338  
                 "Argument must be a CompositeState");
 339  
     }
 340  
 
 341  
 
 342  
     public SimpleState buildSimpleState(Object compositeState) {
 343  0
         if (compositeState instanceof CompositeState) {
 344  0
             SimpleState state = createSimpleState();
 345  0
             state.setContainer((CompositeState) compositeState);
 346  0
             return state;
 347  
         }
 348  0
         throw new IllegalArgumentException(
 349  
                 "Argument must be a CompositeState");
 350  
     }
 351  
 
 352  
 
 353  
     public FinalState buildFinalState(Object compositeState) {
 354  0
         if (compositeState instanceof CompositeState) {
 355  0
             FinalState state = createFinalState();
 356  0
             state.setContainer((CompositeState) compositeState);
 357  0
             return state;
 358  
         }
 359  0
         throw new IllegalArgumentException(
 360  
                 "Argument must be a CompositeState");
 361  
     }
 362  
 
 363  
 
 364  
     public SubmachineState buildSubmachineState(Object compositeState) {
 365  0
         if (compositeState instanceof CompositeState) {
 366  0
             SubmachineState state = createSubmachineState();
 367  0
             state.setContainer((CompositeState) compositeState);
 368  0
             return state;
 369  
         }
 370  0
         throw new IllegalArgumentException(
 371  
                 "Argument must be a CompositeState");
 372  
     }
 373  
 
 374  
 
 375  
     public Transition buildInternalTransition(Object state) {
 376  0
         if (state instanceof State) {
 377  0
             Transition trans = createTransition();
 378  0
             ((State) state).getInternalTransition().add(trans);
 379  0
             trans.setSource((State) state);
 380  0
             trans.setTarget((State) state);
 381  0
             return trans;
 382  
         }
 383  0
         throw new IllegalArgumentException("Argument must be a State");    
 384  
     }
 385  
 
 386  
 
 387  
     public Transition buildTransition(Object source, Object target) {
 388  0
         if (source instanceof StateVertex && target instanceof StateVertex) {
 389  0
             Transition trans = createTransition();
 390  0
             trans.setSource((StateVertex) source);
 391  0
             trans.setTarget((StateVertex) target);
 392  0
             trans.setStateMachine((StateMachine) modelImpl.
 393  
                     getStateMachinesHelper().getStateMachine(source));
 394  0
             return trans;
 395  
         }
 396  0
         throw new IllegalArgumentException();
 397  
     }
 398  
 
 399  
 
 400  
     public CallEvent buildCallEvent(Object ns) {
 401  0
         CallEvent event = createCallEvent();
 402  0
         event.setNamespace((Namespace) ns);
 403  0
         event.setName("");
 404  0
         return event;
 405  
     }
 406  
 
 407  
 
 408  
     public CallEvent buildCallEvent(Object trans, String name, Object ns) {
 409  0
         if (!(trans instanceof Transition)) {
 410  0
             throw new IllegalArgumentException();
 411  
         }
 412  0
         CallEvent evt = createCallEvent();
 413  0
         evt.setNamespace((Namespace) ns);
 414  
 
 415  0
         String operationName = (name.indexOf("(") > 0) ? name.substring(0,
 416  
                 name.indexOf("(")).trim() : name.trim();
 417  0
         evt.setName(operationName);
 418  0
         Object op = modelImpl.getStateMachinesHelper().findOperationByName(
 419  
                 trans, operationName);
 420  0
         if (op != null) {
 421  0
             evt.setOperation((Operation) op);
 422  
         }
 423  0
         return evt;        
 424  
     }
 425  
 
 426  
 
 427  
     public SignalEvent buildSignalEvent(Object ns) {
 428  0
         SignalEvent event = createSignalEvent();
 429  0
         event.setNamespace((Namespace) ns);
 430  0
         event.setName("");
 431  0
         return event;
 432  
     }
 433  
 
 434  
 
 435  
     public SignalEvent buildSignalEvent(String name, Object ns) {
 436  0
         SignalEvent event = createSignalEvent();
 437  0
         event.setNamespace((Namespace) ns);
 438  0
         event.setName(name);
 439  0
         return event;
 440  
     }
 441  
 
 442  
 
 443  
     public TimeEvent buildTimeEvent(Object ns) {
 444  0
         TimeEvent event = createTimeEvent();
 445  0
         event.setNamespace((Namespace) ns);
 446  0
         event.setName("");
 447  0
         return event;
 448  
     }
 449  
 
 450  
 
 451  
     public TimeEvent buildTimeEvent(String s, Object ns) {
 452  0
         TimeEvent event = createTimeEvent();
 453  0
         event.setNamespace((Namespace) ns);
 454  0
         event.setName("");
 455  0
         Object te = modelImpl.getDataTypesFactory().createTimeExpression("", s);
 456  0
         event.setWhen((TimeExpression) te);
 457  0
         return event;
 458  
     }
 459  
 
 460  
 
 461  
     public ChangeEvent buildChangeEvent(Object ns) {
 462  0
         ChangeEvent event =  createChangeEvent();
 463  0
         event.setNamespace((Namespace) ns);
 464  0
         event.setName("");
 465  0
         return event;
 466  
     }
 467  
 
 468  
 
 469  
     public ChangeEvent buildChangeEvent(String expression, Object ns) {
 470  0
         ChangeEvent event = buildChangeEvent(ns);
 471  0
         Object ce = modelImpl.getDataTypesFactory()
 472  
                 .createBooleanExpression("", expression);
 473  0
         event.setChangeExpression((BooleanExpression) ce);
 474  0
         return event;
 475  
     }
 476  
 
 477  
 
 478  
     public Guard buildGuard(Object transition) {
 479  0
         if (transition instanceof Transition) {
 480  0
             Transition t = (Transition) transition;
 481  0
             if (t.getGuard() != null) {
 482  0
                 LOG.warn("Replacing Guard " + t.getGuard().getName() 
 483  
                         + " on Transition " + t.getName());
 484  
             }
 485  0
             Guard guard = createGuard();
 486  0
             guard.setTransition((Transition) transition);
 487  0
             return guard;
 488  
         }
 489  0
         throw new IllegalArgumentException("transition: " + transition);
 490  
     }
 491  
 
 492  
     /**
 493  
      * @param elem
 494  
      *            the UML element to be deleted
 495  
      */
 496  
     void deleteCallEvent(Object elem) {
 497  0
         if (!(elem instanceof CallEvent)) {
 498  0
             throw new IllegalArgumentException();
 499  
         }
 500  0
     }
 501  
 
 502  
     /**
 503  
      * @param elem
 504  
      *            the UML element to be deleted
 505  
      */
 506  
     void deleteChangeEvent(Object elem) {
 507  0
         if (!(elem instanceof ChangeEvent)) {
 508  0
             throw new IllegalArgumentException();
 509  
         }
 510  0
     }
 511  
 
 512  
     /**
 513  
      * Deletes any associated subVertices.
 514  
      * 
 515  
      * This also enforces the following well-formedness rule.
 516  
      * <p>Well formedness rule 4.12.3.1 CompositeState
 517  
      * [4] There have to be at least two composite substates in a
 518  
      * concurrent composite state.<p>
 519  
      * If this is broken by deletion of substate then we delete the other
 520  
      * remaining substate and convert the composite state to non-concurrent
 521  
      *
 522  
      * @param elem
 523  
      *            the UML element to be deleted
 524  
      */
 525  
     void deleteCompositeState(Object elem) {
 526  1
         if (!(elem instanceof CompositeState)) {
 527  0
             throw new IllegalArgumentException();
 528  
         }
 529  
 
 530  1
         final CompositeState compositeState = (CompositeState) elem;
 531  1
         for (StateVertex vertex : compositeState.getSubvertex()) {
 532  0
             modelImpl.getUmlFactory().delete(vertex);
 533  
         }
 534  
         
 535  1
         final CompositeState containingCompositeState = 
 536  
             compositeState.getContainer();
 537  
                 
 538  
         // Well formedness rule 4.12.3.1 CompositeState
 539  
         // [4] There have to be at least two composite substates in a
 540  
         // concurrent composite state.
 541  
         // If this is broken by deletion of substate then we delete the other
 542  
         // remaining substates.
 543  1
         if (containingCompositeState != null
 544  
                 && containingCompositeState.isConcurrent()) {
 545  0
             final Collection<StateVertex> siblings =
 546  
                 containingCompositeState.getSubvertex();
 547  
             
 548  0
             final int substatesRemaining = siblings.size();
 549  0
             if (substatesRemaining == 2) {
 550  0
                 for (StateVertex sibling : siblings) {
 551  0
                     if (sibling != compositeState) {
 552  0
                         modelImpl.getUmlFactory().delete(sibling);
 553  
                     }
 554  
                 }
 555  
             }
 556  
         }
 557  1
     }
 558  
 
 559  
     /**
 560  
      * @param elem
 561  
      *            the UML element to be deleted
 562  
      */
 563  
     void deleteEvent(Object elem) {
 564  0
         if (!(elem instanceof Event)) {
 565  0
             throw new IllegalArgumentException();
 566  
         }
 567  0
     }
 568  
 
 569  
     /**
 570  
      * @param elem
 571  
      *            the UML element to be deleted
 572  
      */
 573  
     void deleteFinalState(Object elem) {
 574  0
         if (!(elem instanceof FinalState)) {
 575  0
             throw new IllegalArgumentException();
 576  
         }
 577  0
     }
 578  
 
 579  
     /**
 580  
      * @param elem
 581  
      *            the UML element to be deleted
 582  
      */
 583  
     void deleteGuard(Object elem) {
 584  0
         if (!(elem instanceof Guard)) {
 585  0
             throw new IllegalArgumentException();
 586  
         }
 587  0
     }
 588  
 
 589  
     /**
 590  
      * @param elem
 591  
      *            the UML element to be deleted
 592  
      */
 593  
     void deletePseudostate(Object elem) {
 594  0
         if (!(elem instanceof Pseudostate)) {
 595  0
             throw new IllegalArgumentException();
 596  
         }
 597  0
     }
 598  
 
 599  
     /**
 600  
      * @param elem
 601  
      *            the UML element to be deleted
 602  
      */
 603  
     void deleteSignalEvent(Object elem) {
 604  0
         if (!(elem instanceof SignalEvent)) {
 605  0
             throw new IllegalArgumentException();
 606  
         }
 607  0
     }
 608  
 
 609  
     /**
 610  
      * @param elem
 611  
      *            the UML element to be deleted
 612  
      */
 613  
     void deleteState(Object elem) {
 614  1
         if (!(elem instanceof State)) {
 615  0
             throw new IllegalArgumentException();
 616  
         }
 617  1
         State state = (State) elem;
 618  1
         deleteNonNull(state.getDoActivity());
 619  1
         deleteNonNull(state.getEntry());
 620  1
         deleteNonNull(state.getExit());
 621  1
         modelImpl.getUmlHelper().deleteCollection(
 622  
                 state.getInternalTransition());
 623  
 
 624  1
     }
 625  
 
 626  
     private void deleteNonNull(ModelElement action) {
 627  3
         if (action != null) {
 628  0
             modelImpl.getUmlFactory().delete(action);
 629  
         }
 630  3
     }
 631  
     
 632  
     /**
 633  
      * @param elem
 634  
      *            the UML element to be deleted
 635  
      */
 636  
     void deleteSimpleState(Object elem) {
 637  0
         if (!(elem instanceof SimpleState)) {
 638  0
             throw new IllegalArgumentException();
 639  
         }
 640  0
     }
 641  
 
 642  
     /**
 643  
      * deletes its top state, which is a composite state (state vertex).
 644  
      * Delete any submachine states which depend on this StateMachine.
 645  
      *
 646  
      * @param elem
 647  
      *            the state machine to be removed.
 648  
      */
 649  
     void deleteStateMachine(Object elem) {
 650  1
         if (!(elem instanceof StateMachine)) {
 651  0
             throw new IllegalArgumentException();
 652  
         }
 653  1
         StateMachine stateMachine = (StateMachine) elem;
 654  
         
 655  
         // This shouldn't be required since it's a composite, but there's
 656  
         // a bug in the version of MDR that we use (20050711) that causes
 657  
         // it to fail to delete aggregate elements which are single valued
 658  
         // and where the aggregate end is listed second in the association
 659  
         // defined in the metamodel. - tfm 20080713
 660  1
         State top = stateMachine.getTop();
 661  1
         if (top != null) {
 662  1
             modelImpl.getUmlFactory().delete(top);
 663  
         }
 664  
         
 665  1
         modelImpl.getUmlHelper().deleteCollection(
 666  
                 stateMachine.getSubmachineState());
 667  1
     }
 668  
 
 669  
     /**
 670  
      * Deletes the outgoing and incoming transitions of a statevertex.
 671  
      * <p>
 672  
      *
 673  
      * @param elem
 674  
      *            the UML element to be deleted
 675  
      */
 676  
     void deleteStateVertex(Object elem) {
 677  1
         if (!(elem instanceof StateVertex)) {
 678  0
             throw new IllegalArgumentException();
 679  
         }
 680  
 
 681  1
         modelImpl.getUmlHelper().deleteCollection(
 682  
                 ((StateVertex) elem).getIncoming());
 683  1
         modelImpl.getUmlHelper().deleteCollection(
 684  
                 ((StateVertex) elem).getOutgoing());
 685  
 
 686  1
     }
 687  
 
 688  
     /**
 689  
      * @param elem
 690  
      *            the UML element to be deleted
 691  
      */
 692  
     void deleteStubState(Object elem) {
 693  0
         if (!(elem instanceof StubState)) {
 694  0
             throw new IllegalArgumentException();
 695  
         }
 696  
 
 697  0
     }
 698  
 
 699  
     /**
 700  
      * @param elem
 701  
      *            the UML element to be deleted
 702  
      */
 703  
     void deleteSubmachineState(Object elem) {
 704  0
         if (!(elem instanceof SubmachineState)) {
 705  0
             throw new IllegalArgumentException();
 706  
         }
 707  
 
 708  0
     }
 709  
 
 710  
     /**
 711  
      * @param elem
 712  
      *            the UML element to be deleted
 713  
      */
 714  
     void deleteSynchState(Object elem) {
 715  0
         if (!(elem instanceof SynchState)) {
 716  0
             throw new IllegalArgumentException();
 717  
         }
 718  0
     }
 719  
 
 720  
     /**
 721  
      * @param elem
 722  
      *            the UML element to be deleted
 723  
      */
 724  
     void deleteTimeEvent(Object elem) {
 725  0
         if (!(elem instanceof TimeEvent)) {
 726  0
             throw new IllegalArgumentException();
 727  
         }
 728  0
     }
 729  
 
 730  
     /**
 731  
      * @param elem
 732  
      *            the UML element to be deleted
 733  
      */
 734  
     void deleteTransition(Object elem) {
 735  0
         if (!(elem instanceof Transition)) {
 736  0
             throw new IllegalArgumentException();
 737  
         }
 738  
         
 739  0
         final Transition transition = (Transition) elem;
 740  0
         final Guard guard = transition.getGuard();
 741  0
         if (guard != null) {
 742  
             // This shouldn't be required since it's a composite, but there's
 743  
             // a bug in the version of MDR that we use (20050711) that causes
 744  
             // it to fail to delete aggregate elements which are single valued
 745  
             // and where the aggregate end is listed second in the association
 746  
             // defined in the metamodel. - tfm 20080713
 747  0
             modelImpl.getUmlFactory().delete(guard);
 748  
         }
 749  
         
 750  
         // The effect will get deleted automatically by MDR, unlike the Guard.
 751  0
     }
 752  
 
 753  
 }
 754