svn commit: r16147 - trunk/src: argouml-app/src/org/argouml/persistence argouml-app/src/org/argouml/ui/explorer 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: 2008-11-23 10:03:41-0800
New Revision: 16147

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/OldModelMemberFilePersister.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/ZargoFilePersister.java
   trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionExportProfileXMI.java   (contents, props changed)
   trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java
   trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.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/XmiWriterMDRImpl.java
   trunk/src/argouml-core-model/src/org/argouml/model/Model.java
   trunk/src/argouml-core-model/src/org/argouml/model/ModelImplementation.java

Log:
Remove deprecated persistence methods.  Review all uses of writers/readers to make sure they are using the correct character encoding.

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&rev=16147&p1=trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java&p2=trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java	2008-11-23 10:03:41-0800
@@ -24,15 +24,11 @@
 
 package org.argouml.persistence;
 
-import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
-import java.io.Writer;
 import java.net.URL;
 
 import org.argouml.application.api.Argo;
@@ -98,42 +94,6 @@
 
 
     @Override
-    @Deprecated
-    public void save(ProjectMember member, Writer writer, boolean xmlFragment)
-    	throws SaveException {
-
-        ProjectMemberDiagram diagramMember = (ProjectMemberDiagram) member;
-        OCLExpander expander;
-        try {
-            expander =
-                new OCLExpander(TemplateReader.getInstance().read(PGML_TEE));
-        } catch (ExpansionException e) {
-            throw new SaveException(e);
-        }
-        if (!xmlFragment) {
-            try {
-                expander.expand(writer, diagramMember.getDiagram());
-            } catch (ExpansionException e) {
-                throw new SaveException(e);
-            }
-        } else {
-            try {
-                File tempFile = File.createTempFile("pgml", null);
-                tempFile.deleteOnExit();
-                FileWriter w = new FileWriter(tempFile);
-                expander.expand(w, diagramMember.getDiagram());
-                w.close();
-                addXmlFileToWriter((PrintWriter) writer, tempFile);
-            } catch (ExpansionException e) {
-                throw new SaveException(e);
-            } catch (IOException e) {
-                throw new SaveException(e);
-            }
-        }
-    }
-    
-
-    @Override
     public void save(ProjectMember member, OutputStream outStream)
         throws SaveException {
 
@@ -153,14 +113,18 @@
         } catch (UnsupportedEncodingException e1) {
             throw new SaveException("Bad encoding", e1);
         }
-        PrintWriter printWriter = new PrintWriter(outputWriter);
+        
         try {
             // WARNING: the OutputStream version of this doesn't work! - tfm
-            expander.expand(printWriter, diagramMember.getDiagram());
+            expander.expand(outputWriter, diagramMember.getDiagram());
         } catch (ExpansionException e) {
             throw new SaveException(e);
         } finally {
-            printWriter.flush();
+            try {
+                outputWriter.flush();
+            } catch (IOException e) {
+                throw new SaveException(e);
+            }
         }
         
     }

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&rev=16147&p1=trunk/src/argouml-app/src/org/argouml/persistence/MemberFilePersister.java&p2=trunk/src/argouml-app/src/org/argouml/persistence/MemberFilePersister.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/MemberFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/MemberFilePersister.java	2008-11-23 10:03:41-0800
@@ -73,22 +73,6 @@
 
 
     /**
-     * Save the projectmember as XML to the given writer.
-     * 
-     * @param member The project member to save.
-     * @param writer The Writer to which to save the XML.
-     * @throws SaveException if the save fails
-     * @deprecated for 0.25.4 by tfmorris. Use
-     *             {@link #save(ProjectMember, OutputStream)}.
-     */
-    @Deprecated
-    public void save(
-            ProjectMember member,
-            Writer writer) throws SaveException {
-	save(member, writer, false);
-    }
-
-    /**
      * Save the project member as XML to the given output stream.
      * 
      * @param member
@@ -103,23 +87,6 @@
             ProjectMember member,
             OutputStream stream) throws SaveException;
     
-    /**
-     * Save the project member as XML to the given writer.
-     *
-     * @param member The project member to save.
-     * @param writer The Writer to which to save the XML.
-     * @param xmlFragment true if the XML saved is a fragment os some other
-     *     XML file (ie part of .uml)
-     * @throws SaveException if the save fails
-     * @deprecated for 0.25.4 by tfmorris. Use 
-     * {@link #save(ProjectMember, OutputStream)}.
-     */
-    @Deprecated
-    public abstract void save(
-            ProjectMember member,
-            Writer writer,
-            boolean xmlFragment) throws SaveException;
-
     
     /**
      * Send an existing file of XML to the PrintWriter.

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&rev=16147&p1=trunk/src/argouml-app/src/org/argouml/persistence/ModelMemberFilePersister.java&p2=trunk/src/argouml-app/src/org/argouml/persistence/ModelMemberFilePersister.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/ModelMemberFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/ModelMemberFilePersister.java	2008-11-23 10:03:41-0800
@@ -24,13 +24,9 @@
 
 package org.argouml.persistence;
 
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.Writer;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -149,56 +145,6 @@
 
     /**
      * Save the project model to XMI.
-     *
-     * {@inheritDoc}
-     */
-    @Deprecated
-    @Override
-    @SuppressWarnings("deprecation")
-    public void save(ProjectMember member, Writer w, boolean xmlFragment)
-    	throws SaveException {
-
-        if (w == null) {
-            throw new IllegalArgumentException("No Writer specified!");
-        }
-
-        try {
-            ProjectMemberModel pmm = (ProjectMemberModel) member;
-            Object model = pmm.getModel();
-            
-            if (xmlFragment) {
-                // If we have an indent then we are adding this file
-                // to a superfile.
-                // That is most likely inserting the XMI into the .uml file
-                File tempFile = File.createTempFile("xmi", null);
-                tempFile.deleteOnExit();
-
-                OutputStream stream = new FileOutputStream(tempFile);
-                XmiWriter xmiWriter = 
-                    Model.getXmiWriter(model, stream, 
-                            ApplicationVersion.getVersion() + "(" 
-                            + UmlFilePersister.PERSISTENCE_VERSION + ")");
-                
-                xmiWriter.write();
-                addXmlFileToWriter((PrintWriter) w, tempFile);
-            } else {
-                // Otherwise we are writing into a zip writer or to XMI.
-                XmiWriter xmiWriter = 
-                    Model.getXmiWriter(model, w, 
-                            ApplicationVersion.getVersion() + "(" 
-                            + UmlFilePersister.PERSISTENCE_VERSION + ")");
-                xmiWriter.write();
-            }
-        } catch (IOException e) {
-            throw new SaveException(e);
-        } catch (UmlException e) {
-            throw new SaveException(e);
-        }
-
-    }
-    
-    /**
-     * Save the project model to XMI.
      * 
      * @see org.argouml.persistence.MemberFilePersister#save(ProjectMember, OutputStream)
      */

Modified: trunk/src/argouml-app/src/org/argouml/persistence/OldModelMemberFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/OldModelMemberFilePersister.java?view=diff&rev=16147&p1=trunk/src/argouml-app/src/org/argouml/persistence/OldModelMemberFilePersister.java&p2=trunk/src/argouml-app/src/org/argouml/persistence/OldModelMemberFilePersister.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/OldModelMemberFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/OldModelMemberFilePersister.java	2008-11-23 10:03:41-0800
@@ -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
@@ -24,47 +24,12 @@
 
 package org.argouml.persistence;
 
-import java.io.Writer;
-
-import org.argouml.application.helpers.ApplicationVersion;
-import org.argouml.kernel.ProjectMember;
-import org.argouml.model.Model;
-import org.argouml.model.UmlException;
-import org.argouml.model.XmiWriter;
-import org.argouml.uml.ProjectMemberModel;
 
 /**
  * The file persister for the UML model.
+ * TODO: This is empty.  What is its purpose? - tfm
  * @author Bob Tarling
  */
 class OldModelMemberFilePersister extends ModelMemberFilePersister 
     implements XmiExtensionParser {
-
-    /**
-     * Save the project model to XMI.
-     *
-     * {@inheritDoc}
-     */
-    @Deprecated
-    @Override
-    @SuppressWarnings("deprecation")    
-    public void save(ProjectMember member, Writer w, boolean xmlFragment)
-    	throws SaveException {
-
-        if (w == null) {
-            throw new IllegalArgumentException("No Writer specified!");
-        }
-
-        try {
-            ProjectMemberModel pmm = (ProjectMemberModel) member;
-            Object model = pmm.getModel();
-            XmiWriter xmiWriter = 
-                Model.getXmiWriter(model, w, 
-                        ApplicationVersion.getVersion() + "(" 
-                        + UmlFilePersister.PERSISTENCE_VERSION + ")");
-            xmiWriter.write();
-        } catch (UmlException e) {
-            throw new SaveException(e);
-        }
-    }
 }

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&rev=16147&p1=trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java&p2=trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java	2008-11-23 10:03:41-0800
@@ -26,14 +26,15 @@
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 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.StringWriter;
-import java.io.Writer;
+import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -41,6 +42,7 @@
 import java.util.List;
 
 import org.apache.log4j.Logger;
+import org.argouml.application.api.Argo;
 import org.argouml.application.helpers.ApplicationVersion;
 import org.argouml.configuration.Configuration;
 import org.argouml.kernel.ProfileConfiguration;
@@ -78,7 +80,7 @@
         throws OpenException {
         try {
             BufferedReader br = new BufferedReader(new InputStreamReader(
-                    inputStream));
+                    inputStream, Argo.getEncoding()));
 
             String line = null;
             while (true) {
@@ -199,7 +201,9 @@
             ProfileManager profileManager) throws IOException {
         File profilesDirectory = getProfilesDirectory(profileManager);
         File profileFile = new File(profilesDirectory, fileName);
-        FileWriter writer = new FileWriter(profileFile);
+        OutputStreamWriter writer = new OutputStreamWriter(
+                new FileOutputStream(profileFile), 
+                Argo.getEncoding());
         writer.write(xmi.toString());
         writer.close();
         LOG.info("Wrote user defined profile \"" + profileFile 
@@ -247,25 +251,19 @@
     }
 
     /*
-     * @see org.argouml.persistence.MemberFilePersister#save(org.argouml.kernel.ProjectMember, java.io.Writer, boolean)
-     */
-    @Override
-    @Deprecated
-    @SuppressWarnings("deprecation")
-    public void save(ProjectMember member, Writer writer, boolean xmlFragment)
-        throws SaveException {
-        PrintWriter w = new PrintWriter(writer);
-        saveProjectMember(member, w);
-    }
-
-    /*
      * @see org.argouml.persistence.MemberFilePersister#save(org.argouml.kernel.ProjectMember, java.io.OutputStream)
      */
     public void save(ProjectMember member, OutputStream stream)
 	throws SaveException {
 	
-        PrintWriter w = new PrintWriter(stream);
-	saveProjectMember(member, w);
+        PrintWriter w;
+        try {
+            w = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
+        } catch (UnsupportedEncodingException e1) {
+            throw new SaveException("UTF-8 encoding not supported on platform",
+                    e1);
+        }
+        saveProjectMember(member, w);
         w.flush();
     }
 
@@ -316,7 +314,9 @@
         throws UmlException {
         
         // TODO: Why is this not executed?  Remove if not needed - tfm
-        if (true) return;
+        if (true) {
+            return;
+        }
 
         StringWriter myWriter = new StringWriter();
         for (Object model : profileModels) {

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&rev=16147&p1=trunk/src/argouml-app/src/org/argouml/persistence/TodoListMemberFilePersister.java&p2=trunk/src/argouml-app/src/org/argouml/persistence/TodoListMemberFilePersister.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/TodoListMemberFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/TodoListMemberFilePersister.java	2008-11-23 10:03:41-0800
@@ -24,15 +24,14 @@
 
 package org.argouml.persistence;
 
-import java.io.File;
-import java.io.FileWriter;
 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.Writer;
+import java.io.UnsupportedEncodingException;
 import java.net.URL;
 
 import org.apache.log4j.Logger;
@@ -96,54 +95,6 @@
     }
 
 
-    @Deprecated
-    @SuppressWarnings("deprecation")
-    @Override
-    public void save(ProjectMember member, Writer writer, boolean xmlFragment)
-        throws SaveException {
-
-        LOG.info("Saving todo list");
-
-        if (writer == null) {
-            throw new IllegalArgumentException(
-                    "No writer specified to save todo list");
-        }
-
-        OCLExpander expander;
-        try {
-            expander =
-                new OCLExpander(TemplateReader.getInstance().read(TO_DO_TEE));
-        } catch (ExpansionException e) {
-            throw new SaveException(e);
-        }
-
-        if (!xmlFragment) {
-            try {
-                Designer.disableCritiquing();
-                expander.expand(writer, member);
-            } catch (ExpansionException e) {
-                throw new SaveException(e);
-            } finally {
-                Designer.enableCritiquing();
-            }
-        } else {
-            try {
-                File tempFile = File.createTempFile("todo", null);
-                tempFile.deleteOnExit();
-                FileWriter w = new FileWriter(tempFile);
-                expander.expand(w, member);
-                w.close();
-                addXmlFileToWriter((PrintWriter) writer, tempFile);
-            } catch (ExpansionException e) {
-                throw new SaveException(e);
-            } catch (IOException e) {
-                throw new SaveException(e);
-            }
-        }
-
-        LOG.debug("Done saving TO DO LIST!!!");
-    }
-    
     public void save(ProjectMember member, OutputStream outStream)
         throws SaveException {
 
@@ -156,7 +107,14 @@
             throw new SaveException(e);
         }
 
-        PrintWriter pw = new PrintWriter(outStream);
+        PrintWriter pw;
+        try {
+            pw = new PrintWriter(new OutputStreamWriter(outStream, "UTF-8"));
+        } catch (UnsupportedEncodingException e1) {
+            throw new SaveException("UTF-8 encoding not supported on platform", 
+                    e1);
+        }
+        
         try {
             Designer.disableCritiquing();
             // WARNING: The GEF implementation of the OutputStream version of 

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&rev=16147&p1=trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java&p2=trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java	2008-11-23 10:03:41-0800
@@ -130,17 +130,14 @@
                     "Failed to archive the previous file version", e);
         }
 
-        BufferedWriter writer = null;
+        ZipOutputStream stream = null;
         try {
 
             project.setFile(file);
             project.setVersion(ApplicationVersion.getVersion());
             project.setPersistenceVersion(PERSISTENCE_VERSION);
 
-            ZipOutputStream stream =
-                new ZipOutputStream(new FileOutputStream(file));
-            writer =
-                new BufferedWriter(new OutputStreamWriter(stream, "UTF-8"));
+            stream = new ZipOutputStream(new FileOutputStream(file));
 
             for (ProjectMember projectMember : project.getMembers()) {
                 if (projectMember.getType().equalsIgnoreCase("xmi")) {
@@ -152,7 +149,7 @@
                             new ZipEntry(projectMember.getZipName()));
                     MemberFilePersister persister =
                         getMemberFilePersister(projectMember);
-                    persister.save(projectMember, writer);
+                    persister.save(projectMember, stream);
                 }
             }
             // if save did not raise an exception
@@ -173,7 +170,9 @@
         } catch (Exception e) {
             LOG.error("Exception occured during save attempt", e);
             try {
-                writer.close();
+                if (stream != null) {
+                    stream.close();
+                }
             } catch (Exception ex) {
                 // Do nothing.
             }
@@ -188,7 +187,7 @@
         }
 
         try {
-            writer.close();
+            stream.close();
         } catch (IOException ex) {
             LOG.error("Failed to close save output writer", ex);
         }
@@ -197,6 +196,7 @@
     /*
      * @see org.argouml.persistence.AbstractFilePersister#isSaveEnabled()
      */
+    @Override
     public boolean isSaveEnabled() {
         return false;
     }

Modified: trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionExportProfileXMI.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionExportProfileXMI.java?view=diff&rev=16147&p1=trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionExportProfileXMI.java&p2=trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionExportProfileXMI.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionExportProfileXMI.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionExportProfileXMI.java	2008-11-23 10:03:41-0800
@@ -1,159 +1,161 @@
-// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $

-// 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.ui.explorer;

-

-import java.awt.event.ActionEvent;

-import java.io.File;

-import java.io.FileWriter;

-import java.io.IOException;

-import java.util.Collection;

-

-import javax.swing.AbstractAction;

-import javax.swing.JFileChooser;

-import javax.swing.filechooser.FileFilter;

-

-import org.apache.log4j.Logger;

-import org.argouml.application.helpers.ApplicationVersion;

-import org.argouml.configuration.Configuration;

-import org.argouml.i18n.Translator;

-import org.argouml.model.Model;

-import org.argouml.model.UmlException;

-import org.argouml.model.XmiWriter;

-import org.argouml.persistence.PersistenceManager;

-import org.argouml.persistence.ProjectFileView;

-import org.argouml.persistence.UmlFilePersister;

-import org.argouml.profile.Profile;

-import org.argouml.profile.ProfileException;

-import org.argouml.util.ArgoFrame;

-

-/**

- * Exports the model of a selected profile as XMI

- *

- * @author Marcos Aurélio

- */

-public class ActionExportProfileXMI extends AbstractAction {

-

-    /**

-     * Logger.

-     */

-    private static final Logger LOG = Logger

-            .getLogger(ActionExportProfileXMI.class);

-

-    private Profile selectedProfile;

-    

-    /**

-     * Default Constructor

-     * 

-     * @param profile the selected profile

-     */

-    public ActionExportProfileXMI(Profile profile) {

-        super(Translator.localize("action.export-profile-as-xmi"));

-        this.selectedProfile = profile;

-    }

-

-    /**

-     * @param arg0

-     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)

-     */

-    public void actionPerformed(ActionEvent arg0) {

-        try {

-            final Collection profilePackages = 

-                selectedProfile.getProfilePackages();

-            final Object model = profilePackages.iterator().next();

-            

-            if (model != null) {

-                File destiny = getTargetFile();

-                if (destiny != null) {

-                    saveModel(destiny, model);

-                }

-            }

-        } catch (ProfileException e) {

-            // TODO: We should be giving the user more direct feedback

-            LOG.error("Exception", e);

-        } catch (IOException e) {

-            LOG.error("Exception", e);

-        } catch (UmlException e) {

-            LOG.error("Exception", e);

-        }

-    }

-

-    @SuppressWarnings("deprecation")

-    private void saveModel(File destiny, Object model) throws IOException,

-            UmlException {

-        FileWriter w = new FileWriter(destiny);

-

-        XmiWriter xmiWriter = Model.getXmiWriter(model, w, ApplicationVersion

-                .getVersion()

-                + "(" + UmlFilePersister.PERSISTENCE_VERSION + ")");

-        xmiWriter.write();

-    }

-

-    private File getTargetFile() {

-        // show a chooser dialog for the file name, only xmi is allowed

-        JFileChooser chooser = new JFileChooser();

-        chooser.setDialogTitle(Translator.localize(

-                                       "action.export-profile-as-xmi"));

-        chooser.setFileView(ProjectFileView.getInstance());

-        chooser.setApproveButtonText(Translator.localize(

-                                             "filechooser.export"));

-        chooser.setAcceptAllFileFilterUsed(true);

-        chooser.setFileFilter(new FileFilter() {

-

-            public boolean accept(File file) {

-                return file.isDirectory()

-                        || (file.isFile() 

-                                && (file.getName().toLowerCase().endsWith(".xml") 

-                                      || file.getName().toLowerCase().endsWith(".xmi")));

-            }

-

-            public String getDescription() {

-                return "*.XMI";

-            }

-

-        });

-

-        String fn =

-            Configuration.getString(

-                PersistenceManager.KEY_PROJECT_NAME_PATH);

-        if (fn.length() > 0) {

-            fn = PersistenceManager.getInstance().getBaseName(fn);

-            chooser.setSelectedFile(new File(fn));

-        }

-

-        int result = chooser.showSaveDialog(ArgoFrame.getInstance());

-        if (result == JFileChooser.APPROVE_OPTION) {

-            File theFile = chooser.getSelectedFile();

-            if (theFile != null) {

-                if (!theFile.getName().toUpperCase().endsWith(".XMI")) {

-                    theFile = new File(theFile.getAbsolutePath() + ".XMI");

-                }

-                return theFile;

-            }

-        }

-        

-        return null;

-    }

-

-}

+// $Id$
+// Copyright (c) 2007-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
+// 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.ui.explorer;
+
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Collection;
+
+import javax.swing.AbstractAction;
+import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
+
+import org.apache.log4j.Logger;
+import org.argouml.application.helpers.ApplicationVersion;
+import org.argouml.configuration.Configuration;
+import org.argouml.i18n.Translator;
+import org.argouml.model.Model;
+import org.argouml.model.UmlException;
+import org.argouml.model.XmiWriter;
+import org.argouml.persistence.PersistenceManager;
+import org.argouml.persistence.ProjectFileView;
+import org.argouml.persistence.UmlFilePersister;
+import org.argouml.profile.Profile;
+import org.argouml.profile.ProfileException;
+import org.argouml.util.ArgoFrame;
+
+/**
+ * Exports the model of a selected profile as XMI
+ *
+ * @author Marcos Aurélio
+ */
+public class ActionExportProfileXMI extends AbstractAction {
+
+    /**
+     * Logger.
+     */
+    private static final Logger LOG = Logger
+            .getLogger(ActionExportProfileXMI.class);
+
+    private Profile selectedProfile;
+    
+    /**
+     * Default Constructor
+     * 
+     * @param profile the selected profile
+     */
+    public ActionExportProfileXMI(Profile profile) {
+        super(Translator.localize("action.export-profile-as-xmi"));
+        this.selectedProfile = profile;
+    }
+
+    
+    public void actionPerformed(ActionEvent arg0) {
+        try {
+            final Collection profilePackages = 
+                selectedProfile.getProfilePackages();
+            final Object model = profilePackages.iterator().next();
+            
+            if (model != null) {
+                File destiny = getTargetFile();
+                if (destiny != null) {
+                    saveModel(destiny, model);
+                }
+            }
+        } catch (ProfileException e) {
+            // TODO: We should be giving the user more direct feedback
+            LOG.error("Exception", e);
+        } catch (IOException e) {
+            LOG.error("Exception", e);
+        } catch (UmlException e) {
+            LOG.error("Exception", e);
+        }
+    }
+
+
+    private void saveModel(File destiny, Object model) throws IOException,
+            UmlException {
+        OutputStream stream = new FileOutputStream(destiny);
+        XmiWriter xmiWriter = 
+            Model.getXmiWriter(model, stream, 
+                    ApplicationVersion.getVersion() + "("
+                        + UmlFilePersister.PERSISTENCE_VERSION + ")");
+        xmiWriter.write();
+    }
+
+    private File getTargetFile() {
+        // show a chooser dialog for the file name, only xmi is allowed
+        JFileChooser chooser = new JFileChooser();
+        chooser.setDialogTitle(Translator.localize(
+                                       "action.export-profile-as-xmi"));
+        chooser.setFileView(ProjectFileView.getInstance());
+        chooser.setApproveButtonText(Translator.localize(
+                                             "filechooser.export"));
+        chooser.setAcceptAllFileFilterUsed(true);
+        chooser.setFileFilter(new FileFilter() {
+
+            public boolean accept(File file) {
+                return file.isDirectory() || isXmiFile(file);
+            }
+
+
+
+            public String getDescription() {
+                return "*.XMI";
+            }
+
+        });
+
+        String fn =
+            Configuration.getString(
+                PersistenceManager.KEY_PROJECT_NAME_PATH);
+        if (fn.length() > 0) {
+            fn = PersistenceManager.getInstance().getBaseName(fn);
+            chooser.setSelectedFile(new File(fn));
+        }
+
+        int result = chooser.showSaveDialog(ArgoFrame.getInstance());
+        if (result == JFileChooser.APPROVE_OPTION) {
+            File theFile = chooser.getSelectedFile();
+            if (theFile != null) {
+                if (!theFile.getName().toUpperCase().endsWith(".XMI")) {
+                    theFile = new File(theFile.getAbsolutePath() + ".XMI");
+                }
+                return theFile;
+            }
+        }
+        
+        return null;
+    }
+    
+    private static boolean isXmiFile(File file) {
+        return file.isFile()
+                && (file.getName().toLowerCase().endsWith(".xml") 
+                        || file.getName().toLowerCase().endsWith(".xmi"));
+    }
+}

Modified: trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java?view=diff&rev=16147&p1=trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java&p2=trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java	(original)
+++ trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java	2008-11-23 10:03:41-0800
@@ -41,7 +41,6 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.Writer;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -522,11 +521,6 @@
         return new XmiReaderEUMLImpl(this);
     }
 
-    public XmiWriterEUMLImpl getXmiWriter(Object model, Writer writer,
-            String version) throws UmlException {
-        return new XmiWriterEUMLImpl(this, model, writer, version);
-    }
-
     public XmiWriterEUMLImpl getXmiWriter(Object model, OutputStream stream,
             String version) throws UmlException {
         return new XmiWriterEUMLImpl(this, model, stream, version);

Modified: trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java?view=diff&rev=16147&p1=trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java&p2=trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java	(original)
+++ trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java	2008-11-23 10:03:41-0800
@@ -28,11 +28,9 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.Writer;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.argouml.model.NotImplementedException;
 import org.argouml.model.UmlException;
 import org.argouml.model.XmiExtensionWriter;
 import org.argouml.model.XmiWriter;
@@ -58,14 +56,6 @@
     private org.eclipse.uml2.uml.Package model;
     
     /**
-     * Old style constructor.  Unsupported (and shouldn't get called)
-     */
-    public XmiWriterEUMLImpl(EUMLModelImplementation implementation,
-            Object model, Writer writer, String version) {
-        throw new NotImplementedException();
-    }
-    
-    /**
      * Constructor.
      * 
      * @param implementation

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&rev=16147&p1=trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java&p2=trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java&r1=16146&r2=16147
==============================================================================
--- 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	2008-11-23 10:03:41-0800
@@ -692,12 +692,6 @@
         return reader;
     }
 
-    @SuppressWarnings("deprecation")
-    public XmiWriter getXmiWriter(Object model, Writer writer, String version)
-        throws UmlException {
-        return new XmiWriterMDRImpl(this, model, writer, version);
-    }
-
 
     public XmiWriter getXmiWriter(Object model, OutputStream stream,
             String version) throws UmlException {

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java?view=diff&rev=16147&p1=trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java&p2=trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java	2008-11-23 10:03:41-0800
@@ -27,7 +27,6 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.Writer;
-import java.util.Arrays;
 
 import javax.jmi.reflect.RefObject;
 import javax.jmi.reflect.RefPackage;
@@ -96,30 +95,7 @@
                 .getObjectToId()));
         config.setHeaderProvider(new XmiHeaderProviderImpl(version));
     }
-    
-    /**
-     * Create an XMI writer for the given model.
-     * 
-     * @param theParent
-     *            The ModelImplementation
-     * @param theModel
-     *            The Model to write. If null, write all top-level model
-     *            elements.
-     * @param theWriter
-     *            The writer to write to
-     * @param version the ArgoUML version
-     * @throws IllegalArgumentException if no writer provided
-     * @deprecated for 0.25.4 by tfmorris.  Use 
-     * {@link #XmiWriterMDRImpl(MDRModelImplementation, Object, OutputStream, String)}.
-     */
-    public XmiWriterMDRImpl(MDRModelImplementation theParent, Object theModel,
-            Writer theWriter, String version) {
-        this(theParent, theModel, version);
-        if (theWriter == null) {
-            throw new IllegalArgumentException("A writer must be provided");
-        }
-        writer = theWriter;
-    }
+
     
     /**
      * Create an XMI writer for the given model.
@@ -151,126 +127,12 @@
         XMIWriter xmiWriter = XMIWriterFactory.getDefault().createXMIWriter(
                 config);
         try {
-            OutputStream stream;
-            if (oStream == null) {
-                LOG.debug("XMI writer using wrapped output writer");
-                stream = new WriterOuputStream(writer);                
-            } else {
-                LOG.debug("XMI writer using native stream");
-                stream = oStream;
-            }
             RefPackage extent = ((RefObject) model).refOutermostPackage();
-            xmiWriter.write(stream, "file:///ThisIsADummyName.xmi", extent,
+            xmiWriter.write(oStream, "file:///ThisIsADummyName.xmi", extent,
                     XMI_VERSION);
         } catch (IOException e) {
             throw new UmlException(e);
-        }
-    }
-
-    /**
-     * Class which wraps a Writer into an OutputStream.
-     * 
-     * TODO: This entire class can go away when we remove
-     * the Writer based interface.
-     * 
-     * @author lmaitre
-     * @deprecated for 0.25.4 by tfmorris
-     */
-    private class WriterOuputStream extends OutputStream {
-
-        private Writer myWriter;
-        private boolean inTag = false;
-        private char tagName[] = new char[12];
-        private int tagLength = 0;
-
-        /**
-         * Constructor.
-         * @param wrappedWriter The myWriter which will be wrapped
-         */
-        public WriterOuputStream(Writer wrappedWriter) {
-            if (wrappedWriter == null) {
-                throw new IllegalArgumentException("No writer provided");
-            }
-            this.myWriter = wrappedWriter;
-        }
-
-        /*
-         * @see java.io.OutputStream#close()
-         */
-        public void close() throws IOException {
-            myWriter.close();
-        }
-
-        /*
-         * @see java.io.OutputStream#flush()
-         */
-        public void flush() throws IOException {
-            myWriter.flush();
-        }
-
-        /*
-         * @see java.io.OutputStream#write(byte[], int, int)
-         */
-        public void write(byte[] b, int off, int len) throws IOException {
-            char[] c = new String(b, off, len, ENCODING).toCharArray();
-            if (xmiExtensionWriter != null) {
-                write(c);
-            } else {
-                myWriter.write(c, 0, c.length);
-            }
-        }
-
-        /*
-         * @see java.io.OutputStream#write(byte[])
-         */
-        public void write(byte[] b) throws IOException {
-            write(b, 0, b.length);
-        }
-
-        /*
-         * @see java.io.OutputStream#write(int)
-         */
-        public void write(int b) throws IOException {
-            write(new byte[] {(byte) (b & 255)}, 0, 1);
-        }
-        
-        /*
-         * @see java.io.OutputStream#write(int)
-         */
-        private void write(char[] ca) throws IOException {
-            
-            int len = ca.length;
-            for (int i = 0; i < len; ++i) {
-                char ch = ca[i];
-                if (inTag) {
-                    if (ch == '>') {
-                        inTag = false;
-                        if (Arrays.equals(tagName, TARGET)) {
-                            if (i > 0) {
-                                myWriter.write(ca, 0, i + 1);
-                            }
-                            xmiExtensionWriter.write(myWriter);
-                            xmiExtensionWriter = null;
-                            if (i + 1 != len - 1) {
-                                myWriter.write(ca, i + 1, (len - i) - 1);
-                            }
-                            return;
-                        }
-                    } else if (tagLength == 12) {
-                        inTag = false;
-                    } else {
-                        tagName[tagLength++] = ch;
-                    }
-                }
-                
-                if (ch == '<') {
-                    inTag = true;
-                    Arrays.fill(tagName, ' ');
-                    tagLength = 0;
-                }
-            }
-            myWriter.write(ca, 0, ca.length);
-        }
+        } 
     }
 
     public void setXmiExtensionWriter(XmiExtensionWriter theWriter) {

Modified: trunk/src/argouml-core-model/src/org/argouml/model/Model.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model/src/org/argouml/model/Model.java?view=diff&rev=16147&p1=trunk/src/argouml-core-model/src/org/argouml/model/Model.java&p2=trunk/src/argouml-core-model/src/org/argouml/model/Model.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-core-model/src/org/argouml/model/Model.java	(original)
+++ trunk/src/argouml-core-model/src/org/argouml/model/Model.java	2008-11-23 10:03:41-0800
@@ -441,26 +441,7 @@
         return impl.getXmiReader();
     }
 
-    /**
-     * Get the XmiWriter object.
-     * 
-     * @param model
-     *            the project member model
-     * @param writer
-     *            the writer
-     * @param version
-     *            string to be written into file header as XMI writer version
-     * @return the object implementing the XmiWriter interface
-     * @throws UmlException
-     *             on any error while writing
-     * @deprecated for 0.25.4 by tfmorris. Use
-     *             {@link #getXmiWriter(Object, OutputStream, String)}.
-     */
-    @Deprecated
-    public static XmiWriter getXmiWriter(Object model, Writer writer,
-            String version) throws UmlException {
-        return impl.getXmiWriter(model, writer, version);
-    }
+
     
     /**
      * Get the XmiWriter object.

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&rev=16147&p1=trunk/src/argouml-core-model/src/org/argouml/model/ModelImplementation.java&p2=trunk/src/argouml-core-model/src/org/argouml/model/ModelImplementation.java&r1=16146&r2=16147
==============================================================================
--- trunk/src/argouml-core-model/src/org/argouml/model/ModelImplementation.java	(original)
+++ trunk/src/argouml-core-model/src/org/argouml/model/ModelImplementation.java	2008-11-23 10:03:41-0800
@@ -275,25 +275,6 @@
      */
     XmiReader getXmiReader() throws UmlException;
 
-    /**
-     * A factory method that creates a new instance of an XmiWriter on each
-     * call.
-     * 
-     * @param model
-     *            the project member model
-     * @param writer
-     *            the writer
-     * @param version
-     *            the version of ArgoUML
-     * @return the object implementing the XmiWriter interface
-     * @throws UmlException
-     *             on any error while writing
-     * @deprecated for 0.25.4 by tfmorris. Use
-     *             {@link #getXmiWriter(Object, OutputStream, String)}.
-     */
-    @Deprecated
-    XmiWriter getXmiWriter(Object model, Writer writer, String version)
-        throws UmlException;
 
     /**
      * A factory method that creates a new instance of an XmiWriter on each
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.