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

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2008-12-19 07:50:11-0800
New Revision: 16386

Modified:
   trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java
   trunk/src/argouml-app/src/org/argouml/persistence/PGMLStackParser.java
   trunk/src/argouml-app/src/org/argouml/persistence/PersistenceManager.java

Log:
Allow modules to register their own class translations.

The sequence2 module now does this so those translations are now removed from PGMLStackParser

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=16386&r1=16385&r2=16386
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/DiagramMemberFilePersister.java	2008-12-19 07:50:11-0800
@@ -30,7 +30,10 @@
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
 
+import org.apache.log4j.Logger;
 import org.argouml.application.api.Argo;
 import org.argouml.kernel.Project;
 import org.argouml.kernel.ProjectMember;
@@ -46,10 +49,20 @@
  * @author Bob Tarling
  */
 class DiagramMemberFilePersister extends MemberFilePersister {
+    
+    /**
+     * Logger.
+     */
+    private static final Logger LOG =
+        Logger.getLogger(DiagramMemberFilePersister.class);
+    
     /**
      * The tee file for persistence.
      */
     private static final String PGML_TEE = "/org/argouml/persistence/PGML.tee";
+    
+    private static final Map<String, String> CLASS_TRANSLATIONS =
+        new HashMap<String, String>();
 
     @Override
     public void load(Project project, InputStream inputStream)
@@ -67,6 +80,13 @@
             // TODO: We need the project specific diagram settings here
             PGMLStackParser parser = new PGMLStackParser(project.getUUIDRefs(),
                     defaultSettings);
+            LOG.info("Adding translations registered by modules");
+            for (Map.Entry<String, String> translation
+                    : CLASS_TRANSLATIONS.entrySet()) {
+                parser.addTranslation(
+                        translation.getKey(),
+                        translation.getValue());
+            }
             ArgoDiagram d = parser.readArgoDiagram(inputStream, false);
             inputStream.close();
             project.addMember(d);
@@ -129,5 +149,17 @@
         
     }
 
-
+    /**
+     * Figs are stored by class name and recreated by reflection. If the class
+     * name changes or moves this provides a simple way of translating from
+     * class name at time of save to the current class name without need for
+     * XSL.
+     * @param originalClassName
+     * @param newClassName
+     */
+    public void addTranslation(
+            final String originalClassName,
+            final String newClassName) {
+        CLASS_TRANSLATIONS.put(originalClassName, newClassName);
+    }
 }

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=16386&r1=16385&r2=16386
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/PGMLStackParser.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/PGMLStackParser.java	2008-12-19 07:50:11-0800
@@ -120,33 +120,6 @@
                 "org.argouml.uml.diagram.deployment.ui.FigNodeInstance");
         addTranslation("org.argouml.uml.diagram.ui.FigRealization",
                 "org.argouml.uml.diagram.ui.FigAbstraction");
-        // Replace any old sequence figs with Seq2
-        // this may change if we refactor package structure
-        try {
-            Class<?> clazz = Class.forName(
-                    "org.argouml.uml.diagram.sequence2.ui.UMLSequenceDiagram");
-            addTranslation(
-                    "org.argouml.uml.diagram.sequence.ui.UMLSequenceDiagram",
-                    "org.argouml.uml.diagram.sequence2.ui.UMLSequenceDiagram");
-            addTranslation(
-                    "org.argouml.uml.diagram.sequence.ui.FigCreateActionMessage",
-                    "org.argouml.uml.diagram.sequence2.ui.FigMessage");
-            addTranslation(
-                    "org.argouml.uml.diagram.sequence.ui.FigDeleteActionMessage",
-                    "org.argouml.uml.diagram.sequence2.ui.FigMessage");
-            addTranslation(
-                    "org.argouml.uml.diagram.sequence.ui.FigCallActionMessage",
-                    "org.argouml.uml.diagram.sequence2.ui.FigMessage");
-            addTranslation(
-                    "org.argouml.uml.diagram.sequence.ui.FigReturnActionMessage",
-                    "org.argouml.uml.diagram.sequence2.ui.FigMessage");
-            addTranslation(
-                    "org.argouml.uml.diagram.sequence.ui.FigClassifierRole",
-                    "org.argouml.uml.diagram.sequence2.ui.FigClassifierRole");
-        } catch (ClassNotFoundException e) {
-            // Temporarily ignore until I can work out how to get tests to
-            // this.
-        }
     }
     
     /**

Modified: trunk/src/argouml-app/src/org/argouml/persistence/PersistenceManager.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/PersistenceManager.java?view=diff&pathrev=16386&r1=16385&r2=16386
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/PersistenceManager.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/PersistenceManager.java	2008-12-19 07:50:11-0800
@@ -410,6 +410,23 @@
     public AbstractFilePersister getSavePersister() {
         return savePersister;
     }
+    
+    /**
+     * Figs are stored by class name and recreated by reflection. If the class
+     * name changes or moves this provides a simple way of translating from
+     * class name at time of save to the current class name without need for
+     * XSL.
+     * @param originalClassName The class name that may be in the save file
+     * @param newClassName The class name to use in preference
+     */
+    public void addTranslation(
+            final String originalClassName,
+            final String newClassName) {
+        getDiagramMemberFilePersister().addTranslation(
+                originalClassName,
+                newClassName);
+    }
+    
 }
 
 /**

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

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.