svn commit: r18282 - trunk/src: argouml-app/src/org/argouml/profile argouml-core-model-euml/src/org/argouml/model/euml argouml-core-model-mdr/src/org/argouml/model/mdr argouml-core-model/src/org/argouml/model

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2010-04-18 01:50:37-0700
New Revision: 18282

Modified:
   trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java
   trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java
   trunk/src/argouml-core-model/src/org/argouml/model/ModelImplementation.java
   trunk/src/argouml-core-model/src/org/argouml/model/UmlFactory.java

Log:
REOPENED - task 6008: Check for profile XMI in repository before attempting to load it to deal with cases where profile was loaded implicitly first, then explicitly later

Modified: trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java?view=diff&pathrev=18282&r1=18281&r2=18282
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java	2010-04-18 01:50:37-0700
@@ -58,10 +58,15 @@
 public class URLModelLoader implements ProfileModelLoader {
 
     /**
+     * Load a profile from a URL.  If a profile with the same public ID has 
+     * already been loaded, its contents are returned instead of loading the
+     * new profile.
+     * 
      * @param url the url/system id to load
      * @param publicId the publicId for which the model will be known - must be
      *                equal in different machines in order to be possible to
-     *                load the model.
+     *                load the model.  If a profile with this public ID has 
+     *                already been loaded, it is returned instead.
      * @return a collection of top level elements in the profile (usually a
      *         single package stereotyped <<profile>>
      * @throws ProfileException if the XMIReader couldn't read the profile
@@ -71,29 +76,33 @@
         if (url == null) {
             throw new ProfileException("Null profile URL");
         }
-        ZipInputStream zis = null;
-        try {
-            Collection elements = null;
-            XmiReader xmiReader = Model.getXmiReader();
-            if (url.getPath().toLowerCase().endsWith(".zip")) {
-                zis = new ZipInputStream(url.openStream());
-                ZipEntry entry = zis.getNextEntry();
-                // TODO: check if it's OK to just get the first zip entry
-                // since the zip file should contain only one xmi file - thn
-                if (entry != null) {
-                    url = makeZipEntryUrl(url, entry.getName());
+        
+        Collection elements = 
+            Model.getUmlFactory().getExtentPackages(publicId.toExternalForm());
+        if (elements == null) {
+            ZipInputStream zis = null;
+            try {
+                XmiReader xmiReader = Model.getXmiReader();
+                if (url.getPath().toLowerCase().endsWith(".zip")) {
+                    zis = new ZipInputStream(url.openStream());
+                    ZipEntry entry = zis.getNextEntry();
+                    // TODO: check if it's OK to just get the first zip entry
+                    // since the zip file should contain only one xmi file - thn
+                    if (entry != null) {
+                        url = makeZipEntryUrl(url, entry.getName());
+                    }
+                    zis.close();
                 }
-                zis.close();
+                InputSource inputSource = new InputSource(url.toExternalForm());
+                inputSource.setPublicId(publicId.toString());
+                elements = xmiReader.parse(inputSource, true);
+            } catch (UmlException e) {
+                throw new ProfileException("Error loading profile XMI file ", e);
+            } catch (IOException e) {
+                throw new ProfileException("I/O error loading profile XMI ", e);
             }
-            InputSource inputSource = new InputSource(url.toExternalForm());
-            inputSource.setPublicId(publicId.toString());
-            elements = xmiReader.parse(inputSource, true);
-            return elements;
-        } catch (UmlException e) {
-            throw new ProfileException("Error loading profile XMI file ", e);
-        } catch (IOException e) {
-            throw new ProfileException("I/O error loading profile XMI ", e);
         }
+        return elements;
     }
 
     /**

Modified: trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java?view=diff&pathrev=18282&r1=18281&r2=18282
==============================================================================
--- trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java	(original)
+++ trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java	2010-04-18 01:50:37-0700
@@ -16,6 +16,7 @@
 package org.argouml.model.euml;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -629,4 +630,9 @@
         }
     }
 
+    public Collection getExtentPackages(String extentName) {
+        // TODO: Auto-generated method stub
+        return null;
+    }
+
 }

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java?view=diff&pathrev=18282&r1=18281&r2=18282
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java	2010-04-18 01:50:37-0700
@@ -348,6 +348,10 @@
         return Collections.unmodifiableSet(extents.keySet());
     }
     
+    public UmlPackage getExtent(String name) {
+        return (UmlPackage) repository.getExtent(name);
+    }
+    
     boolean isReadOnly(Object extent) {
         synchronized (extents) {
             Extent result = extents.get(extent);

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java?view=diff&pathrev=18282&r1=18281&r2=18282
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java	2010-04-18 01:50:37-0700
@@ -39,6 +39,7 @@
 package org.argouml.model.mdr;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -1617,5 +1618,13 @@
             throw new InvalidElementException(e);
         }
     }
+    
+    public Collection getExtentPackages(String name) {
+        org.omg.uml.UmlPackage pkg = modelImpl.getExtent(name);
+        if (pkg == null) {
+            return null;
+        }
+        return pkg.getModelManagement().getUmlPackage().refAllOfType();
+    }
 
 }

Modified: trunk/src/argouml-core-model/src/org/argouml/model/ModelImplementation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model/src/org/argouml/model/ModelImplementation.java?view=diff&pathrev=18282&r1=18281&r2=18282
==============================================================================
--- trunk/src/argouml-core-model/src/org/argouml/model/ModelImplementation.java	(original)
+++ trunk/src/argouml-core-model/src/org/argouml/model/ModelImplementation.java	2010-04-18 01:50:37-0700
@@ -39,7 +39,6 @@
 package org.argouml.model;
 
 import java.io.OutputStream;
-import java.io.Writer;
 
 
 

Modified: trunk/src/argouml-core-model/src/org/argouml/model/UmlFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model/src/org/argouml/model/UmlFactory.java?view=diff&pathrev=18282&r1=18281&r2=18282
==============================================================================
--- trunk/src/argouml-core-model/src/org/argouml/model/UmlFactory.java	(original)
+++ trunk/src/argouml-core-model/src/org/argouml/model/UmlFactory.java	2010-04-18 01:50:37-0700
@@ -38,6 +38,7 @@
 
 package org.argouml.model;
 
+import java.util.Collection;
 
 /**
  * The interface for the UmlFactory.
@@ -174,4 +175,14 @@
      */
     boolean isRemoved(Object o);
 
+    /**
+     * Get the top level packages (typically just a single Model) for the given
+     * extent if it is loaded. Returns null if the extent doesn't exist and an
+     * empty collection if it exists, but contains no packages.
+     * 
+     * @param extentName the extent name (typically the public ID or URL of the
+     *            file which is used for references)
+     * @return a collection of packages if the extent exists, otherwise null
+     */
+    Collection getExtentPackages(String extentName);
 }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2587674

To unsubscribe from this discussion, e-mail: [[email protected]].
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.