svn commit: r17497 - trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java

Thomas Neustupny <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: thn
Date: 2009-11-19 23:47:19-0800
New Revision: 17497

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

Log:
support for profile hierarchy (profiles containing subprofiles to allow for organizing of stereotypes), this is the only way eclipse UML2 allows it to do

Modified: trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java?view=diff&pathrev=17497&r1=17496&r2=17497
==============================================================================
--- trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java	(original)
+++ trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java	2009-11-19 23:47:19-0800
@@ -39,6 +39,7 @@
 import org.eclipse.uml2.uml.Class;
 import org.eclipse.uml2.uml.Element;
 import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Package;
 import org.eclipse.uml2.uml.Profile;
 import org.eclipse.uml2.uml.Stereotype;
 import org.eclipse.uml2.uml.UMLPackage;
@@ -67,21 +68,11 @@
     public void addBaseClass(Object handle, Object baseClass) {
         if (handle instanceof Stereotype) {
             org.eclipse.uml2.uml.Class metaclass = getMetaclass(baseClass);
-            Profile profile = (Profile) modelImpl.getFacade().getRoot(handle);
+            Profile profile = ((Stereotype) handle).getProfile();
             if (metaclass != null && profile != null) {
                 profile.createMetaclassReference(metaclass);
-                Stereotype st = (Stereotype) handle;
-                if (st.getProfile() != null) {
-                    st.createExtension(metaclass, false);
-                    return;
-                } else if (st.getPackage() != null){
-                    // TODO: check if this hack is ok
-                    org.eclipse.uml2.uml.Package p = st.getPackage();
-                    st.setPackage(profile);
-                    st.createExtension(metaclass, false);
-                    st.setPackage(p);
-                    return;
-                }
+                ((Stereotype) handle).createExtension(metaclass, false);
+                return;
             }
         }
         throw new IllegalArgumentException(
@@ -109,6 +100,15 @@
             } else if (handle instanceof Profile) {
                 ((Profile) handle).applyProfile((Profile) profile);
             }
+            // also apply subprofiles:
+            Iterator<Package> iter =
+                ((Profile) profile).getNestedPackages().iterator();
+            while (iter.hasNext()) {
+                Package p = iter.next();
+                if (p instanceof Profile) {
+                    applyProfile(handle, p);
+                }
+            }
         }
     }
 
@@ -209,10 +209,14 @@
         if (models != null) {
             for (Object ns : models) {
                 if (ns instanceof Profile) {
-                    Iterator iter = ((Profile) ns).getOwnedStereotypes()
-                            .iterator();
+                    l.addAll(((Profile) ns).getOwnedStereotypes());
+                    Iterator<Package> iter =
+                        ((Profile) ns).getNestedPackages().iterator();
                     while (iter.hasNext()) {
-                        l.add((Stereotype) iter.next());
+                        Package p = iter.next();
+                        if (p instanceof Profile) {
+                            l.addAll(getAllStereotypesIn((Profile) p));
+                        }
                     }
                 }
             }
@@ -331,6 +335,15 @@
             } else if (handle instanceof Profile) {
                 ((Profile) handle).unapplyProfile((Profile) profile);
             }
+            // also unapply subprofiles:
+            Iterator<Package> iter =
+                ((Profile) profile).getNestedPackages().iterator();
+            while (iter.hasNext()) {
+                Package p = iter.next();
+                if (p instanceof Profile) {
+                    unapplyProfile(handle, p);
+                }
+            }
         }
     }
 
@@ -338,10 +351,33 @@
         Object result = null;
         if (handle instanceof Profile) {
             result = ((Profile) handle).define();
+            // also define subprofiles:
+            Iterator<Package> iter =
+                ((Profile) handle).getNestedPackages().iterator();
+            while (iter.hasNext()) {
+                Package p = iter.next();
+                if (p instanceof Profile) {
+                    makeProfileApplicable(p);
+                }
+            }
         }
         return result;
     }
 
+    private Collection<Stereotype> getAllStereotypesIn(Profile p) {
+        List<Stereotype> l = new ArrayList<Stereotype>();
+        Iterator<Element> iter = p.getOwnedElements().iterator();
+        while (iter.hasNext()) {
+            Element elem = iter.next();
+            if (elem instanceof Stereotype) {
+                l.add((Stereotype) elem);
+            } else if (elem instanceof Profile) {
+                l.addAll(getAllStereotypesIn((Profile) elem));
+            }
+        }
+        return l;
+    }
+
     private org.eclipse.uml2.uml.Class getMetaclass(Object baseClass) {
         org.eclipse.uml2.uml.Class metaclass = null;
         if (baseClass instanceof String) {

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

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.