svn commit: r13757 - trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-11-11 03:22:52-0800
New Revision: 13757

Modified:
   trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java

Log:
Fix NPE in getElement

Modified: trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java?view=diff&rev=13757&p1=trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java&p2=trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java&r1=13756&r2=13757
==============================================================================
--- trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java	(original)
+++ trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java	2007-11-11 03:22:52-0800
@@ -39,6 +39,7 @@
 import javax.jmi.reflect.RefObject;
 import javax.jmi.reflect.RefPackage;
 
+import org.apache.log4j.Logger;
 import org.argouml.model.InvalidElementException;
 import org.argouml.model.ModelManagementHelper;
 import org.omg.uml.behavioralelements.collaborations.Collaboration;
@@ -67,13 +68,17 @@
  */
 class ModelManagementHelperMDRImpl implements ModelManagementHelper {
     
+    private static final Logger LOG = 
+        Logger.getLogger(ModelManagementHelperMDRImpl.class);
+    
     /**
      * The model implementation.
      */
     private MDRModelImplementation modelImpl;
 
     /**
-     * Don't allow instantiation.
+     * Construct a ModelManagementHelper.  Not for use outside of the
+     * Model subsystem implementation.
      * 
      * @param implementation
      *            To get other helpers and factories.
@@ -166,6 +171,7 @@
     
 
     public Collection getAllModelElementsOfKind(Object nsa, Object type) {
+        long startTime = System.currentTimeMillis();
         if (nsa == null || type == null) {
             return Collections.EMPTY_LIST;
         }
@@ -184,7 +190,9 @@
          */
         String name = ((Class) type).getName();
         name = name.substring(name.lastIndexOf(".") + 1);
-        if (name.startsWith("Uml")) name = name.substring(3);
+        if (name.startsWith("Uml")) {
+            name = name.substring(3);
+        }
 
         Collection allOfType = Collections.EMPTY_LIST;
         // Get all (UML) metaclasses and search for the requested one
@@ -216,6 +224,8 @@
                 returnElements.add(me);
             } 
         }
+        long duration = System.currentTimeMillis() - startTime;
+        LOG.debug("Get allOfKind took " + duration + " msec.");
         return returnElements;
     }
 
@@ -227,8 +237,9 @@
         Object current = 
             modelImpl.getFacade().getModelElementContainer(candidate);
         while (current != null) {
-            if (container.equals(current))
+            if (container.equals(current)) {
                 return true;
+            }
             current = modelImpl.getFacade().getModelElementContainer(current);
         }
         return false;
@@ -330,24 +341,27 @@
 
     public Object getElement(List<String> path, Object theRootNamespace) {
         ModelElement root = (ModelElement) theRootNamespace;
-        // TODO: This is very inefficient.  Investigate a direct method - tfm
-        
+
         for (int i = 0; i < path.size(); i++) {
             if (root == null || !(root instanceof Namespace)) {
                 return null;
             }
 
             String name = path.get(i);
-            root = null;
+            boolean found = false;
             for (ModelElement me : ((Namespace) root).getOwnedElement()) {
                 if (i < path.size() - 1 && !(me instanceof Namespace)) {
                     continue;
                 }
                 if (name.equals(me.getName())) {
                     root = me;
+                    found = true;
                     break;
                 }
             }
+            if (!found) {
+                return null;
+            }
         }
         return root;
     }
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.