Coverage Report - org.argouml.model.euml.DataTypesHelperEUMLImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DataTypesHelperEUMLImpl
0%
0/52
0%
0/28
2.692
 
 1  
 // $Id: DataTypesHelperEUMLImpl.java 18433 2010-06-05 13:51:45Z thn $
 2  
 /*******************************************************************************
 3  
  * Copyright (c) 2007,2010 Tom Morris and other contributors
 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  
  *    Tom Morris - initial implementation
 11  
  *    Thomas Neustupny
 12  
  *******************************************************************************/
 13  
 package org.argouml.model.euml;
 14  
 
 15  
 import java.util.List;
 16  
 
 17  
 import org.argouml.model.DataTypesHelper;
 18  
 import org.eclipse.emf.common.util.EList;
 19  
 import org.eclipse.uml2.uml.MultiplicityElement;
 20  
 import org.eclipse.uml2.uml.OpaqueBehavior;
 21  
 import org.eclipse.uml2.uml.OpaqueExpression;
 22  
 import org.eclipse.uml2.uml.PseudostateKind;
 23  
 
 24  
 /**
 25  
  * The implementation of the DataTypesHelper for EUML2.
 26  
  */
 27  
 class DataTypesHelperEUMLImpl implements DataTypesHelper {
 28  
 
 29  
     /**
 30  
      * The model implementation.
 31  
      */
 32  
     private EUMLModelImplementation modelImpl;
 33  
 
 34  
     /**
 35  
      * Constructor.
 36  
      *
 37  
      * @param implementation The ModelImplementation.
 38  
      */
 39  0
     public DataTypesHelperEUMLImpl(EUMLModelImplementation implementation) {
 40  0
         modelImpl = implementation;
 41  0
     }
 42  
 
 43  
     public boolean equalsCHOICEKind(Object kind) {
 44  0
         return PseudostateKind.CHOICE_LITERAL.equals(kind);
 45  
     }
 46  
 
 47  
     public boolean equalsDeepHistoryKind(Object kind) {
 48  0
         return PseudostateKind.DEEP_HISTORY_LITERAL.equals(kind);
 49  
     }
 50  
 
 51  
     public boolean equalsFORKKind(Object kind) {
 52  0
         return PseudostateKind.FORK_LITERAL.equals(kind);
 53  
     }
 54  
 
 55  
     public boolean equalsINITIALKind(Object kind) {
 56  0
         return PseudostateKind.INITIAL_LITERAL.equals(kind);
 57  
     }
 58  
 
 59  
     public boolean equalsJOINKind(Object kind) {
 60  0
         return PseudostateKind.JOIN_LITERAL.equals(kind);
 61  
     }
 62  
 
 63  
     public boolean equalsJUNCTIONKind(Object kind) {
 64  0
         return PseudostateKind.JUNCTION_LITERAL.equals(kind);
 65  
     }
 66  
 
 67  
     public boolean equalsShallowHistoryKind(Object kind) {
 68  0
         return PseudostateKind.SHALLOW_HISTORY_LITERAL.equals(kind);
 69  
     }
 70  
 
 71  
     public String getBody(Object handle) {
 72  0
         EList<String> bodies = null;
 73  0
         if (handle instanceof OpaqueExpression) {
 74  0
             bodies = ((OpaqueExpression) handle).getBodies();
 75  0
         } else if (handle instanceof OpaqueBehavior) {
 76  0
             bodies = ((OpaqueBehavior) handle).getBodies();
 77  
         } else {
 78  0
             throw new IllegalArgumentException(
 79  
                     "handle must be instance of OpaqueExpression or OpaqueBehavior"); //$NON-NLS-1$
 80  
         }
 81  0
         return (bodies.size() < 1) ? null : bodies.get(0);
 82  
     }
 83  
 
 84  
     public String getLanguage(Object handle) {
 85  0
         EList<String> langs = null;
 86  0
         if (handle instanceof OpaqueExpression) {
 87  0
             langs = ((OpaqueExpression) handle).getLanguages();
 88  0
         } else if (handle instanceof OpaqueBehavior) {
 89  0
             langs = ((OpaqueBehavior) handle).getLanguages();
 90  
         } else {
 91  0
             throw new IllegalArgumentException(
 92  
                     "handle must be instance of OpaqueExpression or OpaqueBehavior"); //$NON-NLS-1$
 93  
         }
 94  0
         return (langs.size() < 1) ? null : langs.get(0);
 95  
     }
 96  
 
 97  
     public String multiplicityToString(Object multiplicity) {
 98  0
         if (!(multiplicity instanceof MultiplicityElement)) {
 99  0
             throw new IllegalArgumentException(
 100  
                     "multiplicity must be instance of MultiplicityElement"); //$NON-NLS-1$
 101  
         }
 102  0
         MultiplicityElement mult = (MultiplicityElement) multiplicity;
 103  0
         if (mult.getLower() == mult.getUpper()) {
 104  0
             return DataTypesFactoryEUMLImpl.boundToString(mult.getLower());
 105  
         } else {
 106  0
             return DataTypesFactoryEUMLImpl.boundToString(
 107  
                     mult.getLower())
 108  
                     + ".." //$NON-NLS-1$
 109  
                     + DataTypesFactoryEUMLImpl.boundToString(mult.getUpper());
 110  
         }
 111  
     }
 112  
     
 113  
     public Object setBody(Object handle, String body) {
 114  0
         List<String> bodies = null;
 115  0
         if (handle instanceof OpaqueExpression) {
 116  0
             bodies = ((OpaqueExpression) handle).getBodies();
 117  0
         } else if (handle instanceof OpaqueBehavior) {
 118  0
             bodies = ((OpaqueBehavior) handle).getBodies();
 119  
         } else {
 120  0
             throw new IllegalArgumentException(
 121  
                     "handle must be instance of OpaqueExpression or OpaqueBehavior"); //$NON-NLS-1$
 122  
         }
 123  
         // TODO: Support more than one body/language
 124  0
         if (bodies.size() > 1) {
 125  0
             throw new IllegalStateException("Only one body/lang supported"); //$NON-NLS-1$
 126  
         }
 127  0
         bodies.clear();
 128  0
         bodies.add(body);
 129  0
         return handle;
 130  
     }
 131  
 
 132  
     public Object setLanguage(Object handle, String language) {
 133  0
         List<String> langs = null;
 134  0
         if (handle instanceof OpaqueExpression) {
 135  0
             langs = ((OpaqueExpression) handle).getLanguages();
 136  0
         } else if (handle instanceof OpaqueBehavior) {
 137  0
             langs = ((OpaqueBehavior) handle).getLanguages();
 138  
         } else {
 139  0
             throw new IllegalArgumentException(
 140  
                     "handle must be instance of OpaqueExpression or OpaqueBehavior"); //$NON-NLS-1$
 141  
         }
 142  
         // TODO: Support more than one body/language
 143  0
         if (langs.size() > 1) {
 144  0
             throw new IllegalStateException("Only one body/lang supported"); //$NON-NLS-1$
 145  
         }
 146  0
         langs.clear(); 
 147  0
         langs.add(language);
 148  0
         return handle;
 149  
     }
 150  
 
 151  
 }