Coverage Report - org.argouml.notation.providers.uml.ExtensionPointNotationUml
 
Classes in this File Line Coverage Branch Coverage Complexity
ExtensionPointNotationUml
0%
0/52
0%
0/25
3.571
 
 1  
 /* $Id: ExtensionPointNotationUml.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.util.StringTokenizer;
 42  
 
 43  
 import org.argouml.kernel.ProjectManager;
 44  
 import org.argouml.model.Model;
 45  
 import org.argouml.notation.NotationSettings;
 46  
 import org.argouml.notation.providers.ExtensionPointNotation;
 47  
 
 48  
 /**
 49  
  * The notation for an extension point for UML.
 50  
  * 
 51  
  * @author michiel
 52  
  */
 53  
 public class ExtensionPointNotationUml extends ExtensionPointNotation {
 54  
 
 55  
     /**
 56  
      * The constructor.
 57  
      *
 58  
      * @param ep the represented Extension Point
 59  
      */
 60  
     public ExtensionPointNotationUml(Object ep) {
 61  0
         super(ep);
 62  0
     }
 63  
 
 64  
     /*
 65  
      * @see org.argouml.notation.providers.NotationProvider#parse(java.lang.Object, java.lang.String)
 66  
      */
 67  
     public void parse(Object modelElement, String text) {
 68  
         /* TODO: This try-catch will be needed 
 69  
          * once the code below is improved. */
 70  
 //        try {
 71  0
         parseExtensionPointFig(modelElement, text);
 72  
 //        } catch (ParseException pe) {
 73  
 //            String msg = "statusmsg.bar.error.parsing.extensionpoint";
 74  
 //            Object[] args = {
 75  
 //                pe.getLocalizedMessage(),
 76  
 //                Integer.valueOf(pe.getErrorOffset()),
 77  
 //            };
 78  
 //            ProjectBrowser.getInstance().getStatusBar().showStatus(
 79  
 //                    Translator.messageFormat(msg, args));
 80  
 //        }
 81  0
     }
 82  
     /**
 83  
      * Parse an extension point.<p>
 84  
      *
 85  
      * The syntax is "name: location", "name:", "location" or "". The fields of
 86  
      * the extension point are updated appropriately.
 87  
      *
 88  
      * @param ep      The extension point concerned
 89  
      * @param text    The text to parse
 90  
      */
 91  
     public void parseExtensionPointFig(Object ep, String text) {
 92  
         // We can do nothing if we don't have both the use case and extension
 93  
         // point.
 94  0
         if (ep == null) {
 95  0
             return;
 96  
         }
 97  0
         Object useCase = Model.getFacade().getUseCase(ep);
 98  0
         if (useCase == null) {
 99  0
             return;
 100  
         }
 101  
 
 102  
         // Parse the string to creat a new extension point.
 103  0
         Object newEp = parseExtensionPoint(text);
 104  
 
 105  
         // If we got back null we interpret this as meaning delete the
 106  
         // reference to the extension point from the use case, otherwise we set
 107  
         // the fields of the extension point to the values in newEp.
 108  0
         if (newEp == null) {
 109  0
             ProjectManager.getManager().getCurrentProject().moveToTrash(ep);
 110  
         } else {
 111  0
             Model.getCoreHelper().setName(ep, Model.getFacade().getName(newEp));
 112  0
             Model.getUseCasesHelper().setLocation(ep,
 113  
                     Model.getFacade().getLocation(newEp));
 114  
         }
 115  
         /* TODO: This needs more work! 
 116  
          * We simply throw the new extension point away? */
 117  0
     }
 118  
 
 119  
     /**
 120  
      * Parse a string representing an extension point and return a new extension
 121  
      * point.<p>
 122  
      *
 123  
      * The syntax is "name: location", "name:", "location" or "".
 124  
      * <em>Note:</em> If either field is blank, it will be set to null
 125  
      * in the extension point.
 126  
      *
 127  
      * We break up the string into tokens at the ":". We must keep the ":" as a
 128  
      * token, so we can distinguish between "name:" and "location". The number
 129  
      * of tokens will distinguish our four cases.<p>
 130  
      *
 131  
      * @param text The string to parse
 132  
      *
 133  
      * @return A new extension point, with fields set appropriately, or
 134  
      *         <code>null</code> if we are given <code>null</code> or a
 135  
      *         blank string. <em>Note</em>. The string ":" can be used to set
 136  
      *         both name and location to null.
 137  
      */
 138  
     private Object parseExtensionPoint(String text) {
 139  
 
 140  
         // If we are given the null string, return immediately, 
 141  
         // so that the extensionpoint is removed.
 142  0
         if (text == null) {
 143  0
             return null;
 144  
         }
 145  
 
 146  
         // Build a new extension point
 147  
 
 148  
         // This method has insufficient information to call buildExtensionPoint.
 149  
         // Thus we'll need to create one, and pray that whomever called us knows
 150  
         // what kind of mess they got.
 151  0
         Object ep =
 152  
             Model.getUseCasesFactory().createExtensionPoint();
 153  
 
 154  0
         StringTokenizer st = new StringTokenizer(text.trim(), ":", true);
 155  0
         int numTokens = st.countTokens();
 156  
 
 157  
         String epLocation;
 158  
         String epName;
 159  
 
 160  0
         switch (numTokens) {
 161  
 
 162  
         case 0:
 163  
 
 164  
             // The empty string. Return null
 165  0
             ep = null;
 166  
 
 167  0
             break;
 168  
 
 169  
         case 1:
 170  
 
 171  
             // A string of the form "location". This will be confused by the
 172  
             // string ":", so we pick this out as an instruction to clear both
 173  
             // name and location.
 174  0
             epLocation = st.nextToken().trim();
 175  
 
 176  0
             if (epLocation.equals(":")) {
 177  0
                 Model.getCoreHelper().setName(ep, null);
 178  0
                 Model.getUseCasesHelper().setLocation(ep, null);
 179  
             } else {
 180  0
                 Model.getCoreHelper().setName(ep, null);
 181  0
                 Model.getUseCasesHelper().setLocation(ep, epLocation);
 182  
             }
 183  
 
 184  0
             break;
 185  
 
 186  
         case 2:
 187  
 
 188  
             // A string of the form "name:"
 189  0
             epName = st.nextToken().trim();
 190  
 
 191  0
             Model.getCoreHelper().setName(ep, epName);
 192  0
             Model.getUseCasesHelper().setLocation(ep, null);
 193  
 
 194  0
             break;
 195  
 
 196  
         case 3:
 197  
 
 198  
             // A string of the form "name:location". Discard the middle token
 199  
             // (":")
 200  0
             epName = st.nextToken().trim();
 201  0
             st.nextToken(); // Read past the colon.
 202  0
             epLocation = st.nextToken().trim();
 203  
 
 204  0
             Model.getCoreHelper().setName(ep, epName);
 205  0
             Model.getUseCasesHelper().setLocation(ep, epLocation);
 206  
 
 207  
             break;
 208  
         }
 209  
 
 210  0
         return ep;
 211  
     }
 212  
 
 213  
     /*
 214  
      * @see org.argouml.notation.providers.NotationProvider#getParsingHelp()
 215  
      */
 216  
     public String getParsingHelp() {
 217  0
         return "parsing.help.fig-extensionpoint";
 218  
     }
 219  
 
 220  
     private String toString(final Object modelElement) {
 221  
 
 222  0
         if (modelElement == null) {
 223  0
             return "";
 224  
         }
 225  
 
 226  
         // The string to build
 227  0
         String s = "";
 228  
 
 229  
         // Get the fields we want
 230  0
         String epName = Model.getFacade().getName(modelElement);
 231  0
         String epLocation = Model.getFacade().getLocation(modelElement);
 232  
 
 233  
         // Put in the name field if it's there
 234  0
         if ((epName != null) && (epName.length() > 0)) {
 235  0
             s += epName + ": ";
 236  
         }
 237  
 
 238  
         // Put in the location field if it's there
 239  0
         if ((epLocation != null) && (epLocation.length() > 0)) {
 240  0
             s += epLocation;
 241  
         }
 242  
 
 243  0
         return s;
 244  
     }
 245  
 
 246  
     /**
 247  
      * Generate the text for an extension point.<p>
 248  
      *
 249  
      * The representation is "name: location". 
 250  
      * The "name: " is omitted if there
 251  
      * is no name given.
 252  
      */
 253  
     @Override
 254  
     public String toString(Object modelElement, NotationSettings settings) {
 255  0
         return toString(modelElement);
 256  
     }
 257  
 
 258  
 }