svn commit: r14376 - trunk/src/model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2008-04-17 16:50:26-0700
New Revision: 14376

Modified:
   trunk/src/model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java

Log:
issue 4948 - add special case to delete top CompositeState of a StateMachine

Modified: trunk/src/model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java?view=diff&rev=14376&p1=trunk/src/model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java&p2=trunk/src/model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java&r1=14375&r2=14376
==============================================================================
--- trunk/src/model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java	(original)
+++ trunk/src/model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java	2008-04-17 16:50:26-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-2008 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -177,12 +177,13 @@
     /**
      * The instance that we are deleting.
      */
-    private Set elementsToBeDeleted = new HashSet();
+    private Set<RefObject> elementsToBeDeleted = new HashSet<RefObject>();
 
     /**
      * Ordered list of elements to be deleted.
      */
-    private List elementsInDeletionOrder = new ArrayList();
+    private List<RefObject> elementsInDeletionOrder = 
+        new ArrayList<RefObject>();
 
     /**
      * The top object is the first object given to the UmlFactory when calling
@@ -665,7 +666,7 @@
             if (top == null) {
                 top = elem;
             }
-            elementsToBeDeleted.add(elem);
+            elementsToBeDeleted.add((RefObject) elem);
         }
 
         if (LOG.isDebugEnabled()) {
@@ -675,9 +676,9 @@
             LOG.debug("Deleting " + elem);
         }
 
-        // Begin a write transaction - we'll do a bunch of reads first
+        // Begin a transaction - we'll do a bunch of reads first
         // to collect a set of elements to delete - then delete them all
-        modelImpl.getRepository().beginTrans(true);
+        modelImpl.getRepository().beginTrans(false);
         try {
             // TODO: Encountering a deleted object during
             // any part of this traversal will
@@ -789,7 +790,7 @@
             // Our wrapped version of the same error
             LOG.error("Encountered deleted object during delete of " + elem);
         } finally {
-            // Commit our transacation
+            // end our transaction
             modelImpl.getRepository().endTrans();
         }
 
@@ -803,17 +804,20 @@
             try {
                 Object container = ((RefObject) elem).refImmediateComposite();
                 if (container == null
-                        || !elementsToBeDeleted.contains(container)) {
-                    elementsInDeletionOrder.add(elem);
+                        || !elementsToBeDeleted.contains(container)
+                        // For some reason StateMachine.top doesn't get deleted
+                        // even though it should because it's a composite
+                        // see issue 4948
+                        || (container instanceof StateMachine 
+                                && elem instanceof StateVertex)) {
+                    elementsInDeletionOrder.add((RefObject) elem);
                 }
             } catch (InvalidObjectException e) {
                 LOG.warn("Object already deleted " + elem);
             }
 
             if (elem == top) {
-                Iterator itDelete = elementsInDeletionOrder.iterator();
-                while (itDelete.hasNext()) {
-                    RefObject o = ((RefObject) itDelete.next());
+                for (RefObject o : elementsInDeletionOrder) {
                     try {
                         o.refDelete();
                     } catch (InvalidObjectException e) {
@@ -824,9 +828,9 @@
                 top = null;
                 elementsInDeletionOrder.clear();
                 if (!elementsToBeDeleted.isEmpty()) {
-                    LOG.debug("**Skipped deleting (a 2nd time?) "
+                    LOG.debug("**Skipped deleting "
                             + elementsToBeDeleted.size()
-                            + " elements");
+                            + " elements (probably in a deleted container");
                     elementsToBeDeleted.clear();
                 }
             }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.