Coverage Report - org.argouml.model.mdr.CoreFactoryMDRImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CoreFactoryMDRImpl
1%
15/851
0%
4/462
3.291
CoreFactoryMDRImpl$1
0%
0/13
0%
0/2
3.291
 
 1  
 /* $Id: CoreFactoryMDRImpl.java 18767 2010-09-18 23:19:19Z tfmorris $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009,2010 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    bobtarling
 11  
  *    Thomas Neustupny
 12  
  *    Tom Morris
 13  
  *****************************************************************************
 14  
  *
 15  
  * Some portions of this file was previously release using the BSD License:
 16  
  */
 17  
 
 18  
 // Copyright (c) 1996-2009 The Regents of the University of California. All
 19  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 20  
 // software and its documentation without fee, and without a written
 21  
 // agreement is hereby granted, provided that the above copyright notice
 22  
 // and this paragraph appear in all copies.  This software program and
 23  
 // documentation are copyrighted by The Regents of the University of
 24  
 // California. The software program and documentation are supplied "AS
 25  
 // IS", without any accompanying services from The Regents. The Regents
 26  
 // does not warrant that the operation of the program will be
 27  
 // uninterrupted or error-free. The end-user understands that the program
 28  
 // was developed for research purposes and is advised not to rely
 29  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 30  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 31  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 32  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 33  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 34  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 35  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 36  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 37  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 38  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 39  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 40  
 
 41  
 package org.argouml.model.mdr;
 42  
 
 43  
 import java.util.ArrayList;
 44  
 import java.util.Collection;
 45  
 import java.util.Iterator;
 46  
 import java.util.List;
 47  
 
 48  
 import javax.jmi.reflect.InvalidObjectException;
 49  
 import javax.jmi.reflect.RefObject;
 50  
 
 51  
 import org.apache.log4j.Logger;
 52  
 import org.argouml.model.CoreFactory;
 53  
 import org.argouml.model.Model;
 54  
 import org.argouml.model.ModelCommand;
 55  
 import org.argouml.model.ModelManagementHelper;
 56  
 import org.argouml.model.NotImplementedException;
 57  
 import org.omg.uml.behavioralelements.activitygraphs.ObjectFlowState;
 58  
 import org.omg.uml.behavioralelements.commonbehavior.Reception;
 59  
 import org.omg.uml.behavioralelements.commonbehavior.Signal;
 60  
 import org.omg.uml.behavioralelements.statemachines.Event;
 61  
 import org.omg.uml.foundation.core.Abstraction;
 62  
 import org.omg.uml.foundation.core.Artifact;
 63  
 import org.omg.uml.foundation.core.AssociationClass;
 64  
 import org.omg.uml.foundation.core.AssociationEnd;
 65  
 import org.omg.uml.foundation.core.Attribute;
 66  
 import org.omg.uml.foundation.core.BehavioralFeature;
 67  
 import org.omg.uml.foundation.core.Binding;
 68  
 import org.omg.uml.foundation.core.Classifier;
 69  
 import org.omg.uml.foundation.core.Comment;
 70  
 import org.omg.uml.foundation.core.Component;
 71  
 import org.omg.uml.foundation.core.Constraint;
 72  
 import org.omg.uml.foundation.core.CorePackage;
 73  
 import org.omg.uml.foundation.core.DataType;
 74  
 import org.omg.uml.foundation.core.Dependency;
 75  
 import org.omg.uml.foundation.core.Element;
 76  
 import org.omg.uml.foundation.core.ElementResidence;
 77  
 import org.omg.uml.foundation.core.Enumeration;
 78  
 import org.omg.uml.foundation.core.EnumerationLiteral;
 79  
 import org.omg.uml.foundation.core.Feature;
 80  
 import org.omg.uml.foundation.core.Flow;
 81  
 import org.omg.uml.foundation.core.GeneralizableElement;
 82  
 import org.omg.uml.foundation.core.Generalization;
 83  
 import org.omg.uml.foundation.core.Interface;
 84  
 import org.omg.uml.foundation.core.Method;
 85  
 import org.omg.uml.foundation.core.ModelElement;
 86  
 import org.omg.uml.foundation.core.Namespace;
 87  
 import org.omg.uml.foundation.core.Node;
 88  
 import org.omg.uml.foundation.core.Operation;
 89  
 import org.omg.uml.foundation.core.Parameter;
 90  
 import org.omg.uml.foundation.core.Permission;
 91  
 import org.omg.uml.foundation.core.PresentationElement;
 92  
 import org.omg.uml.foundation.core.Primitive;
 93  
 import org.omg.uml.foundation.core.ProgrammingLanguageDataType;
 94  
 import org.omg.uml.foundation.core.Relationship;
 95  
 import org.omg.uml.foundation.core.Stereotype;
 96  
 import org.omg.uml.foundation.core.StructuralFeature;
 97  
 import org.omg.uml.foundation.core.TemplateArgument;
 98  
 import org.omg.uml.foundation.core.TemplateParameter;
 99  
 import org.omg.uml.foundation.core.UmlAssociation;
 100  
 import org.omg.uml.foundation.core.UmlClass;
 101  
 import org.omg.uml.foundation.core.Usage;
 102  
 import org.omg.uml.foundation.datatypes.AggregationKind;
 103  
 import org.omg.uml.foundation.datatypes.AggregationKindEnum;
 104  
 import org.omg.uml.foundation.datatypes.BooleanExpression;
 105  
 import org.omg.uml.foundation.datatypes.CallConcurrencyKindEnum;
 106  
 import org.omg.uml.foundation.datatypes.ChangeableKind;
 107  
 import org.omg.uml.foundation.datatypes.ChangeableKindEnum;
 108  
 import org.omg.uml.foundation.datatypes.Expression;
 109  
 import org.omg.uml.foundation.datatypes.Multiplicity;
 110  
 import org.omg.uml.foundation.datatypes.MultiplicityRange;
 111  
 import org.omg.uml.foundation.datatypes.OrderingKind;
 112  
 import org.omg.uml.foundation.datatypes.OrderingKindEnum;
 113  
 import org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum;
 114  
 import org.omg.uml.foundation.datatypes.ProcedureExpression;
 115  
 import org.omg.uml.foundation.datatypes.ScopeKind;
 116  
 import org.omg.uml.foundation.datatypes.ScopeKindEnum;
 117  
 import org.omg.uml.foundation.datatypes.VisibilityKind;
 118  
 import org.omg.uml.foundation.datatypes.VisibilityKindEnum;
 119  
 import org.omg.uml.modelmanagement.UmlPackage;
 120  
 
 121  
 /**
 122  
  * Factory to create UML classes for the UML Foundation::Core package.
 123  
  * <p>
 124  
  * Feature, StructuralFeature, and PresentationElement do not have a create
 125  
  * method since they are called an "abstract metaclass" in the UML 
 126  
  * specifications.
 127  
  * <p>
 128  
  * @since ARGO0.19.5
 129  
  * @author Ludovic Ma&icirc;tre
 130  
  * @author Tom Morris
 131  
  * <p>
 132  
  * Derived from NSUML implementation by: 
 133  
  * @author Thierry Lach
 134  
  * @author Jaap Branderhorst
 135  
  */
 136  0
 class CoreFactoryMDRImpl extends AbstractUmlModelFactoryMDR implements
 137  
         CoreFactory {
 138  
 
 139  900
     private static final Logger LOG = Logger
 140  
             .getLogger(CoreFactoryMDRImpl.class);
 141  
     
 142  
     /**
 143  
      * The model implementation.
 144  
      */
 145  
     private MDRModelImplementation modelImpl;
 146  
 
 147  
     /**
 148  
      * Constructor.
 149  
      * 
 150  
      * @param implementation
 151  
      *            To get other helpers and factories.
 152  
      */
 153  900
     CoreFactoryMDRImpl(MDRModelImplementation implementation) {
 154  900
         modelImpl = implementation;
 155  900
     }
 156  
 
 157  
     private CorePackage getCorePackage() {
 158  0
         return modelImpl.getUmlPackage().getCore();
 159  
     }
 160  
     
 161  
     public Abstraction createAbstraction() {
 162  0
         Abstraction myAbstraction = getCorePackage().getAbstraction()
 163  
                 .createAbstraction();
 164  0
         super.initialize(myAbstraction);
 165  0
         return myAbstraction;
 166  
     }
 167  
 
 168  
 
 169  
     public Abstraction buildAbstraction(String name, Object supplier, 
 170  
             Object client) {
 171  0
         if (!(client instanceof Classifier)
 172  
                 || !(supplier instanceof Classifier)) {
 173  0
             throw new IllegalArgumentException(
 174  
                     "The supplier and client of an abstraction"
 175  
                             + "should be classifiers");
 176  
         }
 177  0
         if (client.equals(supplier)) {
 178  0
             throw new IllegalArgumentException("The supplier and the client "
 179  
                     + "must be different elements");
 180  
         }
 181  0
         Abstraction abstraction = createAbstraction();
 182  0
         abstraction.setName(name);
 183  0
         abstraction.getClient().add((Classifier) client);
 184  0
         abstraction.getSupplier().add((Classifier) supplier);
 185  0
         return abstraction;
 186  
     }
 187  
 
 188  
 
 189  
     public Artifact createArtifact() {
 190  0
         Artifact artifact = getCorePackage().getArtifact().createArtifact();
 191  0
         super.initialize(artifact);
 192  0
         return artifact;
 193  
     }
 194  
     
 195  
 
 196  
     @Deprecated
 197  
     public UmlAssociation createAssociation() {
 198  0
         return createAssociation(modelImpl.getUmlPackage());
 199  
     }
 200  
 
 201  
 
 202  
     public UmlAssociation createAssociation(Object extent) {
 203  0
         UmlAssociation assoc = ((org.omg.uml.UmlPackage) extent).getCore()
 204  
                 .getUmlAssociation().createUmlAssociation();
 205  0
         super.initialize(assoc);
 206  0
         return assoc;
 207  
     }
 208  
 
 209  
     public AssociationClass createAssociationClass() {
 210  0
         AssociationClass assoc = getCorePackage().getAssociationClass()
 211  
                 .createAssociationClass();
 212  0
         super.initialize(assoc);
 213  0
         return assoc;
 214  
     }
 215  
 
 216  
 
 217  
     public AssociationEnd createAssociationEnd() {
 218  0
         AssociationEnd assocEnd = getCorePackage().getAssociationEnd()
 219  
                 .createAssociationEnd();
 220  0
         super.initialize(assocEnd);
 221  0
         return assocEnd;
 222  
     }
 223  
 
 224  
 
 225  
     public Attribute createAttribute() {
 226  0
         Attribute myAttribute = getCorePackage().getAttribute().createAttribute();
 227  0
         super.initialize(myAttribute);
 228  0
         return myAttribute;
 229  
     }
 230  
 
 231  
 
 232  
     public Binding createBinding() {
 233  0
         Binding myBinding = getCorePackage().getBinding().createBinding();
 234  0
         super.initialize(myBinding);
 235  0
         return myBinding;
 236  
     }
 237  
 
 238  
 
 239  
     public UmlClass createClass() {
 240  0
         return createClass(modelImpl.getUmlPackage());
 241  
     }
 242  
 
 243  
     public UmlClass createClass(org.omg.uml.UmlPackage extent) {
 244  0
         UmlClass myClass = extent.getCore().getUmlClass().createUmlClass();
 245  0
         super.initialize(myClass);
 246  0
         return myClass;
 247  
     }
 248  
 
 249  
     public Comment createComment() {
 250  0
         Comment myComment = getCorePackage().getComment().createComment();
 251  0
         super.initialize(myComment);
 252  0
         return myComment;
 253  
     }
 254  
 
 255  
 
 256  
     public Component createComponent() {
 257  0
         Component myComponent = getCorePackage().getComponent().createComponent();
 258  0
         super.initialize(myComponent);
 259  0
         return myComponent;
 260  
     }
 261  
 
 262  
 
 263  
     public Constraint createConstraint() {
 264  0
         Constraint myConstraint = getCorePackage().getConstraint()
 265  
                 .createConstraint();
 266  0
         super.initialize(myConstraint);
 267  0
         return myConstraint;
 268  
     }
 269  
 
 270  
 
 271  
     public DataType createDataType() {
 272  0
         DataType dataType = getCorePackage().getDataType().createDataType();
 273  0
         super.initialize(dataType);
 274  0
         return dataType;
 275  
     }
 276  
 
 277  
 
 278  
     public Dependency createDependency() {
 279  0
         Dependency myDependency = getCorePackage().getDependency()
 280  
                 .createDependency();
 281  0
         super.initialize(myDependency);
 282  0
         return myDependency;
 283  
     }
 284  
 
 285  
 
 286  
     public ElementResidence createElementResidence() {
 287  0
         ElementResidence myElementResidence = getCorePackage().
 288  
                 getElementResidence().createElementResidence();
 289  0
         super.initialize(myElementResidence);
 290  0
         return myElementResidence;
 291  
     }
 292  
 
 293  
 
 294  
     public ElementResidence buildElementResidence(Object me, Object component) {
 295  0
         ElementResidence myElementResidence = 
 296  
             ((org.omg.uml.UmlPackage) ((ModelElement) me)
 297  
                 .refOutermostPackage()).getCore().getElementResidence()
 298  
                 .createElementResidence();
 299  0
         super.initialize(myElementResidence);
 300  0
         myElementResidence.setContainer((Component) component);
 301  0
         myElementResidence.setResident((ModelElement) me);
 302  0
         return myElementResidence;
 303  
     }
 304  
 
 305  
     
 306  
     public Enumeration createEnumeration() {
 307  0
         Enumeration myEnumeration = getCorePackage().getEnumeration()
 308  
                 .createEnumeration();
 309  0
         super.initialize(myEnumeration);
 310  0
         return myEnumeration;
 311  
     }
 312  
     
 313  
 
 314  
     public EnumerationLiteral createEnumerationLiteral() {
 315  0
         EnumerationLiteral myEnumerationLiteral = getCorePackage()
 316  
                 .getEnumerationLiteral().createEnumerationLiteral();
 317  0
         super.initialize(myEnumerationLiteral);
 318  0
         return myEnumerationLiteral;
 319  
     }
 320  
 
 321  
 
 322  
     public EnumerationLiteral buildEnumerationLiteral(String name,
 323  
             Object enumeration) {
 324  0
         EnumerationLiteral el = createEnumerationLiteral();
 325  0
         el.setName(name);
 326  0
         el.setEnumeration((Enumeration) enumeration);
 327  0
         return el;
 328  
     }
 329  
 
 330  
     
 331  
     public Flow createFlow() {
 332  0
         Flow myFlow = getCorePackage().getFlow().createFlow();
 333  0
         super.initialize(myFlow);
 334  0
         return myFlow;
 335  
     }
 336  
 
 337  
     @Deprecated
 338  
     public Generalization createGeneralization() {
 339  0
         return createGeneralization(modelImpl.getUmlPackage());
 340  
     }
 341  
 
 342  
     public Generalization createGeneralization(Object extent) {
 343  0
         Generalization myGeneralization = ((org.omg.uml.UmlPackage) extent)
 344  
                 .getCore().getGeneralization().createGeneralization();
 345  0
         super.initialize(myGeneralization);
 346  0
         return myGeneralization;
 347  
     }
 348  
 
 349  
     public Interface createInterface() {
 350  0
         Interface myInterface = getCorePackage()
 351  
                 .getInterface().createInterface();
 352  0
         super.initialize(myInterface);
 353  0
         return myInterface;
 354  
     }
 355  
 
 356  
 
 357  
     public Method createMethod() {
 358  0
         Method myMethod = getCorePackage().getMethod()
 359  
                 .createMethod();
 360  0
         super.initialize(myMethod);
 361  0
         return myMethod;
 362  
     }
 363  
 
 364  
 
 365  
     public Node createNode() {
 366  0
         Node myNode = getCorePackage().getNode().createNode();
 367  0
         super.initialize(myNode);
 368  0
         return myNode;
 369  
     }
 370  
 
 371  
 
 372  
     public Operation createOperation() {
 373  0
         Operation myOperation = getCorePackage()
 374  
                 .getOperation().createOperation();
 375  0
         super.initialize(myOperation);
 376  0
         return myOperation;
 377  
     }
 378  
 
 379  
 
 380  
     public Parameter createParameter() {
 381  0
         Parameter myParameter = getCorePackage()
 382  
                 .getParameter().createParameter();
 383  0
         super.initialize(myParameter);
 384  0
         return myParameter;
 385  
     }
 386  
 
 387  
 
 388  
     @Deprecated
 389  
     public Permission createPermission() {
 390  0
         return createPackageImport();
 391  
     }
 392  
 
 393  
     public Permission createPackageImport() {
 394  0
         Permission myPermission = getCorePackage()
 395  
                 .getPermission().createPermission();
 396  0
         super.initialize(myPermission);
 397  0
         return myPermission;
 398  
     }
 399  
 
 400  
     public Primitive createPrimitiveType() {
 401  0
         Primitive obj = getCorePackage().getPrimitive().createPrimitive();
 402  0
         super.initialize(obj);
 403  0
         return obj;
 404  
     }
 405  
     
 406  
 
 407  
     public TemplateArgument createTemplateArgument() {
 408  0
         return createTemplateArgument(modelImpl.getUmlPackage());
 409  
     }
 410  
     
 411  
       private  TemplateArgument createTemplateArgument(
 412  
               org.omg.uml.UmlPackage extent) {
 413  0
         TemplateArgument obj = extent.getCore().getTemplateArgument()
 414  
                 .createTemplateArgument();
 415  0
         super.initialize(obj);
 416  0
         return obj;
 417  
     }
 418  
         
 419  
 
 420  
     public TemplateParameter createTemplateParameter() {
 421  0
         return createTemplateParameter(modelImpl.getUmlPackage());
 422  
     }
 423  
 
 424  
     private TemplateParameter createTemplateParameter(
 425  
             org.omg.uml.UmlPackage extent) {
 426  0
         TemplateParameter myTemplateParameter = extent.getCore()
 427  
                 .getTemplateParameter().createTemplateParameter();
 428  0
         super.initialize(myTemplateParameter);
 429  0
         return myTemplateParameter;
 430  
     }
 431  
 
 432  
 
 433  
     public Usage createUsage() {
 434  0
         Usage myUsage = getCorePackage().getUsage().createUsage();
 435  0
         super.initialize(myUsage);
 436  0
         return myUsage;
 437  
     }
 438  
 
 439  
     /**
 440  
      * Builds a default binary association with two default association ends.
 441  
      * 
 442  
      * @param c1
 443  
      *            The first classifier to connect to
 444  
      * @param nav1
 445  
      *            The navigability of the Associaton end
 446  
      * @param agg1
 447  
      *            The aggregation type of the second Associaton end
 448  
      * @param c2
 449  
      *            The second classifier to connect to
 450  
      * @param nav2
 451  
      *            The navigability of the second Associaton end
 452  
      * @param agg2
 453  
      *            The aggregation type of the second Associaton end
 454  
      * @return a newly created Association
 455  
      * @throws IllegalArgumentException
 456  
      *             if either Classifier is null
 457  
      */
 458  
     private UmlAssociation buildAssociation(Classifier c1, boolean nav1,
 459  
             AggregationKind agg1, Classifier c2, boolean nav2,
 460  
             AggregationKind agg2) {
 461  0
         if (c1 == null || c2 == null) {
 462  0
             throw new IllegalArgumentException("one of "
 463  
                     + "the classifiers to be " + "connected is null");
 464  
         }
 465  0
         Namespace ns1 = c1.getNamespace();
 466  0
         Namespace ns2 = c2.getNamespace();
 467  0
         if (ns1 == null || ns2 == null) {
 468  0
             throw new IllegalArgumentException("one of "
 469  
                     + "the classifiers does not " + "belong to a namespace");
 470  
         }
 471  
         
 472  
         // We'll put the association in the namespace of whichever end
 473  
         // is not navigable and is writeable.  If they both are, we'll use the
 474  
         // namepace of c1.
 475  0
         Namespace ns = null;
 476  0
         if (nav2 && !modelImpl.getModelManagementHelper().isReadOnly(ns1)) {
 477  0
             ns = ns1;
 478  0
         } else if (nav1
 479  
                 && !modelImpl.getModelManagementHelper().isReadOnly(ns2)) {
 480  0
             ns = ns2;
 481  
         } else {
 482  0
             throw new IllegalArgumentException(
 483  
                     "At least one end must be navigable");
 484  
         }
 485  0
         UmlAssociation assoc = createAssociation(ns.refOutermostPackage());
 486  0
         assoc.setName("");
 487  0
         assoc.setNamespace(ns);
 488  0
         buildAssociationEnd(assoc, null, c1, null, null,
 489  
                 nav1, null, agg1, null, null, null);
 490  0
         buildAssociationEnd(assoc, null, c2, null, null, 
 491  
                 nav2, null, agg2, null, null, null);
 492  0
         return assoc;
 493  
     }
 494  
 
 495  
     @Deprecated
 496  
     public UmlAssociation buildAssociation(Object fromClassifier,
 497  
             Object aggregationKind1, Object toClassifier,
 498  
             Object aggregationKind2, Boolean unidirectional) {
 499  
         
 500  0
         if (unidirectional == null) {
 501  0
             return buildAssociation(fromClassifier, aggregationKind1,
 502  
                     toClassifier, aggregationKind2, false);
 503  
         } else {
 504  0
             return buildAssociation(fromClassifier, aggregationKind1,
 505  
                     toClassifier, aggregationKind2, unidirectional
 506  
                             .booleanValue());
 507  
         }
 508  
     }
 509  
 
 510  
     public UmlAssociation buildAssociation(Object fromClassifier,
 511  
             Object aggregationKind1, Object toClassifier,
 512  
             Object aggregationKind2, boolean unidirectional) {
 513  0
         if (fromClassifier == null || toClassifier == null) {
 514  0
             throw new IllegalArgumentException("one of "
 515  
                     + "the classifiers to be " + "connected is null");
 516  
         }
 517  0
         Classifier from = (Classifier) fromClassifier;
 518  0
         Classifier to = (Classifier) toClassifier;
 519  0
         AggregationKind agg1 = (AggregationKind) aggregationKind1;
 520  0
         AggregationKind agg2 = (AggregationKind) aggregationKind2;
 521  
 
 522  0
         Namespace ns = from.getNamespace();
 523  0
         if (ns == null || modelImpl.getModelManagementHelper().isReadOnly(ns)) {
 524  0
             ns = to.getNamespace();
 525  0
             if (ns == null
 526  
                     || modelImpl.getModelManagementHelper().isReadOnly(ns)) {
 527  0
                 throw new IllegalArgumentException(
 528  
                         "At least one namespace must be non-null and writeable");
 529  
             }
 530  
         }
 531  
 
 532  0
         UmlAssociation assoc = createAssociation(ns.refOutermostPackage());
 533  0
         assoc.setName("");
 534  0
         assoc.setNamespace(ns);
 535  
 
 536  0
         final boolean nav1 = !unidirectional;
 537  0
         final boolean nav2 = true;
 538  
 
 539  0
         buildAssociationEnd(assoc, null, from, null, null, nav1, null, agg1,
 540  
                 null, null, null);
 541  0
         buildAssociationEnd(assoc, null, to, null, null, nav2, null, agg2,
 542  
                 null, null, null);
 543  0
         return assoc;
 544  
     }
 545  
 
 546  
 
 547  
     public UmlAssociation buildAssociation(Object classifier1,
 548  
             Object classifier2) {
 549  0
         Classifier c1 = (Classifier) classifier1;
 550  0
         Classifier c2 = (Classifier) classifier2;
 551  0
         return buildAssociation(c1, true, AggregationKindEnum.AK_NONE, c2,
 552  
                 true, AggregationKindEnum.AK_NONE);
 553  
     }
 554  
 
 555  
 
 556  
     public UmlAssociation buildAssociation(Object c1, boolean nav1, Object c2,
 557  
             boolean nav2, String name) {
 558  0
         UmlAssociation assoc = buildAssociation((Classifier) c1, nav1,
 559  
                 AggregationKindEnum.AK_NONE, (Classifier) c2, nav2,
 560  
                 AggregationKindEnum.AK_NONE);
 561  0
         if (assoc != null) {
 562  0
             assoc.setName(name);
 563  
         }
 564  0
         return assoc;
 565  
     }
 566  
 
 567  
 
 568  
     public AssociationClass buildAssociationClass(Object end1, Object end2) {
 569  0
         if (end1 == null || end2 == null || !(end1 instanceof Classifier)
 570  
                 || !(end2 instanceof Classifier)) {
 571  0
             throw new IllegalArgumentException(
 572  
                     "either one of the arguments was null");
 573  
         }
 574  0
         final Classifier classifier1 = (Classifier) end1;
 575  0
         final Classifier classifier2 = (Classifier) end2;
 576  0
         AssociationClass assocClass = createAssociationClass();
 577  
         
 578  0
         assocClass.setNamespace(classifier1.getNamespace());
 579  0
         assocClass.setName("");
 580  0
         assocClass.setAbstract(false);
 581  0
         assocClass.setActive(false);
 582  0
         assocClass.setRoot(false);
 583  0
         assocClass.setLeaf(false);
 584  0
         assocClass.setSpecification(false);
 585  0
         assocClass.setVisibility(VisibilityKindEnum.VK_PUBLIC);
 586  
         
 587  0
         buildAssociationEnd(
 588  
                 assocClass, null, classifier1, null, null, true, null, null,
 589  
                 null, null, null);
 590  0
         buildAssociationEnd(
 591  
                 assocClass, null, classifier2, null, null, true, null, null,
 592  
                 null, null, null);
 593  0
         return assocClass;
 594  
     }
 595  
 
 596  
 
 597  
     public AssociationEnd buildAssociationEnd(Object assoc, String name,
 598  
             Object type, Integer[] multiplicity, Object stereo, boolean navigable,
 599  
             Object order, Object aggregation, Object scope, Object changeable,
 600  
             Object visibility) {
 601  0
         if (aggregation != null
 602  
                 && aggregation.equals(AggregationKindEnum.AK_COMPOSITE)
 603  
                 && multiplicity != null 
 604  
                 && (multiplicity[1] > 1 || multiplicity[1] == -1) ) {
 605  0
             throw new IllegalArgumentException("aggregation is composite "
 606  
                     + "and multiplicity > 1");
 607  
         }        
 608  0
         AssociationEnd ae = buildAssociationEndInternal(assoc, name, type,
 609  
                 stereo, navigable, order, aggregation, scope, changeable,
 610  
                 visibility);
 611  0
         if (multiplicity != null) {
 612  0
             Multiplicity m = modelImpl.getDataTypesFactoryInternal()
 613  
                     .createMultiplicityInternal(multiplicity[0],
 614  
                             multiplicity[1]);
 615  0
             ae.setMultiplicity(m);
 616  
         }
 617  0
         return ae;
 618  
     }
 619  
 
 620  
     @Deprecated
 621  
     public AssociationEnd buildAssociationEnd(Object assoc, String name,
 622  
             Object type, Object multi, Object stereo, boolean navigable,
 623  
             Object order, Object aggregation, Object scope, Object changeable,
 624  
             Object visibility) {
 625  0
         if (multi != null && !(multi instanceof Multiplicity)) {
 626  0
             throw new IllegalArgumentException("Multiplicity");
 627  
         }
 628  0
         if (aggregation != null
 629  
                 && aggregation.equals(AggregationKindEnum.AK_COMPOSITE)
 630  
                 && multi != null 
 631  
                 && compareMultiplicity(getMaxUpper((Multiplicity) multi), 1) 
 632  
                     > 0) {
 633  0
             throw new IllegalArgumentException("aggregation is composite "
 634  
                     + "and multiplicity > 1");
 635  
         }
 636  0
         AssociationEnd ae = buildAssociationEndInternal(assoc, name, type,
 637  
                 stereo, navigable, order, aggregation, scope, changeable,
 638  
                 visibility);
 639  0
         if (multi == null) {
 640  0
             ae.setMultiplicity(getMultiplicity11());
 641  0
         } else if (multi instanceof Multiplicity) {
 642  0
             ae.setMultiplicity((Multiplicity) multi);
 643  0
         } else if (multi instanceof String) {
 644  0
             Multiplicity m = modelImpl.getDataTypesFactoryInternal()
 645  
                     .createMultiplicityInternal((String) multi);
 646  0
             ae.setMultiplicity(m);
 647  
         }
 648  0
         return ae;
 649  
     }
 650  
 
 651  
     private AssociationEnd buildAssociationEndInternal (Object assoc, String name,
 652  
             Object type, Object stereo, boolean navigable,
 653  
             Object order, Object aggregation, Object scope, Object changeable,
 654  
             Object visibility) {
 655  
         // wellformednessrules and preconditions
 656  0
         if (assoc == null || !(assoc instanceof UmlAssociation) || type == null
 657  
                 || !(type instanceof Classifier)) {
 658  0
             throw new IllegalArgumentException("either type or association "
 659  
                     + "are null");
 660  
         }
 661  0
         if (stereo != null && !(stereo instanceof Stereotype)) {
 662  0
             throw new IllegalArgumentException("Stereotype");
 663  
         }
 664  0
         if (order != null && !(order instanceof OrderingKind)) {
 665  0
             throw new IllegalArgumentException("OrderingKind");
 666  
         }
 667  0
         if (aggregation != null && !(aggregation instanceof AggregationKind)) {
 668  0
             throw new IllegalArgumentException("AggregationKind");
 669  
         }
 670  0
         if (scope != null && !(scope instanceof ScopeKind)) {
 671  0
             throw new IllegalArgumentException("ScopeKind");
 672  
         }
 673  0
         if (changeable != null && !(changeable instanceof ChangeableKind)) {
 674  0
             throw new IllegalArgumentException("ChangeableKind");
 675  
         }
 676  0
         if (visibility != null && !(visibility instanceof VisibilityKind)) {
 677  0
             throw new IllegalArgumentException("VisibilityKind");
 678  
         }
 679  
 
 680  0
         AssociationEnd end = createAssociationEnd();
 681  0
         end.setAssociation((UmlAssociation) assoc);
 682  0
         end.setParticipant((Classifier) type);
 683  0
         end.setName(name);
 684  
         // UML 1.4 WFR 2.5.3.1 #3 - no aggregation for N-ary associations
 685  0
         List<AssociationEnd> ends = ((UmlAssociation) assoc).getConnection();
 686  0
         if (ends.size() >= 3) {
 687  0
             for (AssociationEnd e : ends) {
 688  0
                 e.setAggregation(AggregationKindEnum.AK_NONE);
 689  
             }
 690  
         }
 691  0
         if (stereo != null) {
 692  0
             end.getStereotype().clear();
 693  0
             end.getStereotype().add((Stereotype) stereo);
 694  
         }
 695  0
         end.setNavigable(navigable);
 696  0
         if (order != null) {
 697  0
             end.setOrdering((OrderingKind) order);
 698  
         } else {
 699  0
             end.setOrdering(OrderingKindEnum.OK_UNORDERED);
 700  
         }
 701  0
         if (aggregation != null) {
 702  0
             end.setAggregation((AggregationKind) aggregation);
 703  
         } else {
 704  0
             end.setAggregation(AggregationKindEnum.AK_NONE);
 705  
         }
 706  0
         if (scope != null) {
 707  0
             end.setTargetScope((ScopeKind) scope);
 708  
         } else {
 709  0
             end.setTargetScope(ScopeKindEnum.SK_INSTANCE);
 710  
         }
 711  0
         if (changeable != null) {
 712  0
             end.setChangeability((ChangeableKind) changeable);
 713  
         } else {
 714  0
             end.setChangeability(ChangeableKindEnum.CK_CHANGEABLE);
 715  
         }
 716  0
         if (visibility != null) {
 717  0
             end.setVisibility((VisibilityKind) visibility);
 718  
         } else {
 719  0
             end.setVisibility(VisibilityKindEnum.VK_PUBLIC);
 720  
         }
 721  0
         return end;
 722  
     }
 723  
 
 724  
     private static final int MULT_UNLIMITED = -1;
 725  
     
 726  
     /**
 727  
      * Get the maximum value of a multiplicity
 728  
      * 
 729  
      * @param m
 730  
      *            the Multiplicity
 731  
      * @return upper range
 732  
      */
 733  
     private int getMaxUpper(Multiplicity m) {
 734  0
         int max = 0;
 735  0
         for (MultiplicityRange mr : m.getRange()) {
 736  0
             int value = mr.getUpper();
 737  0
             if (value == MULT_UNLIMITED) {
 738  0
                 max = value;
 739  0
             } else if (max != MULT_UNLIMITED && value > max) {
 740  0
                 max = value;
 741  
             }
 742  0
         }
 743  0
         return max;
 744  
     }
 745  
     
 746  
     /**
 747  
      * Compare two multiplicities taking care of the value 'unlimited' (-1).
 748  
      * 
 749  
      * @param mult1 first multiplicity
 750  
      * @param mult2 second multiplicity
 751  
      * @return 0 if equal, a positive integer (not necessarily 1) if mult1 is
 752  
      *         greater than mult2 and a negative integer if mult2 is greater..
 753  
      */
 754  
     private static int compareMultiplicity(int mult1, int mult2) {
 755  0
         if (mult1 == MULT_UNLIMITED) {
 756  0
             if (mult2 == MULT_UNLIMITED) {
 757  0
                 return 0; // equal
 758  
             }
 759  0
             return 1; // greater
 760  0
         } else if (mult2 == MULT_UNLIMITED) {
 761  0
             return -1; // less than
 762  
         }
 763  0
         return mult1 - mult2;
 764  
     }
 765  
 
 766  
     /**
 767  
      * Get a 1..1 multiplicity
 768  
      */
 769  
     private Multiplicity getMultiplicity11() {
 770  0
         return modelImpl.getDataTypesFactoryInternal()
 771  
                 .createMultiplicityInternal(1, 1);
 772  
     }
 773  
 
 774  
 
 775  
     public AssociationEnd buildAssociationEnd(Object type, Object assoc) {
 776  0
         if (type == null || !(type instanceof Classifier) || assoc == null
 777  
                 || !(assoc instanceof UmlAssociation)) {
 778  0
             throw new IllegalArgumentException("one of the arguments is null");
 779  
         }
 780  0
         return buildAssociationEnd(assoc, "", type, null, null, true, null,
 781  
                 null, null, null, VisibilityKindEnum.VK_PUBLIC);
 782  
     }
 783  
 
 784  
     public Attribute buildAttribute(Object model, Object theType) {
 785  0
         return buildAttribute2(theType);
 786  
     }
 787  
 
 788  
     public Attribute buildAttribute2(Object theType) {
 789  0
         Attribute attr = buildAttribute();
 790  0
         attr.setType((Classifier) theType);
 791  0
         return attr;
 792  
     }
 793  
     
 794  
     /**
 795  
      * Build a new attribute with no type
 796  
      * @return the new attribute
 797  
      */
 798  
     Attribute buildAttribute() {
 799  0
         Attribute attr = createAttribute();
 800  0
         attr.setName("newAttr");
 801  0
         attr.setMultiplicity(getMultiplicity11());
 802  0
         attr.setVisibility(VisibilityKindEnum.VK_PUBLIC);
 803  0
         attr.setOwnerScope(ScopeKindEnum.SK_INSTANCE);
 804  0
         attr.setChangeability(ChangeableKindEnum.CK_CHANGEABLE);
 805  0
         attr.setTargetScope(ScopeKindEnum.SK_INSTANCE);
 806  0
         return attr;
 807  
     }
 808  
     
 809  
 
 810  
     public Attribute buildAttribute2(Object handle, Object type) {
 811  0
         Attribute attr = buildAttribute2(type);
 812  0
         if (handle instanceof Classifier) {
 813  0
             Classifier cls = (Classifier) handle;
 814  0
             cls.getFeature().add(attr);
 815  0
         } else if (handle instanceof AssociationEnd) {
 816  0
             AssociationEnd assend = (AssociationEnd) handle;
 817  0
             assend.getQualifier().add(attr);
 818  0
         } else {
 819  0
             throw new IllegalArgumentException();            
 820  
         }
 821  0
         return attr;
 822  
     }
 823  
     
 824  
 
 825  
     public UmlClass buildClass() {
 826  0
         return buildClass((Object) null);
 827  
     }
 828  
 
 829  
 
 830  
     private static void initClass(UmlClass cl) {
 831  0
         cl.setName("");
 832  0
         cl.setAbstract(false);
 833  0
         cl.setActive(false);
 834  0
         cl.setRoot(false);
 835  0
         cl.setLeaf(false);
 836  0
         cl.setSpecification(false);
 837  0
         cl.setVisibility(VisibilityKindEnum.VK_PUBLIC);
 838  0
     }
 839  
     
 840  
     public UmlClass buildClass(final Object owner) {
 841  0
         ModelCommand command = new ModelCommand() {
 842  
             private UmlClass cl;
 843  
             public UmlClass execute() {
 844  0
                 if (owner == null) {
 845  0
                     cl = createClass();
 846  
                 } else {
 847  0
                     cl = createClass(getExtent(owner));
 848  
                 }
 849  0
                 initClass(cl);
 850  0
                 return cl;
 851  
             }
 852  
             
 853  
             public void undo() {
 854  
                 try {
 855  0
                     cl.refDelete();
 856  0
                 } catch (InvalidObjectException e) {
 857  0
                     LOG.warn("Object already deleted " + cl);
 858  0
                 }
 859  0
             }
 860  
             
 861  
             public boolean isUndoable() {
 862  0
                 return true;
 863  
             }
 864  
             
 865  
             public boolean isRedoable() {
 866  0
                 return false;
 867  
             }
 868  
         };
 869  0
         UmlClass clazz = (UmlClass) org.argouml.model.Model.execute(command);
 870  0
         if (owner instanceof Namespace) {
 871  0
             modelImpl.getCoreHelper().setNamespace(clazz, owner);
 872  
         }
 873  0
         return clazz;
 874  
     }
 875  
 
 876  
 
 877  
     private org.omg.uml.UmlPackage getExtent(Object element) {
 878  0
         return (org.omg.uml.UmlPackage) ((RefObject) element)
 879  
                 .refOutermostPackage();
 880  
     }
 881  
     
 882  
     public UmlClass buildClass(String name) {
 883  0
         UmlClass clazz = buildClass();
 884  0
         clazz.setName(name);
 885  0
         return clazz;
 886  
     }
 887  
 
 888  
 
 889  
     public UmlClass buildClass(String name, Object owner) {
 890  0
         UmlClass clazz = buildClass();
 891  0
         clazz.setName(name);
 892  0
         if (owner instanceof Namespace) {
 893  0
             modelImpl.getCoreHelper().setNamespace(clazz, owner);
 894  
         }
 895  0
         return clazz;
 896  
     }
 897  
 
 898  
 
 899  
     public Interface buildInterface() {
 900  0
         Interface cl = createInterface();
 901  0
         cl.setName("");
 902  0
         cl.setAbstract(false);
 903  0
         cl.setRoot(false);
 904  0
         cl.setLeaf(false);
 905  0
         cl.setSpecification(false);
 906  0
         cl.setVisibility(VisibilityKindEnum.VK_PUBLIC);
 907  0
         return cl;
 908  
     }
 909  
 
 910  
 
 911  
     public Interface buildInterface(Object owner) {
 912  0
         Interface cl = buildInterface();
 913  0
         if (owner instanceof Namespace) {
 914  0
             cl.setNamespace((Namespace) owner);
 915  
         }
 916  0
         return cl;
 917  
     }
 918  
 
 919  
 
 920  
     public Interface buildInterface(String name) {
 921  0
         Interface cl = buildInterface();
 922  0
         cl.setName(name);
 923  0
         return cl;
 924  
     }
 925  
 
 926  
 
 927  
     public Interface buildInterface(String name, Object owner) {
 928  0
         Interface cl = buildInterface();
 929  0
         cl.setName(name);
 930  0
         if (owner instanceof Namespace) {
 931  0
             cl.setNamespace((Namespace) owner);
 932  
         }
 933  0
         return cl;
 934  
     }
 935  
 
 936  
 
 937  
     public DataType buildDataType(String name, Object owner) {
 938  0
         DataType dt = createDataType();
 939  0
         dt.setName(name);
 940  0
         if (owner instanceof Namespace) {
 941  0
             dt.setNamespace((Namespace) owner);
 942  
         }
 943  0
         return dt;
 944  
     }
 945  
 
 946  
 
 947  
     public Enumeration buildEnumeration(String name, Object owner) {
 948  0
         Enumeration e = createEnumeration();
 949  0
         e.setName(name);
 950  0
         if (owner instanceof Namespace) {
 951  0
             e.setNamespace((Namespace) owner);
 952  
         }
 953  0
         return e;
 954  
     }
 955  
 
 956  
 
 957  
     public Dependency buildDependency(Object clientObj, Object supplierObj) {
 958  
 
 959  0
         ModelElement client = (ModelElement) clientObj;
 960  0
         ModelElement supplier = (ModelElement) supplierObj;
 961  0
         if (client == null || supplier == null) {
 962  0
             throw new IllegalArgumentException("client or supplier is null "
 963  
                     + "client = " + client + " supplier = " + supplier);
 964  
         }
 965  0
         Dependency dep = createDependency();
 966  0
         dep.getSupplier().add(supplier);
 967  0
         dep.getClient().add(client);
 968  0
         if (client instanceof Namespace) {
 969  0
             dep.setNamespace((Namespace) client);
 970  0
         } else if (client.getNamespace() != null) {
 971  0
             dep.setNamespace(client.getNamespace());
 972  
         }
 973  0
         return dep;
 974  
     }
 975  
 
 976  
 
 977  
     public Permission buildPackageImport(Object client, Object supplier) {
 978  0
         if (!(client instanceof Namespace) 
 979  
                 || !(supplier instanceof UmlPackage)) {
 980  0
             throw new IllegalArgumentException("client is not a Namespace"
 981  
                     + " or supplier is not a Package");
 982  
         }
 983  0
         Permission per = buildPermissionInternal((ModelElement) client, 
 984  
                 (UmlPackage) supplier);
 985  
 
 986  
         // TODO: This should fetch the stereotype from our profile
 987  0
         modelImpl.getExtensionMechanismsFactory().buildStereotype(per, 
 988  
                 ModelManagementHelper.IMPORT_STEREOTYPE,
 989  
                 per.getNamespace());
 990  0
         return per;
 991  
     }
 992  
 
 993  
     
 994  
     private Permission buildPermissionInternal(ModelElement client, 
 995  
             ModelElement supplier) {
 996  0
         Permission permission = createPackageImport();
 997  0
         permission.getSupplier().add(supplier);
 998  0
         permission.getClient().add(client);
 999  0
         if (client instanceof Namespace) {
 1000  0
             permission.setNamespace((Namespace) client);
 1001  0
         } else if (client.getNamespace() != null) {
 1002  0
             permission.setNamespace(client.getNamespace());
 1003  
         }
 1004  0
         return permission;
 1005  
     }
 1006  
     
 1007  
     
 1008  
     public Permission buildPackageAccess(Object client, Object supplier) {
 1009  0
         if (!(client instanceof Namespace) 
 1010  
                 || !(supplier instanceof UmlPackage)) {
 1011  0
             throw new IllegalArgumentException("client or "
 1012  
                     + "supplier is not a Namespace");
 1013  
         }
 1014  0
         Permission per = buildPermissionInternal((ModelElement) client, 
 1015  
                 (UmlPackage) supplier);
 1016  
 
 1017  
         // TODO: This should fetch the stereotype from our profile
 1018  0
         modelImpl.getExtensionMechanismsFactory().buildStereotype(per, 
 1019  
                 ModelManagementHelper.ACCESS_STEREOTYPE,
 1020  
                 per.getNamespace());
 1021  0
         return per;
 1022  
     }
 1023  
 
 1024  
 
 1025  
     public Generalization buildGeneralization(Object child1, Object parent1) {
 1026  
         // TODO: This is a part implementation of well-formedness rule
 1027  
         // UML1.4.2 - 4.5.3.20 [3] Circular inheritance is not allowed.
 1028  
         // not self.allParents->includes(self)
 1029  0
         if (!(child1 instanceof GeneralizableElement
 1030  
                 && parent1 instanceof GeneralizableElement
 1031  
                 && child1 != parent1)) {
 1032  0
             throw new IllegalArgumentException(
 1033  
                     "Both items must be different generalizable elements");
 1034  
         }
 1035  
 
 1036  0
         GeneralizableElement child = (GeneralizableElement) child1;
 1037  0
         GeneralizableElement parent = (GeneralizableElement) parent1;
 1038  
 
 1039  
         // Check that the two elements aren't already linked the opposite way
 1040  
         // TODO: This is a part implementation of well-formedness rule
 1041  
         // UML1.4.2 - 4.5.3.20 [3] Circular inheritance is not allowed.
 1042  
         // not self.allParents->includes(self)
 1043  0
         for (Generalization gen : parent.getGeneralization()) {
 1044  0
             if (gen.getParent().equals(child)) {
 1045  0
                 throw new IllegalArgumentException("Generalization exists" 
 1046  
                         + " in opposite direction");
 1047  
             }
 1048  
         }
 1049  
 
 1050  
         // TODO: This is well-formedness rule from UML1.4.2
 1051  
         // 4.5.3.20 [2] No GeneralizableElement can have a parent
 1052  
         // Generalization to an element that is a leaf.
 1053  
         // self.parent->forAll(s | not s.isLeaf)
 1054  0
         if (parent.isLeaf()) {
 1055  0
             throw new IllegalArgumentException("parent is leaf");
 1056  
         }
 1057  
         
 1058  
         // TODO: This is well-formedness rule from UML1.4.2
 1059  
         // 4.5.3.20 [1] A root cannot have any Generalizations.
 1060  
         // self.isRoot implies self.generalization->isEmpty        
 1061  0
         if (child.isRoot()) {
 1062  0
             throw new IllegalArgumentException("child is root");
 1063  
         }
 1064  
 
 1065  0
         Namespace ns = child.getNamespace();
 1066  0
         if ((ns == null || modelImpl.getModelManagementHelper().isReadOnly(ns))
 1067  
                 && child instanceof Namespace) {
 1068  0
             ns = (Namespace) child;
 1069  
         }
 1070  0
         if (ns == null || modelImpl.getModelManagementHelper().isReadOnly(ns)) {
 1071  0
             throw new IllegalArgumentException("No valid writeable namespace");
 1072  
         }
 1073  0
         Generalization gen = createGeneralization(ns.refOutermostPackage());
 1074  0
         gen.setParent(parent);
 1075  0
         gen.setChild(child);
 1076  0
         gen.setNamespace(ns);
 1077  0
         return gen;
 1078  
     }
 1079  
 
 1080  
     public Object buildManifestation(Object utilizedElement) {
 1081  0
         throw new NotImplementedException( "UML 1.4 has no manifestations");
 1082  
     }
 1083  
 
 1084  
     public Method buildMethod(String name) {
 1085  0
         Method method = createMethod();
 1086  0
         if (method != null) {
 1087  0
             method.setName(name);
 1088  
         }
 1089  0
         return method;
 1090  
     }
 1091  
 
 1092  
 
 1093  
     public Operation buildOperation(Object classifier, Object returnType) {
 1094  0
         if (!(classifier instanceof Classifier)) {
 1095  0
             throw new IllegalArgumentException("Handle is not a classifier");
 1096  
         }
 1097  0
         Classifier cls = (Classifier) classifier;
 1098  0
         Operation oper = createOperation();
 1099  0
         oper.setName("newOperation");
 1100  0
         oper.setOwner(cls);
 1101  0
         oper.setVisibility(VisibilityKindEnum.VK_PUBLIC);
 1102  0
         oper.setAbstract(false);
 1103  0
         oper.setLeaf(false);
 1104  0
         oper.setRoot(false);
 1105  0
         oper.setQuery(false);
 1106  0
         oper.setOwnerScope(ScopeKindEnum.SK_INSTANCE);
 1107  0
         oper.setConcurrency(CallConcurrencyKindEnum.CCK_SEQUENTIAL);
 1108  
 
 1109  0
         Parameter returnParameter = buildParameter(oper, returnType);
 1110  0
         returnParameter.setKind(ParameterDirectionKindEnum.PDK_RETURN);
 1111  0
         returnParameter.setName("return");
 1112  0
         return oper;
 1113  
     }
 1114  
 
 1115  
 
 1116  
     public Operation buildOperation2(Object cls, Object returnType, 
 1117  
             String name) {
 1118  0
         Operation oper = buildOperation(cls, returnType);
 1119  0
         if (oper != null) {
 1120  0
             oper.setName(name);
 1121  
         }
 1122  0
         return oper;
 1123  
     }
 1124  
 
 1125  
     /**
 1126  
      * Constructs a default parameter.
 1127  
      * 
 1128  
      * @return The newly created parameter.
 1129  
      */
 1130  
     private Parameter buildParameter(Classifier type,
 1131  
             javax.jmi.reflect.RefObject ref) {
 1132  0
         Parameter param = ((org.omg.uml.UmlPackage) ref.refOutermostPackage())
 1133  
                 .getCore().getParameter().createParameter();
 1134  0
         param.setType(type);
 1135  0
         return param;
 1136  
     }
 1137  
 
 1138  
 
 1139  
     public Parameter buildParameter(Object o, Object type) {
 1140  0
         if (o instanceof Event) {
 1141  0
             Event event = (Event) o;
 1142  0
             Parameter res = buildParameter((Classifier) type, event);
 1143  0
             res.setKind(ParameterDirectionKindEnum.PDK_IN);
 1144  0
             event.getParameter().add(res);
 1145  0
             res.setName("arg" + event.getParameter().size());
 1146  0
             return res;
 1147  0
         } else if (o instanceof ObjectFlowState) {
 1148  0
             ObjectFlowState ofs = (ObjectFlowState) o;
 1149  0
             Parameter res = buildParameter((Classifier) type, ofs);
 1150  0
             res.setKind(ParameterDirectionKindEnum.PDK_IN);
 1151  0
             ofs.getParameter().add(res);
 1152  0
             res.setName("arg" + ofs.getParameter().size());
 1153  0
             return res;
 1154  0
         } else if (o instanceof BehavioralFeature) {
 1155  0
             BehavioralFeature oper = (BehavioralFeature) o;
 1156  0
             Parameter res = buildParameter((Classifier) type, oper);
 1157  0
             res.setKind(ParameterDirectionKindEnum.PDK_IN);
 1158  0
             oper.getParameter().add(res);
 1159  0
             res.setName("arg" + oper.getParameter().size());
 1160  0
             return res;
 1161  0
         } else if (o == null) {
 1162  0
             throw new IllegalArgumentException(
 1163  
                     "A containing element must be supplied for the parameter");
 1164  
         } else {
 1165  0
             throw new IllegalArgumentException(
 1166  
                     "Unsupported contining element for parameter "
 1167  
                     + o.getClass().getName());
 1168  
         }
 1169  
     }
 1170  
 
 1171  
 
 1172  
     public Abstraction buildRealization(Object clnt, Object spplr, 
 1173  
             Object model) {
 1174  0
         ModelElement client = (ModelElement) clnt;
 1175  0
         ModelElement supplier = (ModelElement) spplr;
 1176  0
         if (client == null || supplier == null || client.getNamespace() == null
 1177  
                 || supplier.getNamespace() == null || client.equals(supplier)) {
 1178  0
             throw new IllegalArgumentException("faulty arguments.");
 1179  
         }
 1180  0
         Abstraction realization = createAbstraction();
 1181  0
         Namespace nsc = client.getNamespace();
 1182  0
         Namespace nss = supplier.getNamespace();
 1183  0
         Namespace ns = null;
 1184  0
         if (nsc.equals(nss)) {
 1185  0
             ns = nsc;
 1186  
         } else {
 1187  0
             ns = (Namespace) model;
 1188  
         }
 1189  0
         realization.setNamespace(nsc);
 1190  0
         modelImpl.getExtensionMechanismsFactory().buildStereotype(realization,
 1191  
                 CoreFactory.REALIZE_STEREOTYPE, ns);
 1192  0
         realization.getClient().add(client);
 1193  0
         realization.getSupplier().add(supplier);
 1194  0
         return realization;
 1195  
     }
 1196  
 
 1197  
 
 1198  
     public TemplateArgument buildTemplateArgument(Object element) {
 1199  0
         TemplateArgument ta = createTemplateArgument();
 1200  0
         ta.setModelElement((ModelElement) element);
 1201  0
         return ta;
 1202  
     }
 1203  
 
 1204  
     public TemplateArgument buildTemplateArgument(Object binding, 
 1205  
             Object element) {
 1206  0
         if (!(binding instanceof Binding && element instanceof ModelElement)) {
 1207  0
             throw new IllegalArgumentException();
 1208  
         }
 1209  0
         TemplateArgument ta = createTemplateArgument(getExtent(binding));
 1210  0
         ta.setModelElement((ModelElement) element);
 1211  0
         ta.setBinding((Binding) binding);
 1212  0
         return ta;
 1213  
     }
 1214  
     
 1215  
     public Object buildTemplateParameter(Object template, Object parameter,
 1216  
             Object defaultElement) {
 1217  0
         if (!(template instanceof ModelElement)) {
 1218  0
             throw new IllegalArgumentException(
 1219  
                     "Template must be a model element");
 1220  
         }
 1221  0
         if (!(parameter instanceof ModelElement)) {
 1222  0
             if (parameter == null) {
 1223  0
                 parameter = createClass(getExtent(template));
 1224  
             } else {
 1225  0
             throw new IllegalArgumentException(
 1226  
                     "Parameter must be a model element");
 1227  
             }
 1228  
         }
 1229  0
         if (defaultElement != null 
 1230  
                 && !(defaultElement instanceof ModelElement)) {
 1231  0
             throw new IllegalArgumentException(
 1232  
                     "Default element must be a model element");
 1233  
         }
 1234  
 
 1235  0
         TemplateParameter templateParam = 
 1236  
             createTemplateParameter(getExtent(template));
 1237  0
         templateParam.setParameter((ModelElement) parameter);
 1238  0
         if (defaultElement != null) {
 1239  0
             templateParam.setDefaultElement((ModelElement) defaultElement);
 1240  
         }
 1241  0
         templateParam.setTemplate((ModelElement) template);
 1242  0
         return templateParam;
 1243  
     }
 1244  
     
 1245  
 
 1246  
     public Usage buildUsage(Object client, Object supplier) {
 1247  0
         if (client == null || supplier == null) {
 1248  0
             throw new IllegalArgumentException("In buildUsage null arguments.");
 1249  
         }
 1250  0
         if (!(client instanceof ModelElement)) {
 1251  0
             throw new IllegalArgumentException("client ModelElement");
 1252  
         }
 1253  0
         if (!(supplier instanceof ModelElement)) {
 1254  0
             throw new IllegalArgumentException("supplier ModelElement");
 1255  
         }
 1256  
         // TODO: UML 1.4 spec requires both client and supplier to be
 1257  
         // in the same model - tfm
 1258  0
         Usage usage = createUsage();
 1259  0
         usage.getSupplier().add((ModelElement) supplier);
 1260  0
         usage.getClient().add((ModelElement) client);
 1261  0
         if (((ModelElement) supplier).getNamespace() != null) {
 1262  0
             usage.setNamespace(((ModelElement) supplier).getNamespace());
 1263  0
         } else if (((ModelElement) client).getNamespace() != null) {
 1264  0
             usage.setNamespace(((ModelElement) client).getNamespace());
 1265  
         }
 1266  
         // TODO: Add standard stereotype?  Set is open ended, but 
 1267  
         // predefined names include: call, create, instantiate, send
 1268  0
         return usage;
 1269  
     }
 1270  
 
 1271  
 
 1272  
     public Comment buildComment(Object element, Object model) {
 1273  0
         if (model == null) {
 1274  0
             throw new IllegalArgumentException("A namespace must be supplied.");
 1275  
         }
 1276  0
         ModelElement elementToAnnotate = (ModelElement) element;
 1277  0
         Comment comment = createComment();
 1278  
 
 1279  0
         Namespace commentsModel = null;
 1280  0
         if (elementToAnnotate != null) {
 1281  0
             comment.getAnnotatedElement().add(elementToAnnotate);
 1282  0
             commentsModel = elementToAnnotate.getNamespace();
 1283  
         } else {
 1284  0
             commentsModel = (Namespace) model;
 1285  
         }
 1286  
 
 1287  0
         comment.setNamespace(commentsModel);
 1288  0
         return comment;
 1289  
     }
 1290  
 
 1291  
 
 1292  
     public Constraint buildConstraint(Object constrElement) {
 1293  0
         ModelElement constrainedElement = (ModelElement) constrElement;
 1294  0
         if (constrainedElement == null) {
 1295  0
             throw new IllegalArgumentException("the constrained element is "
 1296  
                     + "mandatory and may not be " + "null.");
 1297  
         }
 1298  0
         Constraint con = createConstraint();
 1299  0
         con.getConstrainedElement().add(constrainedElement);
 1300  0
         con.setNamespace(constrainedElement.getNamespace());
 1301  0
         return con;
 1302  
     }
 1303  
 
 1304  
 
 1305  
     public Constraint buildConstraint(String name, Object bexpr) {
 1306  0
         if (bexpr == null || !(bexpr instanceof BooleanExpression)) {
 1307  0
             throw new IllegalArgumentException("invalid boolean expression.");
 1308  
         }
 1309  0
         Constraint con = createConstraint();
 1310  0
         if (name != null) {
 1311  0
             con.setName(name);
 1312  
         }
 1313  0
         con.setBody((BooleanExpression) bexpr);
 1314  0
         return con;
 1315  
     }
 1316  
     
 1317  
 
 1318  
     public Binding buildBinding(Object client, Object supplier, 
 1319  
             List arguments) {
 1320  0
         Collection<Dependency> clientDeps = ((ModelElement) client)
 1321  
                 .getClientDependency();
 1322  0
         for (Dependency dep : clientDeps) {
 1323  0
             if (dep instanceof Binding) {
 1324  0
                 throw new IllegalArgumentException(
 1325  
                         "client is already client of another Binding");
 1326  
             }
 1327  
         }
 1328  
         
 1329  
         // Check arguments against parameters for type and number
 1330  
         // TODO: Perhaps move this to a critic instead? - tfm - 20070326
 1331  0
         if (arguments != null) {
 1332  0
             List<TemplateParameter> params = 
 1333  
                 ((ModelElement) supplier).getTemplateParameter();
 1334  0
             if (params.size() != arguments.size()) {
 1335  0
                 throw new IllegalArgumentException(
 1336  
                         "number of arguments doesn't match number of params");
 1337  
             }
 1338  0
             Iterator<TemplateArgument> ita = arguments.iterator();
 1339  0
             for (TemplateParameter param : params) {
 1340  0
                 TemplateArgument ta = ita.next();
 1341  
                 // TODO: Before allowing this, we should really check that 
 1342  
                 // TemplateParameter.defaultElement is defined
 1343  0
                 if (ta == null || ta.getModelElement() == null) {
 1344  0
                     continue;
 1345  
                 }
 1346  0
                 if (!(param.getParameter().getClass().equals(
 1347  
                         ta.getModelElement().getClass()))) {
 1348  0
                     throw new IllegalArgumentException(
 1349  
                             "type of argument doesn't match type of parameter");
 1350  
                 }
 1351  0
             }
 1352  
         }
 1353  
         
 1354  0
         Binding binding = createBinding();
 1355  0
         binding.getClient().add((ModelElement) client);
 1356  0
         binding.getSupplier().add((ModelElement) supplier);
 1357  0
         if (arguments != null) {
 1358  0
             binding.getArgument().addAll(arguments);
 1359  
         }
 1360  
 
 1361  0
         return binding;
 1362  
     }
 1363  
 
 1364  
 
 1365  
     /**
 1366  
      * @param elem
 1367  
      *            the abstraction to be deleted
 1368  
      */
 1369  
     void deleteAbstraction(Object elem) {
 1370  0
         if (!(elem instanceof Abstraction)) {
 1371  0
             throw new IllegalArgumentException("elem: " + elem);
 1372  
         }
 1373  0
     }
 1374  
 
 1375  
     /**
 1376  
      * @param elem
 1377  
      *            the artifact to be deleted
 1378  
      */
 1379  
     void deleteArtifact(Object elem) {
 1380  0
         if (!(elem instanceof Artifact)) {
 1381  0
             throw new IllegalArgumentException("elem: " + elem);
 1382  
         }
 1383  0
     }
 1384  
 
 1385  
     /**
 1386  
      * @param elem
 1387  
      *            the association to be deleted
 1388  
      */
 1389  
     void deleteAssociation(Object elem) {
 1390  0
         if (!(elem instanceof UmlAssociation)) {
 1391  0
             throw new IllegalArgumentException("elem: " + elem);
 1392  
         }
 1393  0
     }
 1394  
 
 1395  
     /**
 1396  
      * @param elem
 1397  
      *            the a. to be deleted
 1398  
      */
 1399  
     void deleteAssociationClass(Object elem) {
 1400  0
         if (!(elem instanceof AssociationClass)) {
 1401  0
             throw new IllegalArgumentException("elem: " + elem);
 1402  
         }
 1403  0
     }
 1404  
 
 1405  
     /**
 1406  
      * Does a 'cascading delete' to all modelelements that are associated with
 1407  
      * this element that would be in an illegal state after deletion of the
 1408  
      * element. This method should not be called directly.
 1409  
      * <p>
 1410  
      * 
 1411  
      * In the case of an AssociationEnd these are the following elements:
 1412  
      * <ul>
 1413  
      * <li>Binary Associations that lose one of the AssociationEnds by this
 1414  
      * deletion.
 1415  
      * <li>LinkEnds associated with this AssociationEnd.
 1416  
      * </ul>
 1417  
      * 
 1418  
      * 
 1419  
      * @param elem
 1420  
      * @see UmlFactoryMDRImpl#delete(Object)
 1421  
      */
 1422  
     void deleteAssociationEnd(Object elem) {
 1423  0
         if (!(elem instanceof AssociationEnd)) {
 1424  0
             throw new IllegalArgumentException("elem: " + elem);
 1425  
         }
 1426  0
         AssociationEnd ae = (AssociationEnd) elem;
 1427  0
         UmlAssociation assoc = ae.getAssociation();
 1428  0
         if (assoc != null && assoc.getConnection() != null
 1429  
                 && assoc.getConnection().size() == 2) { // binary association
 1430  0
             modelImpl.getUmlFactory().delete(assoc);
 1431  
         }
 1432  
         // delete LinkEnds which have this as their associationEnd
 1433  0
         modelImpl.getUmlHelper().deleteCollection(
 1434  
                 ((org.omg.uml.UmlPackage) ae.refOutermostPackage())
 1435  
                         .getCommonBehavior().getAAssociationEndLinkEnd()
 1436  
                         .getLinkEnd(ae));
 1437  0
     }
 1438  
 
 1439  
     /**
 1440  
      * @param elem
 1441  
      *            the attribute to be deleted
 1442  
      */
 1443  
     void deleteAttribute(Object elem) {
 1444  0
         if (!(elem instanceof Attribute)) {
 1445  0
             throw new IllegalArgumentException("elem: " + elem);
 1446  
         }
 1447  
         // delete AttributeLinks where this is the Attribute
 1448  0
         Attribute attr = (Attribute) elem;
 1449  0
         modelImpl.getUmlHelper().deleteCollection(
 1450  
                 ((org.omg.uml.UmlPackage) attr.refOutermostPackage())
 1451  
                         .getCommonBehavior().getAAttributeLinkAttribute()
 1452  
                         .getAttributeLink(attr));
 1453  0
     }
 1454  
 
 1455  
     /**
 1456  
      * @param elem the element to be deleted
 1457  
      */
 1458  
     void deleteBehavioralFeature(Object elem) {
 1459  0
         if (!(elem instanceof BehavioralFeature)) {
 1460  0
             throw new IllegalArgumentException("elem: " + elem);
 1461  
         }
 1462  
 
 1463  0
     }
 1464  
 
 1465  
     /**
 1466  
      * @param elem
 1467  
      *            the element to be deleted
 1468  
      */
 1469  
     void deleteBinding(Object elem) {
 1470  0
         if (!(elem instanceof Binding)) {
 1471  0
             throw new IllegalArgumentException("elem: " + elem);
 1472  
         }
 1473  0
         Binding binding = (Binding) elem;
 1474  0
         modelImpl.getUmlHelper().deleteCollection(
 1475  
                 ((org.omg.uml.UmlPackage) binding.refOutermostPackage())
 1476  
                         .getCore().getABindingArgument().getArgument(binding));
 1477  0
     }
 1478  
 
 1479  
     /**
 1480  
      * @param elem
 1481  
      *            the element to be deleted
 1482  
      */
 1483  
     void deleteClass(Object elem) {
 1484  0
         if (!(elem instanceof UmlClass)) {
 1485  0
             throw new IllegalArgumentException("elem: " + elem);
 1486  
         }
 1487  0
     }
 1488  
 
 1489  
     /**
 1490  
      * Does a 'cascading delete' to all modelelements that are associated with
 1491  
      * this element that would be in an illegal state after deletion of the
 1492  
      * element. Does not do an cascading delete for elements that are deleted by
 1493  
      * the MDR method remove. This method should not be called directly.
 1494  
      * <p>
 1495  
      * 
 1496  
      * In the case of a classifier these are the following elements:
 1497  
      * <ul>
 1498  
      * <li>AssociationEnds that have this classifier as type
 1499  
      * </ul>
 1500  
      * 
 1501  
      * @param elem
 1502  
      * @see UmlFactoryMDRImpl#delete(Object)
 1503  
      */
 1504  
     void deleteClassifier(Object elem) {
 1505  0
         if (!(elem instanceof Classifier)) {
 1506  0
             throw new IllegalArgumentException("elem: " + elem);
 1507  
         }
 1508  0
         modelImpl.getUmlHelper().deleteCollection(
 1509  
                 modelImpl.getFacade().getAssociationEnds(elem));
 1510  0
         Classifier cls = (Classifier) elem;
 1511  
         // delete CreateActions which have this as their instantiation
 1512  0
         modelImpl.getUmlHelper().deleteCollection(
 1513  
                 ((org.omg.uml.UmlPackage) cls.refOutermostPackage())
 1514  
                         .getCommonBehavior().getACreateActionInstantiation()
 1515  
                         .getCreateAction(cls));
 1516  
         // TODO: ?delete Instances which have this as their classifier?
 1517  
         // or should we leave them since they contain so much state that the
 1518  
         // user would have to recreate??
 1519  
 //        nsmodel.getUmlHelper().deleteCollection(
 1520  
 //                nsmodel.getUmlPackage().getCommonBehavior()
 1521  
 //                        .getAInstanceClassifier().getInstance(cls));
 1522  
         // TODO: ?delete ObjectFlowStates which have this as their type?
 1523  
 //        nsmodel.getUmlHelper().deleteCollection(
 1524  
 //                nsmodel.getUmlPackage().getActivityGraphs()
 1525  
 //                        .getATypeObjectFlowState().getObjectFlowState(cls));
 1526  
         // TODO: ?delete ClassifierInStates which have this as their type?
 1527  0
         modelImpl.getUmlHelper().deleteCollection(
 1528  
                 ((org.omg.uml.UmlPackage) cls.refOutermostPackage())
 1529  
                         .getActivityGraphs().getATypeClassifierInState()
 1530  
                         .getClassifierInState(cls));
 1531  0
     }
 1532  
 
 1533  
     /**
 1534  
      * @param elem
 1535  
      *            the element to be deleted
 1536  
      */
 1537  
     void deleteComment(Object elem) {
 1538  0
         if (!(elem instanceof Comment)) {
 1539  0
             throw new IllegalArgumentException("elem: " + elem);
 1540  
         }
 1541  0
     }
 1542  
 
 1543  
     /**
 1544  
      * @param elem
 1545  
      *            the element to be deleted
 1546  
      */
 1547  
     void deleteComponent(Object elem) {
 1548  0
         if (!(elem instanceof Component)) {
 1549  0
             throw new IllegalArgumentException("elem: " + elem);
 1550  
         }
 1551  
 
 1552  0
     }
 1553  
 
 1554  
     /**
 1555  
      * @param elem
 1556  
      *            the element to be deleted
 1557  
      */
 1558  
     void deleteConstraint(Object elem) {
 1559  0
         if (!(elem instanceof Constraint)) {
 1560  0
             throw new IllegalArgumentException("elem: " + elem);
 1561  
         }
 1562  0
     }
 1563  
 
 1564  
     /**
 1565  
      * @param elem
 1566  
      *            the element to be deleted
 1567  
      */
 1568  
     void deleteDataType(Object elem) {
 1569  0
         if (!(elem instanceof DataType)) {
 1570  0
             throw new IllegalArgumentException("elem: " + elem);
 1571  
         }
 1572  0
     }
 1573  
 
 1574  
     /**
 1575  
      * @param elem
 1576  
      *            the element to be deleted
 1577  
      */
 1578  
     void deleteDependency(Object elem) {
 1579  0
         if (!(elem instanceof Dependency)) {
 1580  0
             throw new IllegalArgumentException("elem: " + elem);
 1581  
         }
 1582  0
     }
 1583  
 
 1584  
     /**
 1585  
      * @param elem
 1586  
      *            the element to be deleted
 1587  
      */
 1588  
     void deleteElement(Object elem) {
 1589  2
         if (!(elem instanceof Element)) {
 1590  0
             throw new IllegalArgumentException("elem: " + elem);
 1591  
         }
 1592  
 
 1593  2
     }
 1594  
 
 1595  
     /**
 1596  
      * @param elem
 1597  
      *            the element to be deleted
 1598  
      */
 1599  
     void deleteElementResidence(Object elem) {
 1600  0
         if (!(elem instanceof ElementResidence)) {
 1601  0
             throw new IllegalArgumentException("elem: " + elem);
 1602  
         }
 1603  0
     }
 1604  
 
 1605  
     /**
 1606  
      * @param elem
 1607  
      *            the element to be deleted
 1608  
      */
 1609  
     void deleteFeature(Object elem) {
 1610  0
         if (!(elem instanceof Feature)) {
 1611  0
             throw new IllegalArgumentException("elem: " + elem);
 1612  
         }
 1613  0
     }
 1614  
 
 1615  
     /**
 1616  
      * @param elem
 1617  
      *            the element to be deleted
 1618  
      */
 1619  
     void deleteFlow(Object elem) {
 1620  0
         if (!(elem instanceof Flow)) {
 1621  0
             throw new IllegalArgumentException("elem: " + elem);
 1622  
         }
 1623  
 
 1624  0
     }
 1625  
 
 1626  
     /**
 1627  
      * @param elem
 1628  
      *            the element to be deleted
 1629  
      */
 1630  
     void deleteGeneralizableElement(Object elem) {
 1631  0
         if (!(elem instanceof GeneralizableElement)) {
 1632  0
             throw new IllegalArgumentException("elem: " + elem);
 1633  
         }
 1634  
 
 1635  0
         GeneralizableElement ge = (GeneralizableElement) elem;
 1636  0
         modelImpl.getUmlHelper().deleteCollection(ge.getGeneralization());
 1637  0
         modelImpl.getUmlHelper().deleteCollection(
 1638  
                 ((org.omg.uml.UmlPackage) ge.refOutermostPackage()).getCore()
 1639  
                         .getAParentSpecialization().getSpecialization(ge));
 1640  
 
 1641  0
     }
 1642  
 
 1643  
     /**
 1644  
      * @param elem the element to be deleted
 1645  
      */
 1646  
     void deleteGeneralization(Object elem) {
 1647  0
         if (!(elem instanceof Generalization)) {
 1648  0
             throw new IllegalArgumentException("elem: " + elem);
 1649  
         }
 1650  0
     }
 1651  
 
 1652  
     /**
 1653  
      * @param elem
 1654  
      *            the element to be deleted
 1655  
      */
 1656  
     void deleteInterface(Object elem) {
 1657  0
         if (!(elem instanceof Interface)) {
 1658  0
             throw new IllegalArgumentException("elem: " + elem);
 1659  
         }
 1660  0
     }
 1661  
 
 1662  
     /**
 1663  
      * @param elem
 1664  
      *            the element to be deleted
 1665  
      */
 1666  
     void deleteMethod(Object elem) {
 1667  0
         if (!(elem instanceof Method)) {
 1668  0
             throw new IllegalArgumentException("elem: " + elem);
 1669  
         }
 1670  0
     }
 1671  
 
 1672  
     /**
 1673  
      * Does a 'cascading delete' to all modelelements that are associated with
 1674  
      * this element that would be in an illegal state after deletion of the
 1675  
      * element. Does not do an cascading delete for elements that are deleted by
 1676  
      * MDR automatically. This method should not be called directly.
 1677  
      * <p>
 1678  
      * 
 1679  
      * In the case of a modelelement these are the following elements:
 1680  
      * <ul>
 1681  
      * <li>Dependencies that have the modelelement as supplier or as a client
 1682  
      * and are binary. (that is, they only have one supplier and one client)
 1683  
      * <li>Behaviors, TemplateArguments, and ElementImports which require
 1684  
      * this ModelElement
 1685  
      * </ul>
 1686  
      * 
 1687  
      * @param elem
 1688  
      * @see UmlFactoryMDRImpl#delete(Object)
 1689  
      */
 1690  
     void deleteModelElement(Object elem) {
 1691  2
         if (!(elem instanceof ModelElement)) {
 1692  0
             throw new IllegalArgumentException("elem: " + elem);
 1693  
         }
 1694  
 
 1695  
         // Delete dependencies where this is the only client
 1696  2
         Collection<Dependency> deps = org.argouml.model.Model.getFacade()
 1697  
                 .getClientDependencies(elem);
 1698  2
         for (Dependency dep : deps) {
 1699  0
             if (dep.getClient().size() < 2
 1700  
                     && dep.getClient().contains(elem)) {
 1701  0
                 modelImpl.getUmlFactory().delete(dep);
 1702  
             }
 1703  
         }
 1704  
 
 1705  
         // Delete dependencies where this is the only supplier
 1706  2
         deps = org.argouml.model.Model.getFacade()
 1707  
                 .getSupplierDependencies(elem);
 1708  2
         for (Dependency dep : deps) {
 1709  0
             if (dep.getSupplier().size() < 2
 1710  
                     && dep.getSupplier().contains(elem)) {
 1711  0
                 modelImpl.getUmlFactory().delete(dep);
 1712  
             }
 1713  
         }
 1714  
 
 1715  
         /* Do not delete behaviors here! 
 1716  
          * The behavior-context relation in the UML model 
 1717  
          * is an aggregate, not composition. See issue 4281. */
 1718  
 
 1719  2
         ModelElement me = (ModelElement) elem;
 1720  2
         modelImpl.getUmlHelper().deleteCollection(
 1721  
                 ((org.omg.uml.UmlPackage) me.refOutermostPackage()).getCore()
 1722  
                         .getAModelElementTemplateArgument()
 1723  
                         .getTemplateArgument(me));
 1724  2
         modelImpl.getUmlHelper().deleteCollection(
 1725  
                 ((org.omg.uml.UmlPackage) me.refOutermostPackage())
 1726  
                         .getModelManagement()
 1727  
                         .getAImportedElementElementImport()
 1728  
                         .getElementImport(me));
 1729  
         
 1730  
 
 1731  2
     }
 1732  
 
 1733  
     /**
 1734  
      * A namespace deletes its owned elements.
 1735  
      * 
 1736  
      * @param elem
 1737  
      *            is the namespace.
 1738  
      */
 1739  
     void deleteNamespace(Object elem) {
 1740  0
         LOG.debug("Deleting namespace " + elem);
 1741  0
         if (!(elem instanceof Namespace)) {
 1742  0
             throw new IllegalArgumentException("elem: " + elem);
 1743  
         }
 1744  
 
 1745  0
         List<ModelElement> ownedElements = new ArrayList<ModelElement>();
 1746  
         // TODO: This is a composite association, so these will get deleted
 1747  
         // automatically.  The only thing we need to do is check for any
 1748  
         // additional elements that need to be deleted as a result.
 1749  0
         ownedElements.addAll(((Namespace) elem).getOwnedElement());
 1750  0
         for (ModelElement element : ownedElements) {
 1751  0
             LOG.debug("Deleting ownedElement " + element);
 1752  0
             modelImpl.getUmlFactory().delete(element);
 1753  
         }
 1754  0
     }
 1755  
 
 1756  
     /**
 1757  
      * @param elem
 1758  
      *            the element to be deleted
 1759  
      */
 1760  
     void deleteNode(Object elem) {
 1761  0
         if (!(elem instanceof Node)) {
 1762  0
             throw new IllegalArgumentException("elem: " + elem);
 1763  
         }
 1764  
 
 1765  0
     }
 1766  
 
 1767  
     /**
 1768  
      * @param elem
 1769  
      *            the element to be deleted
 1770  
      */
 1771  
     void deleteOperation(Object elem) {
 1772  0
         if (!(elem instanceof Operation)) {
 1773  0
             throw new IllegalArgumentException("elem: " + elem);
 1774  
         }
 1775  0
         Operation oper = (Operation) elem;
 1776  
         // delete CallActions which have this as their operation
 1777  0
         modelImpl.getUmlHelper().deleteCollection(
 1778  
                 ((org.omg.uml.UmlPackage) oper.refOutermostPackage())
 1779  
                         .getCommonBehavior().getACallActionOperation()
 1780  
                         .getCallAction(oper));
 1781  
         // delete CallEvents which have this as their operation
 1782  0
         modelImpl.getUmlHelper().deleteCollection(
 1783  
                 ((org.omg.uml.UmlPackage) oper.refOutermostPackage())
 1784  
                         .getStateMachines().getAOccurrenceOperation()
 1785  
                         .getOccurrence(oper));
 1786  0
     }
 1787  
 
 1788  
     /**
 1789  
      * @param elem
 1790  
      *            the element to be deleted
 1791  
      */
 1792  
     void deleteParameter(Object elem) {
 1793  0
         if (!(elem instanceof Parameter)) {
 1794  0
             throw new IllegalArgumentException("elem: " + elem);
 1795  
         }
 1796  0
     }
 1797  
 
 1798  
     /**
 1799  
      * @param elem
 1800  
      *            the element to be deleted
 1801  
      */
 1802  
     void deletePermission(Object elem) {
 1803  0
         if (!(elem instanceof Permission)) {
 1804  0
             throw new IllegalArgumentException("elem: " + elem);
 1805  
         }
 1806  0
     }
 1807  
 
 1808  
     /**
 1809  
      * @param elem
 1810  
      *            the element to be deleted
 1811  
      */
 1812  
     void deletePresentationElement(Object elem) {
 1813  0
         if (!(elem instanceof PresentationElement)) {
 1814  0
             throw new IllegalArgumentException("elem: " + elem);
 1815  
         }
 1816  
 
 1817  0
     }
 1818  
 
 1819  
     /**
 1820  
      * @param elem
 1821  
      *            the element to be deleted
 1822  
      */
 1823  
     void deleteRelationship(Object elem) {
 1824  0
         if (!(elem instanceof Relationship)) {
 1825  0
             throw new IllegalArgumentException("elem: " + elem);
 1826  
         }
 1827  0
     }
 1828  
 
 1829  
     /**
 1830  
      * @param elem
 1831  
      *            the element to be deleted
 1832  
      */
 1833  
     void deleteStructuralFeature(Object elem) {
 1834  0
         if (!(elem instanceof StructuralFeature)) {
 1835  0
             throw new IllegalArgumentException("elem: " + elem);
 1836  
         }
 1837  0
     }
 1838  
 
 1839  
     /**
 1840  
      * @param elem
 1841  
      *            the element to be deleted
 1842  
      */
 1843  
     void deleteTemplateArgument(Object elem) {
 1844  0
         if (!(elem instanceof TemplateArgument)) {
 1845  0
             throw new IllegalArgumentException("elem: " + elem);
 1846  
         }
 1847  0
     }
 1848  
     
 1849  
     /**
 1850  
      * @param elem
 1851  
      *            the element to be deleted
 1852  
      */
 1853  
     void deleteTemplateParameter(Object elem) {
 1854  0
         if (!(elem instanceof TemplateParameter)) {
 1855  0
             throw new IllegalArgumentException("elem: " + elem);
 1856  
         }
 1857  0
     }
 1858  
 
 1859  
     /**
 1860  
      * @param elem
 1861  
      *            the element to be deleted
 1862  
      */
 1863  
     void deleteUsage(Object elem) {
 1864  0
         if (!(elem instanceof Usage)) {
 1865  0
             throw new IllegalArgumentException("elem: " + elem);
 1866  
         }
 1867  0
     }
 1868  
 
 1869  
     /**
 1870  
      * Delete an Enumeration.
 1871  
      * @param elem
 1872  
      *            the element to be deleted
 1873  
      * @since UML 1.4
 1874  
      */
 1875  
     void deleteEnumeration(Object elem) {
 1876  0
         if (!(elem instanceof Enumeration)) {
 1877  0
             throw new IllegalArgumentException("elem: " + elem);
 1878  
         }
 1879  
         // EnumerationLiterals should get deleted implicitly
 1880  
         // since they are associated by composition
 1881  0
     }
 1882  
 
 1883  
     /**
 1884  
      * Delete EnumerationLiteral.
 1885  
      * @param elem
 1886  
      *            the element to be deleted
 1887  
      * @since UML 1.4
 1888  
      */
 1889  
     void deleteEnumerationLiteral(Object elem) {
 1890  0
         if (!(elem instanceof EnumerationLiteral)) {
 1891  0
             throw new IllegalArgumentException("elem: " + elem);
 1892  
         }
 1893  0
     }
 1894  
 
 1895  
     /**
 1896  
      * Delete the given UML Primitive.
 1897  
      * 
 1898  
      * @param elem the element to be deleted
 1899  
      * @since UML 1.4
 1900  
      */
 1901  
     void deletePrimitive(Object elem) {
 1902  0
         if (!(elem instanceof Primitive)) {
 1903  0
             throw new IllegalArgumentException("elem: " + elem);
 1904  
         }
 1905  0
     }
 1906  
 
 1907  
     /**
 1908  
      * Delete the given ProgrammingLanguageDataType.
 1909  
      * 
 1910  
      * @param elem the element to be deleted
 1911  
      * @since UML 1.4
 1912  
      */
 1913  
     void deleteProgrammingLanguageDataType(Object elem) {
 1914  0
         if (!(elem instanceof ProgrammingLanguageDataType)) {
 1915  0
             throw new IllegalArgumentException("elem: " + elem);
 1916  
         }
 1917  0
     }
 1918  
 
 1919  
 
 1920  
 
 1921  
     /**
 1922  
      * Copies a class, and it's features. This may also require other
 1923  
      * classifiers to be copied.
 1924  
      * 
 1925  
      * @param source
 1926  
      *            is the class to copy.
 1927  
      * @param ns
 1928  
      *            is the namespace to put the copy in.
 1929  
      * @return a newly created class.
 1930  
      */
 1931  
     public UmlClass copyClass(Object source, Object ns) {
 1932  0
         if (!(source instanceof UmlClass && ns instanceof Namespace)) {
 1933  0
             throw new IllegalArgumentException("source: " + source + ",ns: "
 1934  
                     + ns);
 1935  
         }
 1936  
 
 1937  0
         UmlClass c = createClass();
 1938  0
         ((Namespace) ns).getOwnedElement().add(c);
 1939  0
         doCopyClass(source, c);
 1940  0
         return c;
 1941  
     }
 1942  
 
 1943  
     /**
 1944  
      * Copies a feature from one classifier to another.
 1945  
      *
 1946  
      * @param source is the feature to copy.
 1947  
      * @param classifier is the classifier to put the copy in.
 1948  
      * @return a newly created feature.
 1949  
      */
 1950  
     public Feature copyFeature(Object source, Object classifier) {
 1951  0
         if (!(source instanceof Feature && classifier instanceof Classifier)) {
 1952  0
             throw new IllegalArgumentException("source: " + source 
 1953  
                     + ",classifier: " + classifier);
 1954  
         }
 1955  
 
 1956  0
         Feature f = null;
 1957  0
         if (source instanceof Attribute) {
 1958  0
             Attribute attr = createAttribute();
 1959  0
             doCopyAttribute((Attribute) source, attr);
 1960  0
             f = attr;
 1961  0
         } else if (source instanceof Operation) {
 1962  0
             Operation oper = createOperation();
 1963  0
             doCopyOperation((Operation) source, oper);
 1964  
             // TODO: build a return parameter
 1965  0
             f = oper;
 1966  0
         } else if (source instanceof Method) {
 1967  0
             Method method = createMethod();
 1968  0
             doCopyMethod((Method) source, method);
 1969  0
             f = method;
 1970  0
         } else if (source instanceof Reception) {
 1971  0
             Reception reception = (Reception) 
 1972  
                 modelImpl.getCommonBehaviorFactory().createReception();
 1973  0
             doCopyReception((Reception) source, reception);
 1974  0
             f = reception;
 1975  0
         } else {
 1976  0
             throw new IllegalArgumentException("source: " + source);
 1977  
         }
 1978  
 
 1979  0
         f.setOwner((Classifier) classifier);
 1980  0
         ((Classifier) classifier).getFeature().add(f);
 1981  0
         return f;
 1982  
     }
 1983  
 
 1984  
     /**
 1985  
      * Copies a datatype, and it's features. This may also require other
 1986  
      * classifiers to be copied.
 1987  
      * 
 1988  
      * @param source
 1989  
      *            is the datatype to copy.
 1990  
      * @param ns
 1991  
      *            is the namespace to put the copy in.
 1992  
      * @return a newly created data type.
 1993  
      */
 1994  
     public DataType copyDataType(Object source, Object ns) {
 1995  0
         if (!(source instanceof DataType)) {
 1996  0
             throw new IllegalArgumentException();
 1997  
         }
 1998  
 
 1999  0
         if (!(ns instanceof Namespace)) {
 2000  0
             throw new IllegalArgumentException();
 2001  
         }
 2002  
 
 2003  0
         DataType i = createDataType();
 2004  0
         ((Namespace) ns).getOwnedElement().add(i);
 2005  0
         doCopyDataType(source, i);
 2006  0
         return i;
 2007  
     }
 2008  
 
 2009  
     /**
 2010  
      * Copies an interface, and it's features. This may also require other
 2011  
      * classifiers to be copied.
 2012  
      * 
 2013  
      * @param source
 2014  
      *            is the interface to copy.
 2015  
      * @param ns
 2016  
      *            is the namespace to put the copy in.
 2017  
      * @return a newly created interface.
 2018  
      */
 2019  
     public Interface copyInterface(Object source, Object ns) {
 2020  0
         if (!(source instanceof Interface)) {
 2021  0
             throw new IllegalArgumentException();
 2022  
         }
 2023  
 
 2024  0
         if (!(ns instanceof Namespace)) {
 2025  0
             throw new IllegalArgumentException();
 2026  
         }
 2027  
 
 2028  0
         Interface i = createInterface();
 2029  0
         ((Namespace) ns).getOwnedElement().add(i);
 2030  0
         doCopyInterface(source, i);
 2031  0
         return i;
 2032  
     }
 2033  
 
 2034  
     /**
 2035  
      * 
 2036  
      * @param from
 2037  
      *            The object which own the enumeration to copy
 2038  
      * @param to
 2039  
      *            The object to which copy the enumeration
 2040  
      */
 2041  
     public void copyEnumeration(Object from, Object to) {
 2042  0
         doCopyModelElement(from, to);
 2043  0
         List listFrom = ((Enumeration) from).getLiteral();
 2044  0
         List listTo = ((Enumeration) to).getLiteral();
 2045  
         Object literalFrom;
 2046  
         Object literalTo;
 2047  0
         for (int i = 0; i < listFrom.size(); i++) {
 2048  0
             literalFrom = listFrom.get(i);
 2049  0
             if (listTo.size() > i) {
 2050  0
                 literalTo = listTo.get(i);
 2051  
             } else {
 2052  0
                 literalTo = createEnumerationLiteral();
 2053  0
                 listTo.add(literalTo);
 2054  
             }
 2055  0
             doCopyModelElement(literalFrom, literalTo);
 2056  0
             ((EnumerationLiteral) literalTo).setEnumeration((Enumeration) to);
 2057  
         }
 2058  0
     }
 2059  
 
 2060  
     /**
 2061  
      * Used by the copy functions. Do not call this function directly.
 2062  
      */
 2063  
     private void doCopyElement(Object source, Object target) {
 2064  
         // Nothing more to do.
 2065  0
     }
 2066  
 
 2067  
     /**
 2068  
      * Used by the copy functions. Do not call this function directly.
 2069  
      * 
 2070  
      * @param source
 2071  
      *            the source class
 2072  
      * @param target
 2073  
      *            the target class
 2074  
      */
 2075  
     public void doCopyClass(Object source, Object target) {
 2076  0
         if (!(source instanceof UmlClass)) {
 2077  0
             throw new IllegalArgumentException();
 2078  
         }
 2079  
 
 2080  0
         if (!(target instanceof UmlClass)) {
 2081  0
             throw new IllegalArgumentException();
 2082  
         }
 2083  
 
 2084  0
         doCopyClassifier(source, target);
 2085  
 
 2086  0
         ((UmlClass) target).setActive(((UmlClass) source).isActive());
 2087  0
     }
 2088  
 
 2089  
     /*
 2090  
      * TODO: All the ToDos in the doCopyFoo methods below are inherited from the
 2091  
      * NSUML implementation and do not reflect new issues. One additional thing
 2092  
      * which does need to be dealt with is the copying of any attributes which
 2093  
      * have been added since this code was implemented for UML 1.3.
 2094  
      */
 2095  
     /**
 2096  
      * Used by the copy functions. Do not call this function directly. 
 2097  
      * TODO: actions? instances? collaborations etc?
 2098  
      * 
 2099  
      * @param source
 2100  
      *            the source classifier
 2101  
      * @param target
 2102  
      *            the target classifier
 2103  
      */
 2104  
     public void doCopyClassifier(Object source, Object target) {
 2105  0
         if (!(source instanceof Classifier)) {
 2106  0
             throw new IllegalArgumentException();
 2107  
         }
 2108  
 
 2109  0
         if (!(target instanceof Classifier)) {
 2110  0
             throw new IllegalArgumentException();
 2111  
         }
 2112  
 
 2113  
         // TODO: how to merge multiple inheritance? Necessary?
 2114  
         // This currently copies the common ancestors multiple times
 2115  0
         doCopyNamespace(source, target);
 2116  0
         doCopyGeneralizableElement(source, target);
 2117  
 
 2118  
         // Copy all the Features
 2119  0
         for (Feature f : ((Classifier) source).getFeature()) {
 2120  0
             copyFeature(f, target);
 2121  
         }
 2122  0
     }
 2123  
 
 2124  
     /**
 2125  
      * Used by the copy functions. Do not call this function directly.
 2126  
      * 
 2127  
      * @param source
 2128  
      *            the source datatype
 2129  
      * @param target
 2130  
      *            the target datatype
 2131  
      */
 2132  
     public void doCopyDataType(Object source, Object target) {
 2133  0
         if (!(source instanceof DataType)) {
 2134  0
             throw new IllegalArgumentException();
 2135  
         }
 2136  
 
 2137  0
         if (!(target instanceof DataType)) {
 2138  0
             throw new IllegalArgumentException();
 2139  
         }
 2140  
 
 2141  0
         doCopyClassifier(source, target);
 2142  0
     }
 2143  
 
 2144  
     /**
 2145  
      * Used by the copy functions. Do not call this function directly. 
 2146  
      * TODO: generalizations, specializations?
 2147  
      * 
 2148  
      * @param source
 2149  
      *            the source generalizable element
 2150  
      * @param target
 2151  
      *            the target generalizable element
 2152  
      */
 2153  
     public void doCopyGeneralizableElement(Object source, Object target) {
 2154  0
         if (!(source instanceof GeneralizableElement
 2155  
                 && target instanceof GeneralizableElement)) {
 2156  0
             throw new IllegalArgumentException("source: " + source
 2157  
                     + ",target: " + target);
 2158  
         }
 2159  
 
 2160  0
         doCopyModelElement(source, target);
 2161  
 
 2162  0
         GeneralizableElement targetGE = ((GeneralizableElement) target);
 2163  0
         GeneralizableElement sourceGE = ((GeneralizableElement) source);
 2164  0
         targetGE.setAbstract(sourceGE.isAbstract());
 2165  0
         targetGE.setLeaf(sourceGE.isLeaf());
 2166  0
         targetGE.setRoot(sourceGE.isRoot());
 2167  0
     }
 2168  
 
 2169  
     /**
 2170  
      * Used by the copy functions. Do not call this function directly.
 2171  
      * 
 2172  
      * @param source
 2173  
      *            the source interface
 2174  
      * @param target
 2175  
      *            the target interface
 2176  
      */
 2177  
     public void doCopyInterface(Object source, Object target) {
 2178  0
         if (!(source instanceof Interface)) {
 2179  0
             throw new IllegalArgumentException();
 2180  
         }
 2181  
 
 2182  0
         if (!(target instanceof Interface)) {
 2183  0
             throw new IllegalArgumentException();
 2184  
         }
 2185  
 
 2186  0
         doCopyClassifier(source, target);
 2187  0
     }
 2188  
 
 2189  
     /**
 2190  
      * Used by the copy functions. Do not call this function directly. 
 2191  
      * TODO: template parameters, default type 
 2192  
      * TODO: constraining elements 
 2193  
      * TODO: flows, dependencies, comments, bindings, contexts ??? 
 2194  
      * TODO: contents, residences ???
 2195  
      * 
 2196  
      * @param source
 2197  
      *            the source me
 2198  
      * @param target
 2199  
      *            the target me
 2200  
      */
 2201  
     public void doCopyModelElement(Object source, Object target) {
 2202  0
         if (!(source instanceof ModelElement)) {
 2203  0
             throw new IllegalArgumentException();
 2204  
         }
 2205  
 
 2206  0
         if (!(target instanceof ModelElement)) {
 2207  0
             throw new IllegalArgumentException();
 2208  
         }
 2209  
 
 2210  
         // Set the name so that superclasses can find the newly
 2211  
         // created element in the model, if necessary.
 2212  0
         ModelElement targetME = ((ModelElement) target);
 2213  0
         ModelElement sourceME = ((ModelElement) source);
 2214  0
         targetME.setName(sourceME.getName());
 2215  0
         doCopyElement(source, target);
 2216  
 
 2217  0
         targetME.setSpecification(sourceME.isSpecification());
 2218  0
         targetME.setVisibility(sourceME.getVisibility());
 2219  0
         modelImpl.getExtensionMechanismsFactory()
 2220  
                 .copyTaggedValues(source, target);
 2221  
 
 2222  0
         if (!sourceME.getStereotype().isEmpty()) {
 2223  
             // Note that if we're copying this element then we
 2224  
             // must also be allowed to copy other necessary
 2225  
             // objects.
 2226  0
             for (Stereotype s : sourceME.getStereotype()) {
 2227  0
                 targetME.getStereotype().add(s);
 2228  
             }
 2229  
         }
 2230  0
     }
 2231  
 
 2232  
     /**
 2233  
      * Used by the copy functions. Do not call this function directly.
 2234  
      * 
 2235  
      * @param source
 2236  
      *            the source namespace
 2237  
      * @param target
 2238  
      *            the target namespace
 2239  
      */
 2240  
     public void doCopyNamespace(Object source, Object target) {
 2241  0
         if (!(source instanceof Namespace)) {
 2242  0
             throw new IllegalArgumentException();
 2243  
         }
 2244  
 
 2245  0
         if (!(target instanceof Namespace)) {
 2246  0
             throw new IllegalArgumentException();
 2247  
         }
 2248  
 
 2249  0
         doCopyModelElement(source, target);
 2250  
         // Nothing more to do, don't copy owned elements.
 2251  0
     }
 2252  
 
 2253  
     /**
 2254  
      * Copy the meta-attributes of an Attribute to another.
 2255  
      * 
 2256  
      * @param source the source attribute
 2257  
      * @param target the new attribute to be adapted
 2258  
      */
 2259  
     void doCopyAttribute(Attribute source, Attribute target) {
 2260  
         // TODO: Delete old multiplicity? Why is "copy" using hard coded value? - tfm
 2261  0
         target.setMultiplicity(getMultiplicity11());
 2262  0
         target.setChangeability(source.getChangeability());
 2263  0
         target.setTargetScope(source.getTargetScope());
 2264  0
         target.setType(source.getType());
 2265  
 
 2266  0
         doCopyFeature(source, target);
 2267  0
     }
 2268  
 
 2269  
     /**
 2270  
      * Copy the attributes of an Operation to another.
 2271  
      * 
 2272  
      * @param source the source operation
 2273  
      * @param target the new operation to be modified
 2274  
      */
 2275  
     void doCopyOperation(Operation source, Operation target) {
 2276  0
         target.setAbstract(source.isAbstract());
 2277  0
         target.setLeaf(source.isLeaf());
 2278  0
         target.setRoot(source.isRoot());
 2279  0
         target.setConcurrency(source.getConcurrency());
 2280  0
         target.setSpecification(source.getSpecification());
 2281  
     
 2282  0
         doCopyBehavioralFeature(source, target);
 2283  0
     }
 2284  
 
 2285  
     /**
 2286  
      * Copy the attributes of one Method to another.
 2287  
      * 
 2288  
      * @param source the method to copy attributes from
 2289  
      * @param target the method to be adapted
 2290  
      */
 2291  
     void doCopyMethod(Method source, Method target) {
 2292  0
         ProcedureExpression pe = source.getBody();
 2293  0
         ProcedureExpression oldPe = target.getBody();
 2294  0
         if (!equal(oldPe,pe)) {
 2295  0
             target.setBody((ProcedureExpression) 
 2296  
                     modelImpl.getDataTypesFactory().createProcedureExpression(
 2297  
                             pe.getLanguage(), pe.getBody()));
 2298  0
             if (oldPe != null) {
 2299  0
                 Model.getUmlFactory().delete(oldPe);
 2300  
             }
 2301  
         }
 2302  
 
 2303  0
         doCopyBehavioralFeature(source, target);
 2304  0
     }
 2305  
 
 2306  
 
 2307  
     private boolean equal(Expression expr1, Expression expr2) {
 2308  0
         if (expr1 == null) {
 2309  0
             if (expr2 == null) {
 2310  0
                 return true;
 2311  
             } else {
 2312  0
                 return false;
 2313  
             }
 2314  
         } else {
 2315  0
             return expr1.equals(expr2);
 2316  
         }
 2317  
     }
 2318  
     
 2319  
     /**
 2320  
      * Copy the attributes of one Reception to another.
 2321  
      * 
 2322  
      * @param source the reception to copy attributes from
 2323  
      * @param target the reception to be adapted
 2324  
      */
 2325  
     void doCopyReception(Reception source, Reception target) {
 2326  0
         target.setAbstract(source.isAbstract());
 2327  0
         target.setLeaf(source.isLeaf());
 2328  0
         target.setRoot(source.isRoot());
 2329  0
         target.setSpecification(source.getSpecification());
 2330  0
         target.setSignal(source.getSignal());
 2331  
 
 2332  0
         doCopyBehavioralFeature(source, target);
 2333  0
     }
 2334  
     
 2335  
     
 2336  
     /**
 2337  
      * Copy the attributes of one BehavioralFeature to another.
 2338  
      * 
 2339  
      * @param source the BehavioralFeature to copy from
 2340  
      * @param target the BehavioralFeature to b adapted
 2341  
      */
 2342  
     void doCopyBehavioralFeature(BehavioralFeature source, 
 2343  
             BehavioralFeature target) {
 2344  0
         target.setQuery(source.isQuery());
 2345  
         // copy raised signals:
 2346  0
         Collection<Signal> raisedSignals = ((org.omg.uml.UmlPackage) source
 2347  
                 .refOutermostPackage()).getCommonBehavior()
 2348  
                 .getAContextRaisedSignal().getRaisedSignal(source);
 2349  0
         for (Signal signal : raisedSignals) {
 2350  0
             ((org.omg.uml.UmlPackage) source.refOutermostPackage())
 2351  
                     .getCommonBehavior().getAContextRaisedSignal().add(target,
 2352  
                             signal);
 2353  
         }
 2354  
 
 2355  0
         doCopyFeature(source, target);
 2356  0
     }
 2357  
 
 2358  
     /**
 2359  
      * Copy the attributes of one Feature to another.
 2360  
      * 
 2361  
      * @param source the Feature to copy from
 2362  
      * @param target the Feature to copy to
 2363  
      */
 2364  
     void doCopyFeature(Feature source, Feature target) {
 2365  0
         target.setVisibility(source.getVisibility());
 2366  0
         target.setOwnerScope(source.getOwnerScope());
 2367  
 
 2368  0
         doCopyModelElement(source, target);
 2369  0
     }
 2370  
 
 2371  
 }