svn commit: r13631 - trunk/src_new/org/argouml/kernel

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-10-03 16:40:39-0700
New Revision: 13631

Modified:
   trunk/src_new/org/argouml/kernel/Project.java
   trunk/src_new/org/argouml/kernel/ProjectImpl.java

Log:
Issue 4875 - Improve compatibility for mixing old & new style root management method invocations.

Improve encapsulation - more final args, return unmodifiable copies of internal collections, not the collections themselves

Modified: trunk/src_new/org/argouml/kernel/Project.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/Project.java?view=diff&rev=13631&p1=trunk/src_new/org/argouml/kernel/Project.java&p2=trunk/src_new/org/argouml/kernel/Project.java&r1=13630&r2=13631
==============================================================================
--- trunk/src_new/org/argouml/kernel/Project.java	(original)
+++ trunk/src_new/org/argouml/kernel/Project.java	2007-10-03 16:40:39-0700
@@ -43,7 +43,7 @@
  * project. It contains the list of diagrams and UML models, various project
  * properties such as the author's name, and defaults for various settings.
  * <p>
- * TODO: This interface was mechanically refactored from the implemenation class
+ * TODO: This interface was mechanically refactored from the implementation class
  * {@link ProjectImpl}. It needs to be reviewed and cleaned up, eliminating
  * methods which should be part of the public API and splitting the interface
  * into smaller function specific (e.g. TrashCan) interfaces.
@@ -75,7 +75,7 @@
      * @throws URISyntaxException if the argument cannot be converted to
      *         an URI.
      */
-    public void setName(String n) throws URISyntaxException;
+    public void setName(final String n) throws URISyntaxException;
 
     /**
      * Get the URI for this project.
@@ -89,7 +89,7 @@
      *
      * @param theUri The URI to set.
      */
-    public void setURI(URI theUri);
+    public void setURI(final URI theUri);
 
     /**
      * Set the project file.
@@ -98,7 +98,7 @@
      *
      * @param file File to set the project to.
      */
-    public void setFile(File file);
+    public void setFile(final File file);
 
     /**
      * Not used by "argo.tee" any more.
@@ -125,7 +125,7 @@
      * Sets the searchpath.
      * @param theSearchpath The searchpath to set
      */
-    public void setSearchPath(List<String> theSearchpath);
+    public void setSearchPath(final List<String> theSearchpath);
     
     /**
      * Get all members of the project.
@@ -140,12 +140,12 @@
      * 
      * @param m the member to be added
      */
-    public void addMember(Object m);
+    public void addMember(final Object m);
 
     /**
      * @param model a namespace
      */
-    public void addModel(Object model);
+    public void addModel(final Object model);
 
     /**
      * Get the author name. 
@@ -189,7 +189,7 @@
      * Set the new version.
      * @param s The new version.
      */
-    public void setVersion(String s);
+    public void setVersion(final String s);
 
     /**
      * Get the description.
@@ -219,7 +219,7 @@
      *
      * @param s The new history file.
      */
-    public void setHistoryFile(String s);
+    public void setHistoryFile(final String s);
 
 
     /**
@@ -343,7 +343,7 @@
     /**
      * @param m the namespace
      */
-    public void setCurrentNamespace(Object m);
+    public void setCurrentNamespace(final Object m);
 
     /**
      * @return the namespace
@@ -381,7 +381,7 @@
     /**
      * @param d the diagram to be added
      */
-    public void addDiagram(ArgoDiagram d);
+    public void addDiagram(final ArgoDiagram d);
 
     /**
      * @param me the given modelelement
@@ -406,7 +406,7 @@
     public void preSave();
 
     /**
-     * This is execcuted after a save.
+     * This is executed after a save.
      */
     public void postSave();
 
@@ -450,7 +450,7 @@
      *          {@link #setProfiles(Collection)}.
      */
     @Deprecated
-    public void setDefaultModel(Object theDefaultModel);
+    public void setDefaultModel(final Object theDefaultModel);
 
     /**
      * @param packages
@@ -459,7 +459,7 @@
      *             {@link #getProfileConfiguration()} instead.
      */
     @Deprecated
-    public void setProfiles(Collection packages);
+    public void setProfiles(final Collection packages);
 
     /**
      * Get the default model.
@@ -506,7 +506,7 @@
      * @deprecated for 0.25.4 by tfmorris - use {@link #setRoots}.
      */
     @Deprecated
-    public void setRoot(Object root);
+    public void setRoot(final Object root);
 
 
     /**
@@ -523,7 +523,7 @@
      * 
      * @param elements Collection of top level ModelElements
      */
-    public void setRoots(Collection elements);
+    public void setRoots(final Collection elements);
     
     /**
      * Returns true if the given name is a valid name for a diagram. Valid means
@@ -560,13 +560,13 @@
      * @deprecated for 0.25.4 by tfmorris. Use {@link #setSearchPath(List)}.
      */
     @Deprecated
-    public void setSearchpath(Vector<String> theSearchpath);
+    public void setSearchpath(final Vector<String> theSearchpath);
 
     /**
      * Sets the uUIDRefs.
      * @param uUIDRefs The uUIDRefs to set
      */
-    public void setUUIDRefs(Map<String, Object> uUIDRefs);
+    public void setUUIDRefs(final Map<String, Object> uUIDRefs);
 
     /**
      * Sets the vetoSupport.
@@ -584,7 +584,7 @@
     /**
      * @param theDiagram the ArgoDiagram
      */
-    public void setActiveDiagram(ArgoDiagram theDiagram);
+    public void setActiveDiagram(final ArgoDiagram theDiagram);
 
     /**
      * Remove the project.
@@ -635,7 +635,7 @@
      * 
      * @param pc the profile configuration
      */
-    public void setProfileConfiguration(ProfileConfiguration pc);
+    public void setProfileConfiguration(final ProfileConfiguration pc);
 
     /**
      * Return the UndoManager for this project.  Undo is managed on a 

Modified: trunk/src_new/org/argouml/kernel/ProjectImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/ProjectImpl.java?view=diff&rev=13631&p1=trunk/src_new/org/argouml/kernel/ProjectImpl.java&p2=trunk/src_new/org/argouml/kernel/ProjectImpl.java&r1=13630&r2=13631
==============================================================================
--- trunk/src_new/org/argouml/kernel/ProjectImpl.java	(original)
+++ trunk/src_new/org/argouml/kernel/ProjectImpl.java	2007-10-03 16:40:39-0700
@@ -99,7 +99,7 @@
 
     private ProjectSettings projectSettings;
 
-    private List<String> searchpath;
+    private final List<String> searchpath = new ArrayList<String>();
 
     // TODO: break into 3 main member types
     // model, diagram and other
@@ -119,7 +119,7 @@
     private final List models = new ArrayList();
     
     private Object root;
-    private Collection roots = new HashSet();
+    private final Collection roots = new HashSet();
     
 
     /**
@@ -143,7 +143,7 @@
      */
     private HashMap<String, Object> defaultModelTypeCache;
 
-    private Collection trashcan = new ArrayList();
+    private final Collection trashcan = new ArrayList();
 
     // TODO: Change this to use an UndoManager instance per project when
     // GEF has been enhanced.
@@ -176,7 +176,6 @@
         // this should be moved to a ui action.
         version = ApplicationVersion.getVersion();
 
-        searchpath = new ArrayList<String>();
         historyFile = "";
         defaultModelTypeCache = new HashMap<String, Object>();
 
@@ -201,7 +200,7 @@
     }
 
 
-    public void setName(String n)
+    public void setName(final String n)
         throws URISyntaxException {
         String s = "";
         if (getURI() != null) {
@@ -236,7 +235,7 @@
     }
 
 
-    public void setFile(File file) {
+    public void setFile(final File file) {
         URI theProjectUri = file.toURI();
 
         if (LOG.isDebugEnabled()) {
@@ -258,11 +257,11 @@
 
 
     public List<String> getSearchPathList() {
-        return searchpath;
+        return Collections.unmodifiableList(searchpath);
     }
 
 
-    public void addSearchPath(String searchPathElement) {
+    public void addSearchPath(final String searchPathElement) {
         if (!searchpath.contains(searchPathElement)) {
             searchpath.add(searchPathElement);
         }
@@ -319,7 +318,7 @@
     /**
      * @param m the model
      */
-    private void addModelMember(Object m) {
+    private void addModelMember(final Object m) {
 
         boolean memberFound = false;
         Object currentMember =
@@ -348,17 +347,20 @@
     }
 
 
-    public void addModel(Object model) {
+    public void addModel(final Object model) {
 
-        if (!Model.getFacade().isANamespace(model)) {
+        if (!Model.getFacade().isAModel(model)) {
             throw new IllegalArgumentException();
 	}
-
-        // fire indeterminate change to avoid copying vector
         if (!models.contains(model)) {
-            models.add(model);
-            roots.add(model);
-        }
+            setRoot(model);
+        }        
+        addModelInternal(model);
+    }
+
+    private void addModelInternal(final Object model) {
+        models.add(model);
+        roots.add(model);
         setCurrentNamespace(model);
         setSaveEnabled(true);
     }
@@ -486,7 +488,7 @@
     }
 
 
-    public void setHistoryFile(String s) {
+    public void setHistoryFile(final String s) {
         historyFile = s;
     }
 
@@ -632,7 +634,7 @@
     }
 
 
-    public void setCurrentNamespace(Object m) {
+    public void setCurrentNamespace(final Object m) {
 
         if (m != null && !Model.getFacade().isANamespace(m)) {
             throw new IllegalArgumentException();
@@ -676,7 +678,7 @@
     }
 
 
-    public void addDiagram(ArgoDiagram d) {
+    public void addDiagram(final ArgoDiagram d) {
         // send indeterminate new value instead of making copy of vector
 	d.setProject(this);
         diagrams.add(d);
@@ -896,7 +898,7 @@
 
 
     @SuppressWarnings("deprecation")
-    public void setDefaultModel(Object theDefaultModel) {
+    public void setDefaultModel(final Object theDefaultModel) {
         // TODO: Marcus Aurelio deprecated this, but also changed the
         // implementation to just throw an exception.  If it's no longer
         // functional, we probably need to just remove it altogether.
@@ -913,7 +915,7 @@
     }
 
     @Deprecated
-    public void setProfiles(Collection packages) {
+    public void setProfiles(final Collection packages) {
         // TODO: Marcus Aurelio deprecated this, but also changed the
         // implementation to just throw an exception.  If it's no longer
         // functional, we probably need to just remove it altogether.
@@ -1004,15 +1006,14 @@
         // TODO: We don't really want to do the following, but I'm not sure
         // what depends on it - tfm - 20070725
         Model.getModelManagementFactory().setRootModel(theRoot);
-        addModel(theRoot);
-        Collection newRoots = new ArrayList();
+        addModelInternal(theRoot);
+        roots.clear();
         roots.add(theRoot);
-        roots = newRoots;
     }
 
     
     public final Collection getRoots() {
-        return roots;
+        return Collections.unmodifiableCollection(roots);
     }
 
 
@@ -1031,7 +1032,8 @@
                 }
             }
         }
-        roots = elements;
+        roots.clear();
+        roots.addAll(elements);
     }
 
     public boolean isValidDiagramName(String name) {
@@ -1058,13 +1060,15 @@
 
 
     @SuppressWarnings("deprecation")
-    public void setSearchpath(Vector<String> theSearchpath) {
-        searchpath = theSearchpath;
+    public void setSearchpath(final Vector<String> theSearchpath) {
+        searchpath.clear();
+        searchpath.addAll(theSearchpath);
     }
 
 
-    public void setSearchPath(List<String> theSearchpath) {
-        searchpath = theSearchpath;
+    public void setSearchPath(final List<String> theSearchpath) {
+        searchpath.clear();
+        searchpath.addAll(theSearchpath);
     }
 
     public void setUUIDRefs(Map<String, Object> uUIDRefs) {
@@ -1082,7 +1086,7 @@
     }
 
 
-    public void setActiveDiagram(ArgoDiagram theDiagram) {
+    public void setActiveDiagram(final ArgoDiagram theDiagram) {
         activeDiagram = theDiagram;
     }
 
@@ -1101,8 +1105,8 @@
         }
         roots.clear();
         models.clear();
-
         diagrams.clear();
+        searchpath.clear();
 
         if (uuidRefs != null) {
             uuidRefs.clear();
@@ -1120,7 +1124,6 @@
         authoremail = null;
         description = null;
         version = null;
-        searchpath = null;
         historyFile = null;
         currentNamespace = null;
         vetoSupport = null;
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.