Coverage Report - org.argouml.model.mdr.ActivityGraphsFactoryMDRImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActivityGraphsFactoryMDRImpl
24%
19/79
13%
4/30
2.5
 
 1  
 /* $Id: ActivityGraphsFactoryMDRImpl.java 18451 2010-06-21 11:57:41Z mvw $
 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  
  *    tfmorris
 11  
  *    mvw
 12  
  *****************************************************************************
 13  
  *
 14  
  * Some portions of this file was previously release using the BSD License:
 15  
  */
 16  
 
 17  
 // Copyright (c) 1996-2007 The Regents of the University of California. All
 18  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 19  
 // software and its documentation without fee, and without a written
 20  
 // agreement is hereby granted, provided that the above copyright notice
 21  
 // and this paragraph appear in all copies.  This software program and
 22  
 // documentation are copyrighted by The Regents of the University of
 23  
 // California. The software program and documentation are supplied "AS
 24  
 // IS", without any accompanying services from The Regents. The Regents
 25  
 // does not warrant that the operation of the program will be
 26  
 // uninterrupted or error-free. The end-user understands that the program
 27  
 // was developed for research purposes and is advised not to rely
 28  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 29  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 30  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 31  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 32  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 33  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 34  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 35  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 36  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 37  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 38  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 39  
 
 40  
 package org.argouml.model.mdr;
 41  
 
 42  
 import java.util.Collection;
 43  
 
 44  
 import org.argouml.model.ActivityGraphsFactory;
 45  
 import org.omg.uml.behavioralelements.activitygraphs.ActionState;
 46  
 import org.omg.uml.behavioralelements.activitygraphs.ActivityGraph;
 47  
 import org.omg.uml.behavioralelements.activitygraphs.CallState;
 48  
 import org.omg.uml.behavioralelements.activitygraphs.ClassifierInState;
 49  
 import org.omg.uml.behavioralelements.activitygraphs.ObjectFlowState;
 50  
 import org.omg.uml.behavioralelements.activitygraphs.Partition;
 51  
 import org.omg.uml.behavioralelements.activitygraphs.SubactivityState;
 52  
 import org.omg.uml.behavioralelements.statemachines.CompositeState;
 53  
 import org.omg.uml.behavioralelements.statemachines.State;
 54  
 import org.omg.uml.foundation.core.BehavioralFeature;
 55  
 import org.omg.uml.foundation.core.Classifier;
 56  
 import org.omg.uml.foundation.core.ModelElement;
 57  
 import org.omg.uml.foundation.core.Namespace;
 58  
 import org.omg.uml.foundation.core.UmlClass;
 59  
 
 60  
 /**
 61  
  * Factory to create UML classes for the UML BehaviorialElements::ActivityGraphs
 62  
  * package.
 63  
  * <p>
 64  
  * @since ARGO0.19.5
 65  
  * @author Ludovic Ma&icirc;tre
 66  
  * Derived from NSUML implementation by:
 67  
  * @author Thierry Lach
 68  
  */
 69  19
 class ActivityGraphsFactoryMDRImpl extends AbstractUmlModelFactoryMDR
 70  
         implements ActivityGraphsFactory {
 71  
 
 72  
     /**
 73  
      * The model implementation.
 74  
      */
 75  
     private MDRModelImplementation modelImpl;
 76  
 
 77  
     /**
 78  
      * Don't allow instantiation.
 79  
      * 
 80  
      * @param implementation
 81  
      *            To get other helpers and factories.
 82  
      */
 83  900
     ActivityGraphsFactoryMDRImpl(MDRModelImplementation implementation) {
 84  900
         modelImpl = implementation;
 85  900
     }
 86  
 
 87  
 
 88  
     public ActionState createActionState() {
 89  0
         ActionState myActionState = modelImpl.getUmlPackage()
 90  
                 .getActivityGraphs().getActionState().createActionState();
 91  0
         super.initialize(myActionState);
 92  0
         return myActionState;
 93  
     }
 94  
 
 95  
 
 96  
     public ActivityGraph createActivityGraph() {
 97  19
         ActivityGraph myActivityGraph = modelImpl.getUmlPackage().
 98  
             getActivityGraphs().getActivityGraph().createActivityGraph();
 99  19
         super.initialize(myActivityGraph);
 100  19
         return myActivityGraph;
 101  
     }
 102  
 
 103  
 
 104  
     public CallState createCallState() {
 105  0
         CallState myCallState = modelImpl.getUmlPackage().getActivityGraphs().
 106  
             getCallState().createCallState();
 107  0
         super.initialize(myCallState);
 108  0
         return myCallState;
 109  
     }
 110  
 
 111  
 
 112  
     public ClassifierInState createClassifierInState() {
 113  0
         ClassifierInState myClassifierInState = modelImpl.getUmlPackage().
 114  
             getActivityGraphs().getClassifierInState().
 115  
                 createClassifierInState();
 116  0
         super.initialize(myClassifierInState);
 117  0
         return myClassifierInState;
 118  
     }
 119  
 
 120  
 
 121  
     public ObjectFlowState createObjectFlowState() {
 122  0
         ObjectFlowState myObjectFlowState = modelImpl.getUmlPackage().
 123  
             getActivityGraphs().getObjectFlowState().
 124  
                 createObjectFlowState();
 125  0
         super.initialize(myObjectFlowState);
 126  0
         return myObjectFlowState;
 127  
     }
 128  
 
 129  
 
 130  
     public Partition createPartition() {
 131  0
         Partition myPartition = modelImpl.getUmlPackage().getActivityGraphs().
 132  
             getPartition().createPartition();
 133  0
         super.initialize(myPartition);
 134  0
         return myPartition;
 135  
     }
 136  
 
 137  
 
 138  
     public SubactivityState createSubactivityState() {
 139  0
         SubactivityState mySubactivityState =
 140  
                 modelImpl.getUmlPackage().getActivityGraphs()
 141  
                         .getSubactivityState().createSubactivityState();
 142  0
         super.initialize(mySubactivityState);
 143  0
         return mySubactivityState;
 144  
     }
 145  
 
 146  
 
 147  
     public ActivityGraph buildActivityGraph(Object theContext) {
 148  19
         if (theContext instanceof ModelElement) {
 149  19
             ActivityGraph myActivityGraph = createActivityGraph();
 150  19
             ModelElement modelelement = (ModelElement) theContext;
 151  19
             myActivityGraph.setContext(modelelement);
 152  
             
 153  19
             if (modelelement instanceof BehavioralFeature) {
 154  0
                 modelelement = ((BehavioralFeature) modelelement).getOwner();
 155  
             }
 156  19
             if (modelelement instanceof Namespace) {
 157  19
                 Namespace namespace = (Namespace) modelelement;
 158  
                 /* Follow well-formedness rule for a Class [2].
 159  
                  * See issue 4282. Do not use a class 
 160  
                  * as the namespace for an activityGraph: */
 161  19
                 while (namespace instanceof UmlClass) {
 162  0
                     Namespace pns = namespace.getNamespace();
 163  0
                     if (pns == null) break;
 164  0
                     namespace = pns;
 165  0
                 }
 166  19
                 myActivityGraph.setNamespace(namespace);
 167  
             }
 168  19
             State top =
 169  
                     (CompositeState) modelImpl.getStateMachinesFactory()
 170  
                             .buildCompositeStateOnStateMachine(myActivityGraph);
 171  19
             myActivityGraph.setTop(top);
 172  19
             return myActivityGraph;
 173  
         }
 174  0
         throw new IllegalArgumentException(
 175  
                 "Cannot create an ActivityGraph with context " + theContext);
 176  
     }
 177  
 
 178  
 
 179  
     public ObjectFlowState buildObjectFlowState(Object compositeState) {
 180  0
         if (!(compositeState instanceof CompositeState)) {
 181  0
             throw new IllegalArgumentException();
 182  
         }
 183  
 
 184  0
         ObjectFlowState state = createObjectFlowState();
 185  0
         state.setContainer((CompositeState) compositeState);
 186  0
         return state;
 187  
     }
 188  
 
 189  
 
 190  
     public ClassifierInState buildClassifierInState(Object classifier,
 191  
             Collection state) {
 192  0
         if (!(classifier instanceof Classifier)) {
 193  0
             throw new IllegalArgumentException();
 194  
         }
 195  0
         if (state.size() < 1) {
 196  0
             throw new IllegalArgumentException(
 197  
                     "Collection of states must have at least one element");
 198  
         }
 199  
 
 200  0
         ClassifierInState c = createClassifierInState();
 201  0
         c.setType((Classifier) classifier);
 202  0
         c.getInState().addAll(state);
 203  0
         c.setNamespace(((Classifier) classifier).getNamespace());
 204  
         // this doesn't support I18N or multiple states, 
 205  
         // but it's just a default
 206  0
         c.setName(((Classifier) classifier).getName() 
 207  
                 + "inState[" 
 208  
                 + ((State) state.iterator().next()).getName() 
 209  
                 + "]");
 210  0
         return c;
 211  
     }
 212  
 
 213  
     /**
 214  
      * @param elem
 215  
      *            the ActionState to be deleted
 216  
      */
 217  
     void deleteActionState(Object elem) {
 218  0
         if (!(elem instanceof ActionState)) {
 219  0
             throw new IllegalArgumentException();
 220  
         }
 221  0
     }
 222  
 
 223  
     /**
 224  
      * @param elem
 225  
      *            the ActivityGraph to be deleted
 226  
      */
 227  
     void deleteActivityGraph(Object elem) {
 228  0
         if (!(elem instanceof ActivityGraph)) {
 229  0
             throw new IllegalArgumentException();
 230  
         }
 231  
         // Partitions are composite elements and will get deleted implicitly
 232  
         // Partition contents don't need to be deleted or checked
 233  0
     }
 234  
 
 235  
     /**
 236  
      * @param elem
 237  
      *            the CallState to be deleted
 238  
      */
 239  
     void deleteCallState(Object elem) {
 240  0
         if (!(elem instanceof CallState)) {
 241  0
             throw new IllegalArgumentException();
 242  
         }
 243  0
     }
 244  
 
 245  
     /**
 246  
      * @param elem
 247  
      *            the ClassifierInState to be deleted
 248  
      */
 249  
     void deleteClassifierInState(Object elem) {
 250  0
         if (!(elem instanceof ClassifierInState)) {
 251  0
             throw new IllegalArgumentException();
 252  
         }
 253  0
     }
 254  
 
 255  
     /**
 256  
      * @param elem
 257  
      *            ObjectFlowState
 258  
      */
 259  
     void deleteObjectFlowState(Object elem) {
 260  0
         if (!(elem instanceof ObjectFlowState)) {
 261  0
             throw new IllegalArgumentException();
 262  
         }
 263  0
     }
 264  
 
 265  
     /**
 266  
      * @param elem
 267  
      *            Partition
 268  
      */
 269  
     void deletePartition(Object elem) {
 270  0
         if (!(elem instanceof Partition)) {
 271  0
             throw new IllegalArgumentException();
 272  
         }
 273  0
     }
 274  
 
 275  
     /**
 276  
      * @param elem
 277  
      *            SubactivityState
 278  
      */
 279  
     void deleteSubactivityState(Object elem) {
 280  0
         if (!(elem instanceof SubactivityState)) {
 281  0
             throw new IllegalArgumentException();
 282  
         }
 283  0
     }
 284  
 
 285  
 }