Coverage Report - org.argouml.uml.cognitive.critics.CrMultipleDeepHistoryStates
 
Classes in this File Line Coverage Branch Coverage Complexity
CrMultipleDeepHistoryStates
20%
10/50
0%
0/24
4
 
 1  
 /* $Id: CrMultipleDeepHistoryStates.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) 2003-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.Collection;
 42  
 import java.util.HashSet;
 43  
 import java.util.Iterator;
 44  
 import java.util.Set;
 45  
 
 46  
 import org.apache.log4j.Logger;
 47  
 import org.argouml.cognitive.Designer;
 48  
 import org.argouml.cognitive.ListSet;
 49  
 import org.argouml.cognitive.ToDoItem;
 50  
 import org.argouml.model.Model;
 51  
 import org.argouml.uml.cognitive.UMLDecision;
 52  
 import org.argouml.uml.cognitive.UMLToDoItem;
 53  
 
 54  
 /**
 55  
  * UML 1.5 Well-formedness rule [2] for Composite States.
 56  
  *
 57  
  * Well-formedness rule [2] for CompositeState. See page 136 of UML 1.4
 58  
  * Semantics. OMG document UML 1.4.2 formal/04-07-02.
 59  
  *
 60  
  * @author pepargouml@yahoo.es
 61  
  */
 62  
 public class CrMultipleDeepHistoryStates extends CrUML {
 63  
     /**
 64  
      * Logger.
 65  
      */
 66  900
     private static final Logger LOG =
 67  
             Logger.getLogger(CrMultipleDeepHistoryStates.class);
 68  
 
 69  
     /**
 70  
      * The constructor.
 71  
      */
 72  900
     public CrMultipleDeepHistoryStates() {
 73  900
         setupHeadAndDesc();
 74  900
         addSupportedDecision(UMLDecision.STATE_MACHINES);
 75  900
         addTrigger("parent");
 76  900
         addTrigger("kind");
 77  900
     }
 78  
 
 79  
     /*
 80  
      * @see org.argouml.uml.cognitive.critics.CrUML#predicate2(java.lang.Object,
 81  
      *      org.argouml.cognitive.Designer)
 82  
      */
 83  
     public boolean predicate2(Object dm, Designer dsgr) {
 84  0
         if (!(Model.getFacade().isAPseudostate(dm))) {
 85  0
             return NO_PROBLEM;
 86  
         }
 87  0
         Object k = Model.getFacade().getKind(dm);
 88  0
         if (!Model.getFacade().equalsPseudostateKind(k,
 89  
                 Model.getPseudostateKind().getDeepHistory())) {
 90  0
             return NO_PROBLEM;
 91  
         }
 92  
 
 93  
         // container state / composite state
 94  0
         Object cs = Model.getFacade().getContainer(dm);
 95  0
         if (cs == null) {
 96  0
             LOG.debug("null parent state");
 97  0
             return NO_PROBLEM;
 98  
         }
 99  0
         Collection peers = Model.getFacade().getSubvertices(cs);
 100  0
         int initialStateCount = 0;
 101  0
         for (Iterator iter = peers.iterator(); iter.hasNext();) {
 102  0
             Object sv = iter.next();
 103  0
             if (Model.getFacade().isAPseudostate(sv)
 104  
                     && Model.getFacade().equalsPseudostateKind(
 105  
                             Model.getFacade().getKind(sv),
 106  
                             Model.getPseudostateKind().getDeepHistory())) {
 107  0
                 initialStateCount++;
 108  
             }
 109  0
         }
 110  0
         if (initialStateCount > 1) {
 111  0
             return PROBLEM_FOUND;
 112  
         }
 113  0
         return NO_PROBLEM;
 114  
     }
 115  
 
 116  
     /*
 117  
      * @see org.argouml.cognitive.critics.Critic#toDoItem(java.lang.Object,
 118  
      *      org.argouml.cognitive.Designer)
 119  
      */
 120  
     public ToDoItem toDoItem(Object dm, Designer dsgr) {
 121  0
         ListSet offs = computeOffenders(dm);
 122  0
         return new UMLToDoItem(this, offs, dsgr);
 123  
     }
 124  
 
 125  
     /**
 126  
      * @param ps the design material
 127  
      * @return the offenders
 128  
      */
 129  
     protected ListSet computeOffenders(Object ps) {
 130  0
         ListSet offs = new ListSet(ps);
 131  0
         Object cs = Model.getFacade().getContainer(ps);
 132  0
         if (cs == null) {
 133  0
             LOG.debug("null parent in still valid");
 134  0
             return offs;
 135  
         }
 136  0
         Collection peers = Model.getFacade().getSubvertices(cs);
 137  0
         for (Iterator iter = peers.iterator(); iter.hasNext();) {
 138  0
             Object sv = iter.next();
 139  0
             if (Model.getFacade().isAPseudostate(sv)
 140  
                     && Model.getFacade().equalsPseudostateKind(
 141  
                             Model.getFacade().getKind(sv),
 142  
                             Model.getPseudostateKind().getDeepHistory())) {
 143  0
                 offs.add(sv);
 144  
             }
 145  0
         }
 146  0
         return offs;
 147  
     }
 148  
 
 149  
     /*
 150  
      * @see org.argouml.cognitive.Poster#stillValid(
 151  
      *      org.argouml.cognitive.ToDoItem, org.argouml.cognitive.Designer)
 152  
      */
 153  
     public boolean stillValid(ToDoItem i, Designer dsgr) {
 154  0
         if (!isActive()) {
 155  0
             return false;
 156  
         }
 157  0
         ListSet offs = i.getOffenders();
 158  0
         Object dm = offs.get(0);
 159  0
         ListSet newOffs = computeOffenders(dm);
 160  0
         boolean res = offs.equals(newOffs);
 161  0
         return res;
 162  
     }
 163  
 
 164  
     /*
 165  
      * @see org.argouml.uml.cognitive.critics.CrUML#getCriticizedDesignMaterials()
 166  
      */
 167  
     public Set<Object> getCriticizedDesignMaterials() {
 168  900
         Set<Object> ret = new HashSet<Object>();
 169  900
         ret.add(Model.getMetaTypes().getPseudostate());
 170  900
         return ret;
 171  
     }
 172  
     
 173  
     /**
 174  
      * The UID.
 175  
      */
 176  
     private static final long serialVersionUID = -4893102976661022514L;
 177  
 }
 178