svn commit: r13368 - branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: b00__1
Date: 2007-08-15 09:44:14-0700
New Revision: 13368

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

Log:
Tweeked the connections

Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java?view=diff&rev=13368&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java&r1=13367&r2=13368
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java	(original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java	2007-08-15 09:44:14-0700
@@ -37,26 +37,25 @@
 import org.argouml.model.MetaTypes;
 import org.argouml.model.UmlFactory;
 import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.impl.EcoreFactoryImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.uml2.uml.Abstraction;
 import org.eclipse.uml2.uml.AggregationKind;
 import org.eclipse.uml2.uml.Association;
 import org.eclipse.uml2.uml.AssociationClass;
 import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Component;
 import org.eclipse.uml2.uml.Dependency;
 import org.eclipse.uml2.uml.Element;
 import org.eclipse.uml2.uml.Extend;
 import org.eclipse.uml2.uml.Generalization;
 import org.eclipse.uml2.uml.Include;
 import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.Message;
 import org.eclipse.uml2.uml.NamedElement;
 import org.eclipse.uml2.uml.PackageImport;
 import org.eclipse.uml2.uml.State;
 import org.eclipse.uml2.uml.Transition;
-import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.Type;
 import org.eclipse.uml2.uml.Usage;
 import org.eclipse.uml2.uml.UseCase;
 
@@ -121,20 +120,21 @@
         {Usage.class,            NamedElement.class, },
         {PackageImport.class,       NamedElement.class, },
         // The following is specifically for Realizations
+        // TODO: correction in GEF, it should use InterfaceRealization, not Abstraction
         {Abstraction.class, org.eclipse.uml2.uml.Class.class, Interface.class, null, },
         // The next 3 restrictions for Abstraction seem to be Argo specific
         // not something the UML spec requires - tfm - 20070215
-        {Abstraction.class, org.eclipse.uml2.uml.Class.class, org.eclipse.uml2.uml.Class.class, null, },
-        {Abstraction.class, org.eclipse.uml2.uml.Package.class,org.eclipse.uml2.uml.Package.class, null, },
-        {Abstraction.class, Component.class, Interface.class, null, },
-        {Association.class,     Classifier.class, }, 
+//        {Abstraction.class, org.eclipse.uml2.uml.Class.class, org.eclipse.uml2.uml.Class.class, null, },
+//        {Abstraction.class, org.eclipse.uml2.uml.Package.class,org.eclipse.uml2.uml.Package.class, null, },
+//        {Abstraction.class, Component.class, Interface.class, null, },
+        {Association.class,     Type.class, }, 
 //        {AssociationRole.class,  ClassifierRole.class, },
         {Extend.class,           UseCase.class, },
         {Include.class,          UseCase.class, },
 //        {Link.class, Instance.class, }, 
 //        {Transition.class,       StateVertex.class, },
         {Transition.class,       State.class, },
-        {AssociationClass.class, org.eclipse.uml2.uml.Class.class, }, 
+        {AssociationClass.class, Type.class, }, 
 //        {AssociationEnd.class, Classifier.class, Association.class, },
 //        {Message.class, ClassifierRole.class },
     };
@@ -154,72 +154,69 @@
         removedAnnotation.setSource(IS_REMOVED_NAME);
     }
 
-    // TODO: This is unchanged from UML 1.4 - needs review - tfm
     public Object buildConnection(Object elementType, Object fromElement,
             Object fromStyle, Object toElement, Object toStyle,
             Object unidirectional, Object namespace)
         throws IllegalModelElementConnectionException {
+        
+        IllegalModelElementConnectionException exception = new IllegalModelElementConnectionException("Cannot make a "
+                + elementType.getClass().getName() + " between a "
+                + fromElement.getClass().getName() + " and a "
+                + toElement.getClass().getName()); 
+        
         if (!isConnectionValid(elementType, fromElement, toElement, true)) {
-            throw new IllegalModelElementConnectionException("Cannot make a "
-                    + elementType.getClass().getName() + " between a "
-                    + fromElement.getClass().getName() + " and a "
-                    + toElement.getClass().getName());
+            throw exception;
         }
 
         Object connection = null;
 
         if (elementType == metaTypes.getAssociation()) {
             connection =
-                getCore().buildAssociation((Classifier) fromElement,
+                modelImpl.getCoreFactory().buildAssociation((Classifier) fromElement,
                     (AggregationKind) fromStyle, (Classifier) toElement,
                     (AggregationKind) toStyle, (Boolean) unidirectional);
         } else if (elementType == metaTypes.getAssociationEnd()) {
             if (fromElement instanceof Association) {
                 connection =
-                    getCore().buildAssociationEnd(toElement, fromElement);
+                    modelImpl.getCoreFactory().buildAssociationEnd(toElement, fromElement);
             } else if (fromElement instanceof Classifier) {
                 connection =
-                    getCore().buildAssociationEnd(fromElement, toElement);
+                    modelImpl.getCoreFactory().buildAssociationEnd(fromElement, toElement);
             }
         } else if (elementType
                 == metaTypes.getAssociationClass()) {
             connection =
-                getCore().buildAssociationClass(fromElement, toElement);
+                modelImpl.getCoreFactory().buildAssociationClass(fromElement, toElement);
         } else if (elementType == metaTypes.getAssociationRole()) {
             connection =
-                getCollaborations().buildAssociationRole(fromElement,
+                modelImpl.getCollaborationsFactory().buildAssociationRole(fromElement,
                     fromStyle, toElement, toStyle, (Boolean) unidirectional);
         } else if (elementType == metaTypes.getGeneralization()) {
-            connection = getCore().buildGeneralization(fromElement, toElement);
+            connection = modelImpl.getCoreFactory().buildGeneralization(fromElement, toElement);
         } else if (elementType == metaTypes.getPackageImport()) {
-            connection = getCore().buildPackageImport(fromElement, toElement);
+            connection = modelImpl.getCoreFactory().buildPackageImport(fromElement, toElement);
         } else if (elementType == metaTypes.getUsage()) {
-            connection = getCore().buildUsage(fromElement, toElement);
-        } else if (elementType == metaTypes.getGeneralization()) {
-            connection = getCore().buildGeneralization(fromElement, toElement);
+            connection = modelImpl.getCoreFactory().buildUsage(fromElement, toElement);
         } else if (elementType == metaTypes.getDependency()) {
-            connection = getCore().buildDependency(fromElement, toElement);
+            connection = modelImpl.getCoreFactory().buildDependency(fromElement, toElement);
         } else if (elementType == metaTypes.getAbstraction()) {
             connection =
-                getCore().buildRealization(fromElement, toElement, namespace);
+                modelImpl.getCoreFactory().buildRealization(fromElement, toElement, namespace);
         } else if (elementType == metaTypes.getLink()) {
-            connection = getCommonBehavior().buildLink(fromElement, toElement);
+            connection = modelImpl.getCommonBehaviorFactory().buildLink(fromElement, toElement);
         } else if (elementType == metaTypes.getExtend()) {
             // Extend, but only between two use cases. Remember we draw from the
             // extension port to the base port.
-            connection = getUseCases().buildExtend(toElement, fromElement);
+            connection = modelImpl.getUseCasesFactory().buildExtend(toElement, fromElement);
         } else if (elementType == metaTypes.getInclude()) {
-            connection = getUseCases().buildInclude(fromElement, toElement);
+            connection = modelImpl.getUseCasesFactory().buildInclude(fromElement, toElement);
         } else if (elementType == metaTypes.getTransition()) {
             connection =
-                getStateMachines().buildTransition(fromElement, toElement);
+                modelImpl.getStateMachinesFactory().buildTransition(fromElement, toElement);
         }
 
         if (connection == null) {
-            throw new IllegalModelElementConnectionException("Cannot make a "
-                    + elementType.getClass().getName() + " between a "
-                    + fromElement.getClass().getName() + " and a "
-                    + toElement.getClass().getName());
+            throw exception;
         }
 
         return connection;
@@ -227,84 +224,84 @@
 
     public Object buildNode(Object elementType) {
         if (elementType == metaTypes.getActor()) {
-            return getUseCases().createActor();
+            return modelImpl.getUseCasesFactory().createActor();
         } else if (elementType == metaTypes.getUseCase()) {
-            return getUseCases().createUseCase();
+            return modelImpl.getUseCasesFactory().createUseCase();
         } else if (elementType == metaTypes.getUMLClass()) {
-            return getCore().buildClass();
+            return modelImpl.getCoreFactory().buildClass();
         } else if (elementType == metaTypes.getInterface()) {
-            return getCore().buildInterface();
+            return modelImpl.getCoreFactory().buildInterface();
         } else if (elementType == metaTypes.getDataType()) {
-            return getCore().createDataType();
+            return modelImpl.getCoreFactory().createDataType();
         } else if (elementType == metaTypes.getPackage()) {
-            return getModelManagement().createPackage();
+            return modelImpl.getModelManagementFactory().createPackage();
         } else if (elementType == metaTypes.getModel()) {
-            return getModelManagement().createModel();
+            return modelImpl.getModelManagementFactory().createModel();
         } else if (elementType == metaTypes.getInstance()) {
             throw new IllegalArgumentException(
                     "Attempt to instantiate abstract type");
         } else if (elementType == metaTypes.getSubsystem()) {
-            return getModelManagement().createSubsystem();
+            return modelImpl.getModelManagementFactory().createSubsystem();
         } else if (elementType == metaTypes.getCallState()) {
-            return getActivityGraphs().createCallState();
+            return modelImpl.getActivityGraphsFactory().createCallState();
         } else if (elementType == metaTypes.getSimpleState()) {
-            return getStateMachines().createSimpleState();
+            return modelImpl.getStateMachinesFactory().createSimpleState();
         } else if (elementType == metaTypes.getFinalState()) {
-            return getStateMachines().createFinalState();
+            return modelImpl.getStateMachinesFactory().createFinalState();
         } else if (elementType == metaTypes.getPseudostate()) {
-            return getStateMachines().createPseudostate();
+            return modelImpl.getStateMachinesFactory().createPseudostate();
         } else if (elementType == metaTypes.getObjectFlowState()) {
-            return getActivityGraphs().createObjectFlowState();
+            return modelImpl.getActivityGraphsFactory().createObjectFlowState();
         } else if (elementType == metaTypes.getActionState()) {
-            return getActivityGraphs().createActionState();
+            return modelImpl.getActivityGraphsFactory().createActionState();
         } else if (elementType == metaTypes.getSubactivityState()) {
-            return getActivityGraphs().createSubactivityState();
+            return modelImpl.getActivityGraphsFactory().createSubactivityState();
         } else if (elementType == metaTypes.getPartition()) {
-            return getActivityGraphs().createPartition();
+            return modelImpl.getActivityGraphsFactory().createPartition();
         } else if (elementType == metaTypes.getStubState()) {
-            return getStateMachines().createStubState();
+            return modelImpl.getStateMachinesFactory().createStubState();
         } else if (elementType == metaTypes.getSubmachineState()) {
-            return getStateMachines().createSubmachineState();
+            return modelImpl.getStateMachinesFactory().createSubmachineState();
         } else if (elementType == metaTypes.getCompositeState()) {
-            return getStateMachines().createCompositeState();
+            return modelImpl.getStateMachinesFactory().createCompositeState();
         } else if (elementType == metaTypes.getSynchState()) {
-            return getStateMachines().createSynchState();
+            return modelImpl.getStateMachinesFactory().createSynchState();
         } else if (elementType == metaTypes.getState()) {
             throw new IllegalArgumentException(
                     "Attempt to instantiate abstract type");
         } else if (elementType == modelImpl.getMetaTypes().getSimpleState()) {
-            return getStateMachines().createSimpleState();
+            return modelImpl.getStateMachinesFactory().createSimpleState();
         } else if (elementType == metaTypes.getClassifierRole()) {
-            return getCollaborations().createClassifierRole();
+            return modelImpl.getCollaborationsFactory().createClassifierRole();
         } else if (elementType == metaTypes.getComponent()) {
-            return getCore().createComponent();
+            return modelImpl.getCoreFactory().createComponent();
         } else if (elementType == metaTypes.getComponentInstance()) {
-            return getCommonBehavior().createComponentInstance();
+            return modelImpl.getCommonBehaviorFactory().createComponentInstance();
         } else if (elementType == metaTypes.getNode()) {
-            return getCore().createNode();
+            return modelImpl.getCoreFactory().createNode();
         } else if (elementType == metaTypes.getNodeInstance()) {
-            return getCommonBehavior().createNodeInstance();
+            return modelImpl.getCommonBehaviorFactory().createNodeInstance();
         } else if (elementType == metaTypes.getObject()) {
-            return getCommonBehavior().createObject();
+            return modelImpl.getCommonBehaviorFactory().createObject();
         } else if (elementType == metaTypes.getComment()) {
-            return getCore().createComment();
+            return modelImpl.getCoreFactory().createComment();
         } else if (elementType == metaTypes.getNamespace()) {
             throw new IllegalArgumentException(
                     "Attempt to instantiate abstract type");
         } else if (elementType == metaTypes.getOperation()) {
-            return getCore().createOperation();
+            return modelImpl.getCoreFactory().createOperation();
         } else if (elementType == metaTypes.getEnumeration()) {
-            return getCore().createEnumeration();
+            return modelImpl.getCoreFactory().createEnumeration();
         } else if (elementType == metaTypes.getStereotype()) {
-            return getExtensionMechanisms().createStereotype();
+            return modelImpl.getExtensionMechanismsFactory().createStereotype();
         } else if (elementType == metaTypes.getAttribute()) {
-            return getCore().createAttribute();
+            return modelImpl.getCoreFactory().createAttribute();
         } else if (elementType == metaTypes.getSignal()) {
-            return getCommonBehavior().createSignal();
+            return modelImpl.getCommonBehaviorFactory().createSignal();
         } else if (elementType == metaTypes.getException()) {
-            return getCommonBehavior().createException();
+            return modelImpl.getCommonBehaviorFactory().createException();
         } else if (elementType == metaTypes.getTransition()) {
-            return getStateMachines().createTransition();
+            return modelImpl.getStateMachinesFactory().createTransition();
         }
             
         throw new IllegalArgumentException(
@@ -315,15 +312,18 @@
     public void delete(Object elem) {
         // TODO: We probably need a better way of doing this - tfm
         // Add an annotation saying that we've deleted the element
-        ((EModelElement) elem).getEAnnotations().add(removedAnnotation);
-        ((Element) elem).destroy();
+        if (!(elem instanceof EObject)) {
+            throw new IllegalArgumentException("elem must be instance of EObject"); //$NON-NLS-1$
+        }
+        EcoreUtil.delete((EObject) elem);
+//        ((EModelElement) elem).getEAnnotations().add(removedAnnotation);
+//        ((Element) elem).destroy();
     }
     
     public boolean isRemoved(Object o) {
-        // TODO: We  need a way to tell if #destroy() has
-        // been called
         if (o instanceof Element) {
-            return ((EModelElement) o).getEAnnotation(IS_REMOVED_NAME) != null;
+            return ((Element) o).eResource() != null;
+//            return ((EModelElement) o).getEAnnotation(IS_REMOVED_NAME) != null;
         }
         throw new IllegalArgumentException("Not an Element : " + o);
     }
@@ -338,7 +338,6 @@
         return isConnectionValid(connectionType, fromElement, toElement, true);
     }
 
-    // TODO: This is unchanged from UML 1.4 - needs review - tfm
     public boolean isConnectionValid(Object connectionType, Object fromElement,
             Object toElement, boolean checkWFR) {
         // Get the list of valid model item pairs for the given connection type
@@ -397,91 +396,6 @@
         return true;
     }
 
-
-
-    /**
-     * Returns the package factory for the UML package
-     * Foundation::ExtensionMechanisms.
-     *
-     * @return the ExtensionMechanisms factory instance.
-     */
-    private ExtensionMechanismsFactoryEUMLImpl getExtensionMechanisms() {
-        return (ExtensionMechanismsFactoryEUMLImpl) modelImpl.
-                getExtensionMechanismsFactory();
-    }
-
-    /**
-     * Returns the package factory for the UML package Foundation::Core.
-     *
-     * @return the Core factory instance.
-     */
-    private CoreFactoryEUMLImpl getCore() {
-        return (CoreFactoryEUMLImpl) modelImpl.getCoreFactory();
-    }
-
-    /**
-     * Returns the package factory for the UML package
-     * BehavioralElements::CommonBehavior.
-     *
-     * @return the CommonBehavior factory instance.
-     */
-    private CommonBehaviorFactoryEUMLImpl getCommonBehavior() {
-        return (CommonBehaviorFactoryEUMLImpl) modelImpl.
-                getCommonBehaviorFactory();
-    }
-
-    /**
-     * Returns the package factory for the UML package
-     * BehavioralElements::UseCases.
-     *
-     * @return the UseCases factory instance.
-     */
-    private UseCasesFactoryEUMLImpl getUseCases() {
-        return (UseCasesFactoryEUMLImpl) modelImpl.getUseCasesFactory();
-    }
-
-    /**
-     * Returns the package factory for the UML package
-     * BehavioralElements::StateMachines.
-     *
-     * @return the StateMachines factory instance.
-     */
-    private StateMachinesFactoryEUMLImpl getStateMachines() {
-        return (StateMachinesFactoryEUMLImpl) modelImpl.getStateMachinesFactory();
-    }
-
-    /**
-     * Returns the package factory for the UML package
-     * BehavioralElements::Collaborations.
-     *
-     * @return the Collaborations factory instance.
-     */
-    private CollaborationsFactoryEUMLImpl getCollaborations() {
-        return (CollaborationsFactoryEUMLImpl) modelImpl.
-                getCollaborationsFactory();
-    }
-
-    /**
-     * Returns the package factory for the UML package
-     * BehavioralElements::ActivityGraphs.
-     *
-     * @return the ActivityGraphs factory instance.
-     */
-    private ActivityGraphsFactoryEUMLlImpl getActivityGraphs() {
-        return (ActivityGraphsFactoryEUMLlImpl) modelImpl.
-                getActivityGraphsFactory();
-    }
-
-    /**
-     * Returns the package factory for the UML package ModelManagement.
-     *
-     * @return the ModelManagement factory instance.
-     */
-    private ModelManagementFactoryEUMLImpl getModelManagement() {
-        return (ModelManagementFactoryEUMLImpl) modelImpl.
-                getModelManagementFactory();
-    }
-
     private void buildValidConnectionMap() {
         // A list of valid connections between elements, the
         // connection type first and then the elements to be connected
@@ -510,7 +424,8 @@
                 validItems.add(modeElementPair);
                 // If the array hasn't been flagged to indicate otherwise
                 // swap elements the elemnts and add again.
-                if (VALID_CONNECTIONS[i].length < 4) {
+                if (VALID_CONNECTIONS[i].length < 4
+                        && VALID_CONNECTIONS[i][1] != VALID_CONNECTIONS[i][2]) {
                     Object[] reversedModeElementPair = new Class[2];
                     reversedModeElementPair[0] = VALID_CONNECTIONS[i][2];
                     reversedModeElementPair[1] = VALID_CONNECTIONS[i][1];
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.