svn commit: r14731 - trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2008-05-14 07:57:39-0700
New Revision: 14731

Modified:
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java

Log:
Issue 5084: Enforce aggregation well-formedness 

http://argouml.tigris.org/issues/show_bug.cgi?id=5084

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java?view=diff&rev=14731&p1=trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java&p2=trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java&r1=14730&r2=14731
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java	2008-05-14 07:57:39-0700
@@ -598,6 +598,13 @@
         end.setAssociation((UmlAssociation) assoc);
         end.setParticipant((Classifier) type);
         end.setName(name);
+        // UML 1.4 WFR 2.5.3.1 #3 - no aggregation for N-ary associations
+        List<AssociationEnd> ends = ((UmlAssociation) assoc).getConnection();
+        if (ends.size() >= 3) {
+            for (AssociationEnd e : ends) {
+                e.setAggregation(AggregationKindEnum.AK_NONE);
+            }
+        }
         if (multi != null) {
             end.setMultiplicity((Multiplicity) multi);
         } else {

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java?view=diff&rev=14731&p1=trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java&p2=trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java&r1=14730&r2=14731
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java	2008-05-14 07:57:39-0700
@@ -2120,7 +2120,15 @@
     public void addConnection(Object handle, Object connection) {
         if (handle instanceof UmlAssociation
                 && connection instanceof AssociationEnd) {
-            ((UmlAssociation) handle).getConnection().add((AssociationEnd) connection);
+            List<AssociationEnd> ends = 
+                ((UmlAssociation) handle).getConnection();
+            ends.add((AssociationEnd) connection);
+            // UML 1.4 WFR 2.5.3.1 #3
+            if (ends.size() >= 3) {
+                for (AssociationEnd end : ends) {
+                    end.setAggregation(AggregationKindEnum.AK_NONE);
+                }
+            }
             return;
         }
         if (handle instanceof Link && connection instanceof LinkEnd) {
@@ -2137,6 +2145,14 @@
                 && connection instanceof AssociationEnd) {
             ((UmlAssociation) handle).getConnection().add(position,
                     (AssociationEnd) connection);
+            List<AssociationEnd> ends = 
+                ((UmlAssociation) handle).getConnection();
+            // UML 1.4 WFR 2.5.3.1 #3 - no aggregation for N-ary associations
+            if (ends.size() >= 3) {
+                for (AssociationEnd end : ends) {
+                    end.setAggregation(AggregationKindEnum.AK_NONE);
+                }
+            }
             return;
         }
         /* Strange, but the Link.getConnection() 
@@ -2492,8 +2508,16 @@
     public void setAggregation(Object handle, Object aggregationKind) {
         if (handle instanceof AssociationEnd
                 && aggregationKind instanceof AggregationKind) {
-            ((AssociationEnd) handle).
-                    setAggregation((AggregationKind) aggregationKind);
+            AggregationKind ak = (AggregationKind) aggregationKind;
+            AssociationEnd ae = (AssociationEnd) handle;
+            // We silently ignore requests which conflict with 
+            // UML 1.4 WFR 2.5.3.1 #3 - no aggregation for n-ary associations
+            if (ak == AggregationKindEnum.AK_NONE
+                    || ae.getAssociation().getConnection().size() < 3) {
+                ae.setAggregation(ak);
+            } else {
+                ae.setAggregation(AggregationKindEnum.AK_NONE);
+            }
             return;
         }
         throw new IllegalArgumentException("handle: " + handle
@@ -2626,8 +2650,15 @@
 
     public void setConnections(Object handle, Collection elems) {
         if (handle instanceof UmlAssociation && elems instanceof List) {
-            CollectionHelper.update(
-                    ((UmlAssociation) handle).getConnection(), elems);
+            List<AssociationEnd> ends = 
+                ((UmlAssociation) handle).getConnection();
+            CollectionHelper.update(ends, elems);
+            // UML 1.4 WFR 2.5.3.1 #3 - no aggregation for N-ary associations
+            if (ends.size() >= 3) {
+                for (AssociationEnd end : ends) {
+                    end.setAggregation(AggregationKindEnum.AK_NONE);
+                }
+            }
             return;
         }
         if (handle instanceof Link && elems instanceof List) {
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.