Coverage Report - org.argouml.model.mdr.DataTypesHelperMDRImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DataTypesHelperMDRImpl
4%
3/74
0%
0/30
5.286
 
 1  
 /* $Id: DataTypesHelperMDRImpl.java 17765 2010-01-11 21:20:14Z 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  
  *    tfmorris
 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.model.mdr;
 40  
 
 41  
 import java.util.Iterator;
 42  
 
 43  
 import javax.jmi.reflect.InvalidObjectException;
 44  
 
 45  
 import org.argouml.model.DataTypesHelper;
 46  
 import org.argouml.model.InvalidElementException;
 47  
 import org.omg.uml.foundation.datatypes.Expression;
 48  
 import org.omg.uml.foundation.datatypes.Multiplicity;
 49  
 import org.omg.uml.foundation.datatypes.MultiplicityRange;
 50  
 import org.omg.uml.foundation.datatypes.PseudostateKind;
 51  
 import org.omg.uml.foundation.datatypes.PseudostateKindEnum;
 52  
 
 53  
 /**
 54  
  * DataTypesHelper for the MDR ModelImplementation
 55  
  * <p>
 56  
  * @since ARGO0.19.5
 57  
  * @author Ludovic Ma&icirc;tre
 58  
  * @author Tom Morris
 59  
  */
 60  
 class DataTypesHelperMDRImpl implements DataTypesHelper {
 61  
 
 62  
     private MDRModelImplementation modelImpl;
 63  
         
 64  
     /**
 65  
      * Default constructor
 66  
      * @param implementation the ModelImplementatin
 67  
      */
 68  900
     public DataTypesHelperMDRImpl(MDRModelImplementation implementation) {
 69  900
         modelImpl = implementation;
 70  900
     }
 71  
 
 72  
     
 73  
     public boolean equalsINITIALKind(Object kind) {
 74  0
         if (!(kind instanceof PseudostateKind)) {
 75  0
             throw new IllegalArgumentException();
 76  
         }
 77  
         try {
 78  0
             return PseudostateKindEnum.PK_INITIAL.equals(kind);
 79  0
         } catch (InvalidObjectException e) {
 80  0
             throw new InvalidElementException(e);
 81  
         }
 82  
     }
 83  
 
 84  
 
 85  
     public boolean equalsDeepHistoryKind(Object kind) {
 86  0
         if (!(kind instanceof PseudostateKind)) {
 87  0
             throw new IllegalArgumentException();
 88  
         }
 89  
         try {
 90  0
             return PseudostateKindEnum.PK_DEEP_HISTORY.equals(kind);
 91  0
         } catch (InvalidObjectException e) {
 92  0
             throw new InvalidElementException(e);
 93  
         }
 94  
     }
 95  
 
 96  
 
 97  
     public boolean equalsShallowHistoryKind(Object kind) {
 98  0
         if (!(kind instanceof PseudostateKind)) {
 99  0
             throw new IllegalArgumentException();
 100  
         }
 101  
         try {
 102  0
             return PseudostateKindEnum.PK_SHALLOW_HISTORY.equals(kind);
 103  0
         } catch (InvalidObjectException e) {
 104  0
             throw new InvalidElementException(e);
 105  
         }
 106  
     }
 107  
 
 108  
 
 109  
     public boolean equalsFORKKind(Object kind) {
 110  0
         if (!(kind instanceof PseudostateKind)) {
 111  0
             throw new IllegalArgumentException();
 112  
         }
 113  
         try {
 114  0
             return PseudostateKindEnum.PK_FORK.equals(kind);
 115  0
         } catch (InvalidObjectException e) {
 116  0
             throw new InvalidElementException(e);
 117  
         }
 118  
     }
 119  
 
 120  
 
 121  
     public boolean equalsJOINKind(Object kind) {
 122  0
         if (!(kind instanceof PseudostateKind)) {
 123  0
             throw new IllegalArgumentException();
 124  
         }
 125  
         try {
 126  0
             return PseudostateKindEnum.PK_JOIN.equals(kind);
 127  0
         } catch (InvalidObjectException e) {
 128  0
             throw new InvalidElementException(e);
 129  
         }
 130  
     }
 131  
 
 132  
 
 133  
     public boolean equalsCHOICEKind(Object kind) {
 134  0
         if (!(kind instanceof PseudostateKind)) {
 135  0
             throw new IllegalArgumentException();
 136  
         }
 137  
         try {
 138  0
             return PseudostateKindEnum.PK_CHOICE.equals(kind);
 139  0
         } catch (InvalidObjectException e) {
 140  0
             throw new InvalidElementException(e);
 141  
         }
 142  
     }
 143  
 
 144  
 
 145  
     public boolean equalsJUNCTIONKind(Object kind) {
 146  0
         if (!(kind instanceof PseudostateKind)) {
 147  0
             throw new IllegalArgumentException();
 148  
         }
 149  
         try {
 150  0
             return PseudostateKindEnum.PK_JUNCTION.equals(kind);
 151  0
         } catch (InvalidObjectException e) {
 152  0
             throw new InvalidElementException(e);
 153  
         }
 154  
     }
 155  
 
 156  
 
 157  
     public String multiplicityToString(Object multiplicity) {
 158  0
         if (!(multiplicity instanceof Multiplicity)) {
 159  0
             throw new IllegalArgumentException("Unrecognized object: "
 160  
                     + multiplicity);
 161  
         }
 162  
         try {
 163  0
             String rc = "";
 164  0
             Iterator i = ((Multiplicity) multiplicity).getRange().iterator();
 165  0
             boolean first = true;
 166  0
             while (i.hasNext()) {
 167  0
                 if (first) {
 168  0
                     first = false;
 169  
                 } else {
 170  0
                     rc += ",";
 171  
                 }
 172  0
                 rc += multiplicityRangeToString((MultiplicityRange) i.next());
 173  
             }
 174  0
             return rc;
 175  0
         } catch (InvalidObjectException e) {
 176  0
             throw new InvalidElementException(e);
 177  
         }
 178  
     }
 179  
 
 180  
     /**
 181  
      * @param range multiplicity range to convert
 182  
      * @return string representing multiplicity range
 183  
      */
 184  
     private String multiplicityRangeToString(MultiplicityRange range) {
 185  0
         if (range.getLower() == range.getUpper()) {
 186  0
             return DataTypesFactoryMDRImpl.boundToString(range.getLower());
 187  
         } else {
 188  0
             return DataTypesFactoryMDRImpl.boundToString(
 189  
                     range.getLower())
 190  
                     + ".."
 191  
                     + DataTypesFactoryMDRImpl.boundToString(range.getUpper());
 192  
         }
 193  
     }
 194  
 
 195  
 
 196  
     public Object setBody(Object handle, String body) {
 197  0
         if (handle instanceof Expression) {
 198  0
             ((Expression) handle).setBody(body);
 199  0
             return handle;
 200  
         }
 201  0
         throw new IllegalArgumentException("handle: " + handle + " body:"
 202  
                 + body);
 203  
     }
 204  
 
 205  
 
 206  
     public String getBody(Object handle) {
 207  
         try {
 208  0
             if (handle instanceof Expression) {
 209  0
                 return ((Expression) handle).getBody();
 210  
             }
 211  0
         } catch (InvalidObjectException e) {
 212  0
             throw new InvalidElementException(e);
 213  0
         }
 214  0
         throw new IllegalArgumentException("handle: " + handle);
 215  
     }
 216  
 
 217  
 
 218  
     public Object setLanguage(Object handle, String language) {
 219  0
         if (handle instanceof Expression) {
 220  0
             ((Expression) handle).setLanguage(language);
 221  0
             return handle;
 222  
         }
 223  0
         throw new IllegalArgumentException("handle: " + handle + " language: "
 224  
                 + language);
 225  
     }
 226  
 
 227  
 
 228  
     public String getLanguage(Object handle) {
 229  
         try {
 230  0
             if (handle instanceof Expression) {
 231  0
                 return ((Expression) handle).getLanguage();
 232  
             }
 233  0
         } catch (InvalidObjectException e) {
 234  0
             throw new InvalidElementException(e);
 235  0
         }
 236  0
         throw new IllegalArgumentException("handle: " + handle);
 237  
     }
 238  
         
 239  
 }