Coverage Report - com.sdmetrics.model.XMITrigger - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
XMITrigger
100%
19/19
100%
8/8
3,667
XMITrigger$TriggerType
100%
23/23
N/A
3,667
 
 1  3295
 /*
 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.model;
 23  
 
 24  
 import java.util.Locale;
 25  
 
 26  
 /** Stores information for one trigger of an XMITransformation. */
 27  
 class XMITrigger {
 28  
 
 29  
         /** Enumerates the types of triggers. */
 30  39
         static enum TriggerType {
 31  39
                 /** Trigger "constant". */
 32  39
                 CONSTANT(true, false),
 33  39
                 /** Trigger "attrval". */
 34  39
                 ATTRVAL(true, false),
 35  39
                 /** Trigger "cattrval". */
 36  39
                 CATTRVAL(true, true),
 37  39
                 /** Trigger "ctext". */
 38  39
                 CTEXT(false, true),
 39  39
                 /** Trigger "gcattrval". */
 40  39
                 GCATTRVAL(true, true),
 41  39
                 /** Trigger "ignore". */
 42  39
                 IGNORE(false, false),
 43  39
                 /** Trigger "xmi2assoc". */
 44  39
                 XMI2ASSOC(true, false),
 45  39
                 /** Deprecated trigger "reflist". */
 46  39
                 REFLIST(true, true);
 47  
 
 48  
                 /** Indicates if the trigger require the "attr" attribute to be set. */
 49  
                 final boolean requiresAttr;
 50  
                 /** Indicates if the trigger require the "src" attribute to be set. */
 51  
                 final boolean requiresSrc;
 52  
 
 53  312
                 private TriggerType(boolean requiresAttr, boolean requiresSrc) {
 54  312
                         this.requiresAttr = requiresAttr;
 55  312
                         this.requiresSrc = requiresSrc;
 56  312
                 }
 57  
 
 58  
                 /**
 59  
                  * Sets trigger names to lower case for output.
 60  
                  */
 61  
                 @Override
 62  
                 public String toString() {
 63  3247
                         return name().toLowerCase(Locale.ENGLISH);
 64  
                 }
 65  
 
 66  
         }
 67  
 
 68  
         /** Value of the name attribute of this trigger. */
 69  
         String name;
 70  
 
 71  
         /** The type of trigger (attrval, ctext, ...) */
 72  
         TriggerType type;
 73  
 
 74  
         /** The XMI element that holds the information for this trigger. */
 75  
         String src;
 76  
 
 77  
         /** The relevant attribute of the XMI element that holds the information. */
 78  
         String attr;
 79  
 
 80  
         /** Name of an attribute storing back links to a referencing element. */
 81  
         String linkback;
 82  
 
 83  
         /**
 84  
          * Create a new trigger.
 85  
          * 
 86  
          * @param attributeName The name of the metamodel element attribute for
 87  
          *        which this trigger is defined.
 88  
          * @param triggerType The type of trigger.
 89  
          * @param srcElement The XMI element that holds the information for this
 90  
          *        trigger.
 91  
          * @param srcAttribute The relevant attribute of the XMI element that holds
 92  
          *        the information.
 93  
          * @param linkBackAttribute For cross-reference attributes: the link back
 94  
          *        attribute.
 95  
          * @throws IllegalArgumentException Unknown trigger kind or required
 96  
          *         attributes were missing.
 97  
          */
 98  3256
         XMITrigger(String attributeName, String triggerType, String srcElement,
 99  
                         String srcAttribute, String linkBackAttribute) {
 100  3256
                 name = attributeName;
 101  3256
                 src = srcElement;
 102  3256
                 attr = srcAttribute;
 103  3256
                 linkback = linkBackAttribute;
 104  
 
 105  3256
                 type = null;
 106  
                 try {
 107  3256
                         type = TriggerType.valueOf(triggerType.toUpperCase(Locale.ENGLISH));
 108  3255
                 } catch (IllegalArgumentException ex) {
 109  2
                         throw new IllegalArgumentException("Unknown trigger type '"
 110  1
                                         + triggerType + "'.");
 111  
                 }
 112  
 
 113  3255
                 if (type.requiresAttr && srcAttribute == null)
 114  8
                         throw new IllegalArgumentException(
 115  8
                                         "Attribute 'attr' must be specified for triggers of type '"
 116  4
                                                         + triggerType + "'.");
 117  
 
 118  3251
                 if (type.requiresSrc && srcElement == null)
 119  8
                         throw new IllegalArgumentException(
 120  8
                                         "Attribute 'src' must be specified for triggers of type '"
 121  4
                                                         + triggerType + "'.");
 122  3247
         }
 123  
 }