svn commit: r13205 - branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: b00__1
Date: 2007-08-02 04:21:17-0700
New Revision: 13205

Modified:
   branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java

Log:
getAllModelElementsOfKind uses a namespace as the container

Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java?view=diff&rev=13205&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java&r1=13204&r2=13205
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java	(original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java	2007-08-02 04:21:17-0700
@@ -28,7 +28,6 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.Vector;
@@ -37,7 +36,6 @@
 import org.eclipse.uml2.uml.Element;
 import org.eclipse.uml2.uml.NamedElement;
 import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.Type;
 
 
 /**
@@ -71,8 +69,11 @@
         return null;
     }
 
-    public Collection getAllContents(Object namespace) {
-        return ((Element) namespace).allOwnedElements();
+    public Collection getAllContents(Object element) {
+        if (!(element instanceof Element)) {
+            throw new IllegalArgumentException("The argument must be instance of Element"); //$NON-NLS-1$
+        }
+        return ((Element) element).allOwnedElements();
     }
 
     public Collection getAllImportedElements(Object pack) {
@@ -81,36 +82,36 @@
     }
 
     public Collection getAllModelElementsOfKind(Object nsa, Object type) {
-
-        if (nsa == null || type == null) {
-            return Collections.EMPTY_LIST;
+        if (!(nsa instanceof Namespace)) {
+            throw new IllegalArgumentException(
+                    "nsa must be instance of Namespace"); //$NON-NLS-1$
         }
+        Class theType = null;
         if (type instanceof String) {
-            return getAllModelElementsOfKind(nsa, (String) type);
-        }
-        if (!(nsa instanceof org.eclipse.uml2.uml.Package) || !(type instanceof Class)) {
-            throw new IllegalArgumentException("illegal argument - namespace: "
-                    + nsa + " type: " + type);
-        }
-        
-        org.eclipse.uml2.uml.Package pkg = (org.eclipse.uml2.uml.Package) nsa;
-        Class typeClass = (Class) type;
-
-        Collection<Type> result = new HashSet<Type>();
-        for (Type ownedType : pkg.getOwnedTypes()) {
-            if (typeClass.isAssignableFrom(ownedType.getClass())) {
-                result.add(ownedType);
+            try {
+                theType = Class.forName((String) type);
+            } catch (ClassNotFoundException e) {
+                throw new IllegalArgumentException(e);
             }
+        } else if (type instanceof Class) {
+            theType = (Class) type;
+        } else {
+            throw new IllegalArgumentException(
+                    "type must be instance of Class or String"); //$NON-NLS-1$
         }
-
-        for (org.eclipse.uml2.uml.Package nestedPackage : pkg
-                .getNestedPackages()) {
-            result.addAll(getAllModelElementsOfKind(nestedPackage, typeClass));
+        if (!Element.class.isAssignableFrom(theType)) {
+            throw new IllegalArgumentException("type must represent an Element"); //$NON-NLS-1$
         }
-        return result;        
 
+        Collection<Element> result = new ArrayList<Element>();
 
+        for (Element element : ((Namespace) nsa).allOwnedElements()) {
+            if (theType.isAssignableFrom(element.getClass())) {
+                result.add(element);
+            }
+        }
 
+        return result;
     }
 
     /*
@@ -128,12 +129,7 @@
     }
     
     public Collection getAllModelElementsOfKind(Object nsa, String kind) {
-        try {
-            return getAllModelElementsOfKind(nsa, Class.forName(kind));
-        } catch (ClassNotFoundException cnfe) {
-            throw new IllegalArgumentException(
-                    "Can't derive a class name from " + kind);
-        }
+        return getAllModelElementsOfKind(nsa, kind);
     }
 
     public Collection getAllModelElementsOfKindWithModel(Object model,
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.