svn commit: r13276 - trunk/src_new/org/argouml/persistence/ArgoParser.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-08-09 12:34:09-0700
New Revision: 13276

Modified:
   trunk/src_new/org/argouml/persistence/ArgoParser.java

Log:
Add readProject() for InputSource as alternative to Reader variant

Modified: trunk/src_new/org/argouml/persistence/ArgoParser.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/persistence/ArgoParser.java?view=diff&rev=13276&p1=trunk/src_new/org/argouml/persistence/ArgoParser.java&p2=trunk/src_new/org/argouml/persistence/ArgoParser.java&r1=13275&r2=13276
==============================================================================
--- trunk/src_new/org/argouml/persistence/ArgoParser.java	(original)
+++ trunk/src_new/org/argouml/persistence/ArgoParser.java	2007-08-09 12:34:09-0700
@@ -31,12 +31,12 @@
 import org.apache.log4j.Logger;
 import org.argouml.kernel.Project;
 import org.argouml.kernel.ProjectSettings;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 
-
 /**
- * @stereotype singleton
+ * Parser for ArgoUML project description file (.argo)
  */
 class ArgoParser extends SAXParserBase {
 
@@ -45,10 +45,8 @@
      */
     private static final Logger LOG = Logger.getLogger(ArgoParser.class);
 
-    ////////////////////////////////////////////////////////////////
-    // instance variables
-
     private Project project;
+    
     private ProjectSettings ps;
 
     private ArgoTokenTable tokens = new ArgoTokenTable();
@@ -63,40 +61,68 @@
         super();
     }
 
-    ////////////////////////////////////////////////////////////////
-    // main parsing methods
+    /**
+     * @param theProject the project to populate
+     * @param source the input source
+     * @throws SAXException on error when parsing xml
+     */
+    public void readProject(Project theProject, InputSource source)
+        throws SAXException {
 
+        if (source == null) {
+            throw new IllegalArgumentException(
+                    "An InputSource must be supplied");
+        }
+
+        preRead(theProject);
+        
+        try {
+            parse(source);
+        } catch (SAXException e) {
+            logError(source.toString(), e);
+            throw e;
+        }
+    }
+    
     /**
      * @param theProject the project to populate
-     * @param is the reader
+     * @param reader the reader
      * @throws SAXException on error when parsing xml
      */
-    public void readProject(Project theProject, Reader is)
+    public void readProject(Project theProject, Reader reader)
     	throws SAXException {
 
-        if (is == null) {
+        if (reader == null) {
             throw new IllegalArgumentException(
-                    "An input stream must be supplied");
+                    "A reader must be supplied");
         }
 
-        PersistenceManager.getInstance().setLastLoadMessage("OK");
-        PersistenceManager.getInstance().setLastLoadStatus(true);
-
+        preRead(theProject);
+        
         try {
-            LOG.info("=======================================");
-            LOG.info("== READING PROJECT " + theProject);
-            project = theProject;
-            ps = project.getProjectSettings();
-            parse(is);
+            parse(reader);
         } catch (SAXException e) {
-            PersistenceManager.getInstance().setLastLoadStatus(false);
-            LOG.error("Exception reading project================");
-            LOG.error(is.toString());
-            PersistenceManager.getInstance().setLastLoadMessage(e.toString());
+            logError(reader.toString(), e);
             throw e;
         }
     }
 
+    private void preRead(Project theProject) {
+        PersistenceManager.getInstance().setLastLoadMessage("OK");
+        PersistenceManager.getInstance().setLastLoadStatus(true);
+        LOG.info("=======================================");
+        LOG.info("== READING PROJECT " + theProject);
+        project = theProject;
+        ps = project.getProjectSettings();
+    }
+
+    private void logError(String projectName, SAXException e) {
+        PersistenceManager.getInstance().setLastLoadStatus(false);
+        LOG.error("Exception reading project================");
+        LOG.error(projectName);
+        PersistenceManager.getInstance().setLastLoadMessage(e.toString());
+    }
+    
     /**
      * Get the project to which the URI is to be parsed.
      * @return the project
@@ -398,10 +424,10 @@
     }
 
     /**
-     * Get the numer of diagram members read.
-     * @return the numer of diagram members read.
+     * Get the number of diagram members read.
+     * @return the number of diagram members read.
      */
     public List getMemberList() {
         return memberList;
     }
-} /* end class ArgoParser */
+}
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.