svn commit: r14001 - trunk/src_new/org/argouml/profile

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-12-27 09:32:48-0800
New Revision: 14001

Added:
   trunk/src_new/org/argouml/profile/URLModelLoader.java   (contents, props changed)
Modified:
   trunk/src_new/org/argouml/profile/ResourceModelLoader.java

Log:
Load profile from URL instead of stream so that we have system ID available

Modified: trunk/src_new/org/argouml/profile/ResourceModelLoader.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/profile/ResourceModelLoader.java?view=diff&rev=14001&p1=trunk/src_new/org/argouml/profile/ResourceModelLoader.java&p2=trunk/src_new/org/argouml/profile/ResourceModelLoader.java&r1=14000&r2=14001
==============================================================================
--- trunk/src_new/org/argouml/profile/ResourceModelLoader.java	(original)
+++ trunk/src_new/org/argouml/profile/ResourceModelLoader.java	2007-12-27 09:32:48-0800
@@ -33,7 +33,7 @@
  *
  * @author maurelio1234
  */
-public class ResourceModelLoader extends StreamModelLoader {
+public class ResourceModelLoader extends URLModelLoader {
 
     /**
      * Logger.
@@ -63,7 +63,7 @@
 
     public Collection loadModel(String path) throws ProfileException {
         LOG.info("Loading profile from resource'" + path + "'");
-        return super.loadModel(clazz.getResourceAsStream(path));
+        return super.loadModel(clazz.getResource(path));
     }
 
 }

Added: trunk/src_new/org/argouml/profile/URLModelLoader.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/profile/URLModelLoader.java?view=auto&rev=14001
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/profile/URLModelLoader.java	2007-12-27 09:32:48-0800
@@ -0,0 +1,65 @@
+// $Id$
+// Copyright (c) 2007 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
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.profile;
+
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+import org.argouml.model.Model;
+import org.argouml.model.UmlException;
+import org.argouml.model.XmiReader;
+import org.xml.sax.InputSource;
+
+/**
+ * Abstract ProfileModelLoader which loads models from a URL.
+ *
+ * @author Tom Morris
+ */
+public abstract class URLModelLoader implements ProfileModelLoader {
+
+    private static final Logger LOG = Logger.getLogger(URLModelLoader.class);
+
+    /**
+     * @param url the url/system id to load
+     * @return the model
+     * @throws ProfileException if the XMIReader couldn't read the profile
+     */
+    public Collection loadModel(URL url)
+    throws ProfileException {
+        if (url == null) {
+            throw new ProfileException("Null profile URL");
+        }
+        try {
+            XmiReader xmiReader = Model.getXmiReader();
+            InputSource inputSource = new InputSource(url.toExternalForm());
+            Collection elements = xmiReader.parse(inputSource, true);
+            return elements;
+        } catch (UmlException e) {
+            LOG.error("Exception while loading profile ", e);
+            throw new ProfileException("Invalid XMI data!");
+        }
+    }
+}
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.