Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
NodeInstanceNotationUml |
|
| 3.6;3.6 |
1 | /* $Id: NodeInstanceNotationUml.java 18852 2010-11-20 19:27:11Z mvw $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009-2010 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 | * Michiel van der Wulp | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 2005-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.ArrayList; | |
42 | import java.util.List; | |
43 | import java.util.StringTokenizer; | |
44 | ||
45 | import org.argouml.model.Model; | |
46 | import org.argouml.notation.NotationSettings; | |
47 | import org.argouml.notation.providers.NodeInstanceNotation; | |
48 | ||
49 | /** | |
50 | * Notation for a NodeInstance. | |
51 | * | |
52 | * @author Michiel van der Wulp | |
53 | */ | |
54 | public class NodeInstanceNotationUml extends NodeInstanceNotation { | |
55 | ||
56 | /** | |
57 | * The constructor. | |
58 | * | |
59 | * @param nodeInstance the UML nodeInstance | |
60 | */ | |
61 | public NodeInstanceNotationUml(Object nodeInstance) { | |
62 | 0 | super(nodeInstance); |
63 | 0 | } |
64 | ||
65 | /** | |
66 | * Parse a line of the form: "name : base-node". | |
67 | * <p> | |
68 | * The base-node part is a comma separated list of Nodes. <p> | |
69 | * | |
70 | * Note that stereotypes are not supported. | |
71 | * | |
72 | * {@inheritDoc} | |
73 | */ | |
74 | public void parse(Object modelElement, String text) { | |
75 | // strip any trailing semi-colons | |
76 | 0 | String s = text.trim(); |
77 | 0 | if (s.length() == 0) { |
78 | 0 | return; |
79 | } | |
80 | 0 | if (s.charAt(s.length() - 1) == ';') { |
81 | 0 | s = s.substring(0, s.length() - 2); |
82 | } | |
83 | ||
84 | 0 | String name = ""; |
85 | 0 | String bases = ""; |
86 | 0 | StringTokenizer tokenizer = null; |
87 | ||
88 | 0 | if (s.indexOf(":", 0) > -1) { |
89 | 0 | name = s.substring(0, s.indexOf(":")).trim(); |
90 | 0 | bases = s.substring(s.indexOf(":") + 1).trim(); |
91 | } else { | |
92 | 0 | name = s; |
93 | } | |
94 | ||
95 | 0 | tokenizer = new StringTokenizer(bases, ","); |
96 | ||
97 | 0 | List<Object> classifiers = new ArrayList<Object>(); |
98 | 0 | Object ns = Model.getFacade().getNamespace(modelElement); |
99 | 0 | if (ns != null) { |
100 | 0 | while (tokenizer.hasMoreElements()) { |
101 | 0 | String newBase = tokenizer.nextToken(); |
102 | 0 | Object cls = Model.getFacade().lookupIn(ns, newBase.trim()); |
103 | 0 | if (cls != null) { |
104 | 0 | classifiers.add(cls); |
105 | } | |
106 | 0 | } |
107 | } | |
108 | ||
109 | 0 | Model.getCommonBehaviorHelper().setClassifiers(modelElement, |
110 | classifiers); | |
111 | 0 | Model.getCoreHelper().setName(modelElement, name); |
112 | 0 | } |
113 | ||
114 | /* | |
115 | * @see org.argouml.notation.providers.NotationProvider#getParsingHelp() | |
116 | */ | |
117 | public String getParsingHelp() { | |
118 | 0 | return "parsing.help.fig-nodeinstance"; |
119 | } | |
120 | ||
121 | private String toString(Object modelElement) { | |
122 | 0 | String nameStr = ""; |
123 | 0 | if (Model.getFacade().getName(modelElement) != null) { |
124 | 0 | nameStr = Model.getFacade().getName(modelElement).trim(); |
125 | } | |
126 | // construct bases string (comma separated) | |
127 | 0 | StringBuilder baseStr = NotationUtilityUml.formatNameList( |
128 | Model.getFacade().getClassifiers(modelElement)); | |
129 | ||
130 | 0 | if ((nameStr.length() == 0) && (baseStr.length() == 0)) { |
131 | 0 | return ""; |
132 | } | |
133 | 0 | String base = baseStr.toString().trim(); |
134 | 0 | if (base.length() < 1) { |
135 | 0 | return nameStr.trim(); |
136 | } | |
137 | 0 | return nameStr.trim() + " : " + base; |
138 | } | |
139 | ||
140 | @Override | |
141 | public String toString(Object modelElement, NotationSettings settings) { | |
142 | 0 | return toString(modelElement); |
143 | } | |
144 | ||
145 | } |