Coverage Report - org.argouml.notation.providers.uml.AssociationNameNotationUml
 
Classes in this File Line Coverage Branch Coverage Complexity
AssociationNameNotationUml
0%
0/25
0%
0/10
2.4
 
 1  
 /* $Id: AssociationNameNotationUml.java 17828 2010-01-12 18:55:12Z 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  
  *    mvw
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2006-2009 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.notation.providers.uml;
 40  
 
 41  
 import java.text.ParseException;
 42  
 
 43  
 import org.argouml.application.events.ArgoEventPump;
 44  
 import org.argouml.application.events.ArgoEventTypes;
 45  
 import org.argouml.application.events.ArgoHelpEvent;
 46  
 import org.argouml.i18n.Translator;
 47  
 import org.argouml.model.Model;
 48  
 import org.argouml.notation.NotationSettings;
 49  
 import org.argouml.notation.providers.AssociationNameNotation;
 50  
 
 51  
 /**
 52  
  * Handles the notation of the name of an association modelelement in UML,
 53  
  * ie a string on the format:<pre>
 54  
  *     [ &lt;&lt; stereotype &gt;&gt;] [+|-|#|~] [name]
 55  
  * </pre>
 56  
  *
 57  
  * @author Michiel
 58  
  */
 59  
 public class AssociationNameNotationUml extends AssociationNameNotation {
 60  
 
 61  
     /**
 62  
      * The constructor.
 63  
      *
 64  
      * @param association the association modelelement
 65  
      * that we represent in textual form.
 66  
      */
 67  
     public AssociationNameNotationUml(Object association) {
 68  0
         super(association);
 69  0
     }
 70  
 
 71  
     /*
 72  
      * @see org.argouml.notation.providers.NotationProvider#getParsingHelp()
 73  
      */
 74  
     public String getParsingHelp() {
 75  0
         return "parsing.help.fig-association-name";
 76  
     }
 77  
 
 78  
     /*
 79  
      * @see org.argouml.notation.providers.NotationProvider#parse(java.lang.Object, java.lang.String)
 80  
      */
 81  
     public void parse(Object modelElement, String text) {
 82  
         try {
 83  0
             NotationUtilityUml.parseModelElement(modelElement, text);
 84  0
         } catch (ParseException pe) {
 85  0
             String msg = "statusmsg.bar.error.parsing.association-name";
 86  0
             Object[] args = {
 87  
                 pe.getLocalizedMessage(),
 88  
                 Integer.valueOf(pe.getErrorOffset()),
 89  
             };
 90  0
             ArgoEventPump.fireEvent(new ArgoHelpEvent(
 91  
                     ArgoEventTypes.HELP_CHANGED, this,
 92  
                 Translator.messageFormat(msg, args)));
 93  0
         }
 94  0
     }
 95  
 
 96  
     /*
 97  
      * @see org.argouml.notation.providers.NotationProvider#toString(java.lang.Object, java.util.Map)
 98  
      */
 99  
     public String toString(Object modelElement, NotationSettings settings) {
 100  0
         return toString(modelElement, settings.isShowAssociationNames(),
 101  
                 settings.isFullyHandleStereotypes(),
 102  
                 settings.isShowPaths(),
 103  
                 settings.isShowVisibilities(),
 104  
                 settings.isUseGuillemets());
 105  
     }
 106  
 
 107  
     private String toString(Object modelElement, Boolean showAssociationName,
 108  
             boolean fullyHandleStereotypes, boolean showPath, 
 109  
             boolean showVisibility, boolean useGuillemets) {
 110  
 
 111  0
         if (showAssociationName == Boolean.FALSE) {
 112  0
             return "";
 113  
         }
 114  
 
 115  0
         String name = Model.getFacade().getName(modelElement);
 116  0
         StringBuffer sb = new StringBuffer("");
 117  0
         if (fullyHandleStereotypes) {
 118  0
             sb.append(NotationUtilityUml.generateStereotype(modelElement, 
 119  
                     useGuillemets));
 120  
         }
 121  0
         if (showVisibility) {
 122  0
             sb.append(NotationUtilityUml.generateVisibility2(modelElement));
 123  0
             sb.append(" ");
 124  
         }
 125  0
         if (showPath) {
 126  0
             sb.append(NotationUtilityUml.generatePath(modelElement));
 127  
         }
 128  0
         if (name != null) {
 129  0
             sb.append(name);
 130  
         }
 131  0
         return sb.toString();
 132  
     }
 133  
 
 134  
 }