svn commit: r16962 - trunk/src/argouml-app/src/org/argouml/persistence

Tom Morris <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2009-03-26 12:35:40-0700
New Revision: 16962

Modified:
   trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java
   trunk/src/argouml-app/src/org/argouml/persistence/MemberFilePersister.java
   trunk/src/argouml-app/src/org/argouml/persistence/ModelMemberFilePersister.java
   trunk/src/argouml-app/src/org/argouml/persistence/PGMLStackParser.java
   trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java
   trunk/src/argouml-app/src/org/argouml/persistence/TodoListMemberFilePersister.java
   trunk/src/argouml-app/src/org/argouml/persistence/TodoParser.java
   trunk/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java
   trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java

Log:
Issue 5751: Expose load(InputSource) method so our URL/system ID is available to lower layers for use

Modified: trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java?view=diff&pathrev=16962&r1=16961&r2=16962
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java	2009-03-26 12:35:40-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Copyright (c) 1996-2009 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
@@ -43,6 +43,7 @@
 import org.tigris.gef.ocl.ExpansionException;
 import org.tigris.gef.ocl.OCLExpander;
 import org.tigris.gef.ocl.TemplateReader;
+import org.xml.sax.InputSource;
 
 /**
  * The file persister for the diagram members.
@@ -67,6 +68,17 @@
     @Override
     public void load(Project project, InputStream inputStream)
         throws OpenException {
+        load(project, new InputSource(inputStream));
+        try {
+            inputStream.close();
+        } catch (IOException e) {
+            throw new OpenException("I/O error on stream close", e);
+        }
+    }
+    
+    @Override
+    public void load(Project project, InputSource inputSource)
+        throws OpenException {
 
         // If the model repository doesn't manage a DI model
         // then we must generate our Figs by inspecting PGML
@@ -87,8 +99,7 @@
                         translation.getKey(),
                         translation.getValue());
             }
-            ArgoDiagram d = parser.readArgoDiagram(inputStream, false);
-            inputStream.close();
+            ArgoDiagram d = parser.readArgoDiagram(inputSource, false);
             project.addMember(d);
         } catch (Exception e) {
             if (e instanceof OpenException) {
@@ -100,11 +111,7 @@
     
     @Override
     public void load(Project project, URL url) throws OpenException {   
-        try {
-            load(project, url.openStream());
-        } catch (IOException e) {
-            throw new OpenException(e);
-        }
+        load(project, new InputSource(url.toExternalForm()));
     }
 
     @Override

Modified: trunk/src/argouml-app/src/org/argouml/persistence/MemberFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/MemberFilePersister.java?view=diff&pathrev=16962&r1=16961&r2=16962
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/MemberFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/MemberFilePersister.java	2009-03-26 12:35:40-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-2009 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
@@ -33,12 +33,12 @@
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintWriter;
-import java.io.Writer;
 import java.net.URL;
 
 import org.argouml.application.api.Argo;
 import org.argouml.kernel.Project;
 import org.argouml.kernel.ProjectMember;
+import org.xml.sax.InputSource;
 
 /**
  * A base class file persister for project members.
@@ -56,7 +56,7 @@
         throws OpenException;
 
     /**
-     * Load a project member from an InputStream.
+     * Load a project member from a URL.
      *
      * @param project the project to persist
      * @param url the URL to open and parse to load the member.
@@ -64,6 +64,18 @@
      */
     public abstract void load(Project project, URL url)
         throws OpenException;
+
+    /**
+     * Load a project member from a SAX InputSource.
+     *
+     * @param project the project to persist
+     * @param inputSource the InputSource to load from
+     * @throws OpenException on any parsing errors.
+     * @since 0.29.1
+     */
+    public abstract void load(Project project, InputSource inputSource)
+        throws OpenException;
+    
     
     /**
      * Gets the tag name which is the root tag for this member.

Modified: trunk/src/argouml-app/src/org/argouml/persistence/ModelMemberFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/ModelMemberFilePersister.java?view=diff&pathrev=16962&r1=16961&r2=16962
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/ModelMemberFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/ModelMemberFilePersister.java	2009-03-26 12:35:40-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Copyright (c) 1996-2009 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
@@ -72,9 +72,6 @@
      * If there is a problem with the xmi file, an error is set in the
      * getLastLoadStatus() field. This needs to be examined by the
      * calling function.<p>
-     *
-     * @see org.argouml.persistence.MemberFilePersister#load(org.argouml.kernel.Project,
-     * java.io.InputStream)
      */
     public void load(Project project, URL url)
         throws OpenException {
@@ -100,7 +97,7 @@
     }
 
 
-    private void load(Project project, InputSource source)
+    public void load(Project project, InputSource source)
         throws OpenException {
 
         Object mmodel = null;

Modified: trunk/src/argouml-app/src/org/argouml/persistence/PGMLStackParser.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/PGMLStackParser.java?view=diff&pathrev=16962&r1=16961&r2=16962
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/PGMLStackParser.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/PGMLStackParser.java	2009-03-26 12:35:40-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2005-2008 The Regents of the University of California. All
+// Copyright (c) 2005-2009 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
@@ -56,6 +56,7 @@
 import org.tigris.gef.presentation.FigGroup;
 import org.tigris.gef.presentation.FigNode;
 import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
@@ -335,6 +336,20 @@
      * @return the diagram created as a result of the parse
      * @throws SAXException
      */
+    public ArgoDiagram readArgoDiagram(InputSource is, boolean closeStream)
+        throws SAXException {
+
+        return (ArgoDiagram) readDiagram(is.getByteStream(), closeStream);
+    }
+    
+    /**
+     * Read and parse the input stream to create a new diagram and return it.
+     * 
+     * @param is the input stream
+     * @param closeStream true to close the stream when parsing is complete
+     * @return the diagram created as a result of the parse
+     * @throws SAXException
+     */
     public ArgoDiagram readArgoDiagram(InputStream is, boolean closeStream)
         throws SAXException {
 

Modified: trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java?view=diff&pathrev=16962&r1=16961&r2=16962
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java	2009-03-26 12:35:40-0700
@@ -72,15 +72,20 @@
         return "profile";
     }
 
+    public void load(Project project, InputStream inputStream)
+        throws OpenException {
+        load(project, new InputSource(inputStream));
+    }
+    
     /*
      * @see org.argouml.persistence.MemberFilePersister#load(org.argouml.kernel.Project, java.io.InputStream)
      */
-    public void load(Project project, InputStream inputStream)
+    public void load(Project project, InputSource inputSource)
         throws OpenException {
         try {
             ProfileConfigurationParser parser = 
                 new ProfileConfigurationParser();
-            parser.parse(new InputSource(inputStream));
+            parser.parse(inputSource);
             Collection<Profile> profiles = parser.getProfiles();
 
             Collection<String> unresolved = parser.getUnresolvedFilenames();
@@ -259,11 +264,7 @@
 
     @Override
     public void load(Project project, URL url) throws OpenException {
-        try {
-            load(project, url.openStream());
-        } catch (IOException e) {
-            throw new OpenException(e);
-        }
+        load(project, new InputSource(url.toExternalForm()));
     }
     
 }

Modified: trunk/src/argouml-app/src/org/argouml/persistence/TodoListMemberFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/TodoListMemberFilePersister.java?view=diff&pathrev=16962&r1=16961&r2=16962
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/TodoListMemberFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/TodoListMemberFilePersister.java	2009-03-26 12:35:40-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Copyright (c) 1996-2009 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
@@ -24,13 +24,11 @@
 
 package org.argouml.persistence;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
-import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
 
@@ -43,6 +41,7 @@
 import org.argouml.uml.cognitive.ProjectMemberTodoList;
 import org.tigris.gef.ocl.ExpansionException;
 import org.tigris.gef.ocl.TemplateReader;
+import org.xml.sax.InputSource;
 
 /**
  * The file persister for the Todo members.
@@ -55,19 +54,24 @@
 
     private static final String TO_DO_TEE = "/org/argouml/persistence/todo.tee";
 
-    /**
-     * Load the todo member.
-     * @see org.argouml.persistence.MemberFilePersister#load(org.argouml.kernel.Project,
-     * java.io.InputStream)
-     */
+
     public void load(Project project, InputStream inputStream)
         throws OpenException {
+        try {
+            load(project, new InputSource(new InputStreamReader(inputStream,
+                    Argo.getEncoding())));
+        } catch (UnsupportedEncodingException e) {
+            throw new OpenException(e);
+        }
+    }
+    
+
+    public void load(Project project, InputSource inputSource)
+        throws OpenException {
 
         try {
             TodoParser parser = new TodoParser();
-            Reader reader = new InputStreamReader(inputStream,
-                    Argo.getEncoding());
-            parser.readTodoList(reader);
+            parser.readTodoList(inputSource);
             ProjectMemberTodoList pm = new ProjectMemberTodoList("", project);
             project.addMember(pm);
         } catch (Exception e) {
@@ -80,11 +84,7 @@
     
     @Override
     public void load(Project project, URL url) throws OpenException {   
-        try {
-            load(project, url.openStream());
-        } catch (IOException e) {
-            throw new OpenException(e);
-        }
+        load(project, new InputSource(url.toExternalForm()));
     }
 
     /*

Modified: trunk/src/argouml-app/src/org/argouml/persistence/TodoParser.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/TodoParser.java?view=diff&pathrev=16962&r1=16961&r2=16962
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/TodoParser.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/TodoParser.java	2009-03-26 12:35:40-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2009 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
@@ -27,12 +27,13 @@
 import java.io.Reader;
 import java.util.ArrayList;
 import java.util.List;
+
 import org.apache.log4j.Logger;
 import org.argouml.cognitive.Designer;
-
+import org.argouml.cognitive.ListSet;
 import org.argouml.cognitive.ResolvedCritic;
 import org.argouml.cognitive.ToDoItem;
-import org.argouml.cognitive.ListSet;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 
@@ -91,6 +92,18 @@
 
 
     /**
+     * Read an XML todo list and enter any todo items into the current designer.
+     * 
+     * @param inputSource The stream containing TodoList XML data.
+     * @throws SAXException on any error
+     */
+    public synchronized void readTodoList(
+            InputSource inputSource) throws SAXException {
+        LOG.info("Reading ToDo list");
+        parse(inputSource);
+    }
+    
+    /**
      * Reads an XML todo list from InputStream is and enters
      * any todo items into the current designer.
      *

Modified: trunk/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java?view=diff&pathrev=16962&r1=16961&r2=16962
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java	2009-03-26 12:35:40-0700
@@ -71,6 +71,7 @@
 import org.tigris.gef.ocl.ExpansionException;
 import org.tigris.gef.ocl.OCLExpander;
 import org.tigris.gef.ocl.TemplateReader;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 
@@ -366,8 +367,18 @@
                 LOG.info("Loading member with "
                         + persister.getClass().getName());
                 inputStream.reopen(persister.getMainTag());
+                // TODO: Do we need to set the input encoding here?  It was
+                // done for ToDo parsing, but none of the other member types
+//                InputSource inputSource = new InputSource(
+//                        new InputStreamReader(inputStream, Argo
+//                                .getEncoding()));
+                InputSource inputSource = new InputSource(inputStream);
+                // Don't use systemId here or it will get opened in preference 
+                // to inputStream. 
+                inputSource.setPublicId(
+                        originalFile.toURI().toURL().toExternalForm());
                 try {
-                    persister.load(p, inputStream);
+                    persister.load(p, inputSource);
                 } catch (OpenException e) {
                     // UML 2.x files don't have XMI as their outer
                     // tag.  Try again with uml:Model
@@ -375,7 +386,7 @@
                             && e.getCause() instanceof UmlException 
                             && e.getCause().getCause() instanceof IOException) {
                         inputStream.reopen("uml:Model");
-                        persister.load(p, inputStream);
+                        persister.load(p, inputSource);
                     } else {
                         throw e;
                     }

Modified: trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java?view=diff&pathrev=16962&r1=16961&r2=16962
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java	2009-03-26 12:35:40-0700
@@ -50,10 +50,10 @@
 import org.argouml.application.api.Argo;
 import org.argouml.application.helpers.ApplicationVersion;
 import org.argouml.i18n.Translator;
+import org.argouml.kernel.ProfileConfiguration;
 import org.argouml.kernel.Project;
 import org.argouml.kernel.ProjectFactory;
 import org.argouml.kernel.ProjectMember;
-import org.argouml.kernel.ProfileConfiguration;
 import org.argouml.util.FileConstants;
 import org.argouml.util.ThreadUtils;
 import org.xml.sax.InputSource;
@@ -273,7 +273,8 @@
             // removed from here also.
             String xmiEntry = getEntryNames(file, ".xmi").iterator().next();
             MemberFilePersister persister = getMemberFilePersister("xmi");
-            persister.load(p, makeZipEntryUrl(toURL(file), xmiEntry));
+            URL url = makeZipEntryUrl(toURL(file), xmiEntry);
+            persister.load(p, new InputSource(url.toExternalForm()));
             
             // Load the rest
             List<String> entries = getEntryNames(file, null);
@@ -283,7 +284,8 @@
                     persister = getMemberFilePersister(ext);
                     LOG.info("Loading member with "
                             + persister.getClass().getName());
-                    persister.load(p, openZipEntry(toURL(file), name));
+                    url = makeZipEntryUrl(toURL(file), name);
+                    persister.load(p, new InputSource(url.toExternalForm()));
                 }
             }

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

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.