Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ObjectFlowStateTypeNotationUml |
|
| 3.3333333333333335;3.333 |
1 | /* $Id: ObjectFlowStateTypeNotationUml.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.ObjectFlowStateTypeNotation; | |
50 | ||
51 | /** | |
52 | * @author Michiel | |
53 | */ | |
54 | public class ObjectFlowStateTypeNotationUml | |
55 | extends ObjectFlowStateTypeNotation { | |
56 | ||
57 | /** | |
58 | * The constructor. | |
59 | * | |
60 | * @param objectflowstate the ObjectFlowState represented by this notation | |
61 | */ | |
62 | public ObjectFlowStateTypeNotationUml(Object objectflowstate) { | |
63 | 0 | super(objectflowstate); |
64 | 0 | } |
65 | ||
66 | /* | |
67 | * @see org.argouml.notation.providers.NotationProvider#parse(java.lang.Object, java.lang.String) | |
68 | */ | |
69 | public void parse(Object modelElement, String text) { | |
70 | try { | |
71 | 0 | parseObjectFlowState1(modelElement, text); |
72 | 0 | } catch (ParseException pe) { |
73 | 0 | String msg = "statusmsg.bar.error.parsing.objectflowstate"; |
74 | 0 | Object[] args = { |
75 | pe.getLocalizedMessage(), | |
76 | Integer.valueOf(pe.getErrorOffset()), | |
77 | }; | |
78 | 0 | ArgoEventPump.fireEvent(new ArgoHelpEvent( |
79 | ArgoEventTypes.HELP_CHANGED, this, | |
80 | Translator.messageFormat(msg, args))); | |
81 | 0 | } |
82 | 0 | } |
83 | ||
84 | /** | |
85 | * Do the actual parsing. <p> | |
86 | * | |
87 | * This method does create a Class | |
88 | * if a Classifier with the given name is not encountered. | |
89 | * See for explanation issue 4382. | |
90 | * | |
91 | * @param objectFlowState the given element to be altered | |
92 | * @param s the new string | |
93 | * @return the altered ObjectFlowState | |
94 | * @throws ParseException when the given text was rejected | |
95 | */ | |
96 | protected Object parseObjectFlowState1(Object objectFlowState, String s) | |
97 | throws ParseException { | |
98 | 0 | Object c = |
99 | Model.getActivityGraphsHelper() | |
100 | .findClassifierByName(objectFlowState, s); | |
101 | 0 | if (c != null) { |
102 | /* Great! The class already existed - just use it. */ | |
103 | 0 | Model.getCoreHelper().setType(objectFlowState, c); |
104 | 0 | return objectFlowState; |
105 | } | |
106 | /* Let's create a class with the given name, otherwise | |
107 | * the user will not understand why we refuse his input! */ | |
108 | 0 | if (s != null && s.length() > 0) { |
109 | 0 | Object topState = Model.getFacade().getContainer(objectFlowState); |
110 | 0 | if (topState != null) { |
111 | 0 | Object machine = Model.getFacade().getStateMachine(topState); |
112 | 0 | if (machine != null) { |
113 | 0 | Object ns = Model.getFacade().getNamespace(machine); |
114 | 0 | if (ns != null) { |
115 | 0 | Object clazz = Model.getCoreFactory().buildClass(s, ns); |
116 | 0 | Model.getCoreHelper().setType(objectFlowState, clazz); |
117 | 0 | return objectFlowState; |
118 | } | |
119 | } | |
120 | } | |
121 | } | |
122 | 0 | String msg = "parsing.error.object-flow-type.classifier-not-found"; |
123 | 0 | Object[] args = {s}; |
124 | 0 | throw new ParseException(Translator.localize(msg, args), 0); |
125 | } | |
126 | ||
127 | /* | |
128 | * @see org.argouml.notation.providers.NotationProvider#getParsingHelp() | |
129 | */ | |
130 | public String getParsingHelp() { | |
131 | 0 | return "parsing.help.fig-objectflowstate1"; |
132 | } | |
133 | ||
134 | private String toString(Object modelElement) { | |
135 | 0 | Object classifier = Model.getFacade().getType(modelElement); |
136 | 0 | if (Model.getFacade().isAClassifierInState(classifier)) { |
137 | 0 | classifier = Model.getFacade().getType(classifier); |
138 | } | |
139 | 0 | if (classifier == null) { |
140 | 0 | return ""; |
141 | } | |
142 | 0 | String name = Model.getFacade().getName(classifier); |
143 | 0 | if (name == null) { |
144 | 0 | name = ""; |
145 | } | |
146 | 0 | return name; |
147 | } | |
148 | ||
149 | @Override | |
150 | public String toString(Object modelElement, NotationSettings settings) { | |
151 | 0 | return toString(modelElement); |
152 | } | |
153 | ||
154 | } |