Coverage Report - com.sdmetrics.metrics.SDMetricsException - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
SDMetricsException
100%
15/15
100%
4/4
1,4
 
 1  
 /*
 2  
  * SDMetrics Open Core for UML design measurement
 3  
  * Copyright (c) Juergen Wuest
 4  
  * To contact the author, see <http://www.sdmetrics.com/Contact.html>.
 5  
  * 
 6  
  * This file is part of the SDMetrics Open Core.
 7  
  * 
 8  
  * SDMetrics Open Core is free software: you can redistribute it and/or modify
 9  
  * it under the terms of the GNU Affero General Public License as
 10  
  * published by the Free Software Foundation, either version 3 of the
 11  
  * License, or (at your option) any later version.
 12  
     
 13  
  * SDMetrics Open Core is distributed in the hope that it will be useful,
 14  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16  
  * GNU Affero General Public License for more details.
 17  
  *
 18  
  * You should have received a copy of the GNU Affero General Public License
 19  
  * along with SDMetrics Open Core.  If not, see <http://www.gnu.org/licenses/>.
 20  
  *
 21  
  */
 22  
 package com.sdmetrics.metrics;
 23  
 
 24  
 import com.sdmetrics.model.ModelElement;
 25  
 
 26  
 /**
 27  
  * Exception to deal with problems that can occur during metrics calculation.
 28  
  * <p>
 29  
  * If this exception is thrown, it is always due to a bug in the metric
 30  
  * definition file (typos, a required attribute is missing, an unknown metric is
 31  
  * requested etc.) The only way to fix the problem is then to edit the metric
 32  
  * definition file.
 33  
  * <p>
 34  
  * For a correct metric definition file, this exception will never be thrown. So
 35  
  * unless users write their own metric definitions (and invariably make mistakes
 36  
  * in the process), they should never experience any such errors during
 37  
  * calculation.
 38  
  */
 39  
 
 40  
 public class SDMetricsException extends RuntimeException {
 41  
         private static final long serialVersionUID = 6113288972487051364L;
 42  
 
 43  
         /** Model element for which the calculation failed. */
 44  
         private ModelElement element;
 45  
         /** Metric, set, matrix or rule for which the calculation failed. */
 46  
         private MetricEntry entry;
 47  
 
 48  
         /**
 49  
          * Constructor with message.
 50  
          * 
 51  
          * @param element The model element that caused the problem.
 52  
          * @param entry The metric/set/rule that caused the problem.
 53  
          * @param message A message describing the problem.
 54  
          */
 55  
         public SDMetricsException(ModelElement element, MetricEntry entry,
 56  
                         String message) {
 57  49
                 super(message);
 58  49
                 this.element = element;
 59  49
                 this.entry = entry;
 60  49
         }
 61  
 
 62  
         /**
 63  
          * Constructor with an exception to be chained.
 64  
          * 
 65  
          * @param element The model element that caused the problem.
 66  
          * @param entry The metric/set/rule that caused the problem.
 67  
          * @param cause The exception causing the problem.
 68  
          */
 69  
         public SDMetricsException(ModelElement element, MetricEntry entry,
 70  
                         Exception cause) {
 71  4
                 super("Internal metrics engine failure: " + cause.getMessage(), cause);
 72  4
                 this.element = element;
 73  4
                 this.entry = entry;
 74  4
         }
 75  
 
 76  
         /**
 77  
          * Gets the model element that caused the problem.
 78  
          * 
 79  
          * @return Model element that caused the problem.
 80  
          */
 81  
         public ModelElement getElement() {
 82  10
                 return element;
 83  
         }
 84  
 
 85  
         /**
 86  
          * Gets the metric, set, rule, or matrix that caused the problem.
 87  
          * 
 88  
          * @return Metric entry that caused the problem.
 89  
          */
 90  
         public MetricEntry getMetricEntry() {
 91  10
                 return entry;
 92  
         }
 93  
 
 94  
         /**
 95  
          * Sets the model element and/or metric entry that caused the problem, if
 96  
          * not already set. Problems can arise in places where the model element or
 97  
          * metric is not known. The metrics engine then adds this information later.
 98  
          * 
 99  
          * @param elem The model element that caused the problem.
 100  
          * @param culprit The metric/set/rule that caused the problem.
 101  
          */
 102  
         void fillInPerpetrators(ModelElement elem, MetricEntry culprit) {
 103  7
                 if (element == null)
 104  3
                         element = elem;
 105  7
                 if (entry == null)
 106  4
                         entry = culprit;
 107  7
         }
 108  
 }