Coverage Report - org.argouml.uml.cognitive.critics.CrCrossNamespaceAssoc
 
Classes in this File Line Coverage Branch Coverage Complexity
CrCrossNamespaceAssoc
40%
8/20
0%
0/10
3.667
 
 1  
 /* $Id: CrCrossNamespaceAssoc.java 17849 2010-01-12 19:50:34Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 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  
  *    maurelio1234
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2007 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.uml.cognitive.critics;
 40  
 
 41  
 import java.util.HashSet;
 42  
 import java.util.Iterator;
 43  
 import java.util.Set;
 44  
 
 45  
 import org.argouml.cognitive.Critic;
 46  
 import org.argouml.cognitive.Designer;
 47  
 import org.argouml.model.Model;
 48  
 import org.argouml.uml.cognitive.UMLDecision;
 49  
 
 50  
 /**
 51  
  * A critic to check that the classifiers associated with the ends of an
 52  
  * association are in the same namespace as the association.<p>
 53  
  *
 54  
  * This is the fourth well-formedness rule for associations in the UML 1.3
 55  
  * standard (see section 2.5.3 of the standard).<p>
 56  
  *
 57  
  * Well-formedness rule [4] for Association. See page 52 of UML 1.4
 58  
  * Semantics. OMG document UML 1.4.2 formal/04-07-02.
 59  
  * 
 60  
  * See the ArgoUML User Manual: Classifier not in Namespace of its Association
 61  
  *
 62  
  * @author Jason Robbins
 63  
  */
 64  
 public class CrCrossNamespaceAssoc extends CrUML {
 65  
     /**
 66  
      * Constructor for the critic.<p>
 67  
      *
 68  
      * Sets up the resource name, which will allow headline and description
 69  
      * to found for the current locale. Provides a design issue category
 70  
      * (MODULARITY) and a knowledge type (SYNTAX).
 71  
      */
 72  900
     public CrCrossNamespaceAssoc() {
 73  900
         setupHeadAndDesc();
 74  900
         addSupportedDecision(UMLDecision.MODULARITY);
 75  900
         setKnowledgeTypes(Critic.KT_SYNTAX);
 76  900
     }
 77  
 
 78  
     /**
 79  
      * The trigger for the critic.<p>
 80  
      *
 81  
      * Get the association. Then loop through the association ends, checking
 82  
      * that their associated classifiers are in the namespace, i.e. are part of
 83  
      * the same model or subsystem.<p>
 84  
      *
 85  
      * @param  dm    the {@link java.lang.Object Object} to be checked against
 86  
      *               the critic.
 87  
      *
 88  
      * @param  dsgr  the {@link org.argouml.cognitive.Designer Designer}
 89  
      *               creating the model. Not used, this is for future
 90  
      *               development of ArgoUML.
 91  
      *
 92  
      * @return       {@link #PROBLEM_FOUND PROBLEM_FOUND} if the critic is
 93  
      *               triggered, otherwise {@link #NO_PROBLEM NO_PROBLEM}.
 94  
      */
 95  
     public boolean predicate2(Object dm, Designer dsgr) {
 96  
         // Only look at associations
 97  0
         if (!Model.getFacade().isAAssociation(dm)) {
 98  0
             return NO_PROBLEM;
 99  
         }
 100  
 
 101  0
         Object ns = Model.getFacade().getNamespace(dm);
 102  0
         if (ns == null) {
 103  0
             return PROBLEM_FOUND;
 104  
         }
 105  
 
 106  
         // Get the Association and its connections.
 107  
         // Iterate over all the AssociationEnds and check that each connected
 108  
         // classifier is in the same sub-system or model
 109  0
         Iterator assocEnds = Model.getFacade().getConnections(dm).iterator();
 110  0
         while (assocEnds.hasNext()) {
 111  
             // The next AssociationEnd, and its classifier. Check the
 112  
             // classifier is in the namespace of the association. If not we
 113  
             // have a problem.
 114  0
             Object clf = Model.getFacade().getType(assocEnds.next());
 115  0
             if (clf != null && ns != Model.getFacade().getNamespace(clf)) {
 116  0
                 return PROBLEM_FOUND;
 117  
             }
 118  0
         }
 119  
         // If we drop out there is no problem
 120  0
         return NO_PROBLEM;
 121  
     }
 122  
     
 123  
     /*
 124  
      * @see org.argouml.uml.cognitive.critics.CrUML#getCriticizedDesignMaterials()
 125  
      */
 126  
     public Set<Object> getCriticizedDesignMaterials() {
 127  900
         Set<Object> ret = new HashSet<Object>();
 128  900
         ret.add(Model.getMetaTypes().getAssociationClass());
 129  900
         return ret;
 130  
     }
 131  
     
 132  
 } /* end class CrCrossNamespaceAssoc */