svn commit: r12797 - trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-06-08 12:33:57-0700
New Revision: 12797

Modified:
   trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java

Log:
Implement getAllModelElementsOfKind

Modified: trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java?view=diff&rev=12797&p1=trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java&r1=12796&r2=12797
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java	(original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java	2007-06-08 12:33:57-0700
@@ -37,6 +37,7 @@
 import org.eclipse.uml2.uml.Element;
 import org.eclipse.uml2.uml.NamedElement;
 import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.Type;
 
 
 /**
@@ -87,55 +88,28 @@
         if (type instanceof String) {
             return getAllModelElementsOfKind(nsa, (String) type);
         }
-        if (!(nsa instanceof Namespace) || !(type instanceof Class)) {
+        if (!(nsa instanceof org.eclipse.uml2.uml.Package) || !(type instanceof Class)) {
             throw new IllegalArgumentException("illegal argument - namespace: "
                     + nsa + " type: " + type);
         }
-
-        return Collections.EMPTY_SET;
-        
-        // TODO: MDR impelementation below - needs review/conversion
         
-        /*
-         * Because we get the metatype class stripped of its reflective
-         * proxies, we need to jump through a hoop or two to find it
-         * in the metamodel, then work from there to get its proxy.
-         */
-//        String name = ((Class) type).getName();
-//        name = name.substring(name.lastIndexOf(".") + 1);
-//        if (name.startsWith("Uml")) name = name.substring(3);
-//
-//        Collection allOfType = Collections.EMPTY_LIST;
-//        // Get all (UML) metaclasses and search for the requested one
-//        Collection metaTypes = nsmodel.getModelPackage().getMofClass()
-//                .refAllOfClass();
-//        for (Iterator it = metaTypes.iterator(); it.hasNext();) {
-//            MofClass elem = (MofClass) it.next();
-//            // TODO: Generalize - assumes UML type names are unique
-//            // without the qualifying package names - true for UML 1.4
-//            if (name.equals(elem.getName())) {
-//                List names = elem.getQualifiedName();
-//                // TODO: Generalize to handle more than one level of package
-//                // OK for UML 1.4 because of clustering
-//                RefPackage pkg = nsmodel.getUmlPackage().refPackage(
-//                        (String) names.get(0));
-//                // Get the metatype proxy and use it to find all instances
-//                RefClass classProxy = pkg.refClass((String) names.get(1));
-//                allOfType = classProxy.refAllOfType();
-//                break;
-//            }
-//        }
-//
-//        // Remove any elements not in requested namespace
-//        Collection returnElements = new ArrayList();
-//        for (Iterator i = allOfType.iterator(); i.hasNext();) {
-//            Object me = i.next();
-//            // TODO: Optimize for root model case? - tfm
-//            if (contained(nsa, me)) {
-//                returnElements.add(me);
-//            } 
-//        }
-//        return returnElements;
+        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);
+            }
+        }
+
+        for (org.eclipse.uml2.uml.Package nestedPackage : pkg
+                .getNestedPackages()) {
+            result.addAll(getAllModelElementsOfKind(nestedPackage, typeClass));
+        }
+        return result;        
+
+
 
     }
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.