1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package org.argouml.model.mdr; |
40 | |
|
41 | |
import java.util.ArrayList; |
42 | |
import java.util.Collections; |
43 | |
import java.util.List; |
44 | |
import java.util.StringTokenizer; |
45 | |
|
46 | |
import org.apache.log4j.Logger; |
47 | |
import org.argouml.model.DataTypesFactory; |
48 | |
import org.omg.uml.foundation.datatypes.ActionExpression; |
49 | |
import org.omg.uml.foundation.datatypes.ArgListsExpression; |
50 | |
import org.omg.uml.foundation.datatypes.BooleanExpression; |
51 | |
import org.omg.uml.foundation.datatypes.Expression; |
52 | |
import org.omg.uml.foundation.datatypes.IterationExpression; |
53 | |
import org.omg.uml.foundation.datatypes.MappingExpression; |
54 | |
import org.omg.uml.foundation.datatypes.Multiplicity; |
55 | |
import org.omg.uml.foundation.datatypes.MultiplicityRange; |
56 | |
import org.omg.uml.foundation.datatypes.ObjectSetExpression; |
57 | |
import org.omg.uml.foundation.datatypes.ProcedureExpression; |
58 | |
import org.omg.uml.foundation.datatypes.TimeExpression; |
59 | |
import org.omg.uml.foundation.datatypes.TypeExpression; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 0 | class DataTypesFactoryMDRImpl extends AbstractUmlModelFactoryMDR |
71 | |
implements DataTypesFactory { |
72 | |
|
73 | 900 | private static final Logger LOG = |
74 | |
Logger.getLogger(DataTypesFactoryMDRImpl.class); |
75 | |
|
76 | |
|
77 | |
|
78 | |
private MDRModelImplementation modelImpl; |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | 900 | DataTypesFactoryMDRImpl(MDRModelImplementation implementation) { |
87 | 900 | this.modelImpl = implementation; |
88 | 900 | } |
89 | |
|
90 | |
|
91 | |
public ActionExpression createActionExpression(String language, String body) { |
92 | 0 | ActionExpression myActionExpression = modelImpl.getUmlPackage() |
93 | |
.getDataTypes().getActionExpression() |
94 | |
.createActionExpression(language, body); |
95 | 0 | super.initialize(myActionExpression); |
96 | 0 | return myActionExpression; |
97 | |
} |
98 | |
|
99 | |
|
100 | |
public ArgListsExpression createArgListsExpression(String language, String body) { |
101 | 0 | ArgListsExpression myArgListsExpression = modelImpl.getUmlPackage() |
102 | |
.getDataTypes().getArgListsExpression() |
103 | |
.createArgListsExpression(language, body); |
104 | 0 | super.initialize(myArgListsExpression); |
105 | 0 | return myArgListsExpression; |
106 | |
} |
107 | |
|
108 | |
|
109 | |
public BooleanExpression createBooleanExpression(String language, String body) { |
110 | 0 | BooleanExpression myBooleanExpression = modelImpl.getUmlPackage() |
111 | |
.getDataTypes().getBooleanExpression() |
112 | |
.createBooleanExpression(language, body); |
113 | 0 | super.initialize(myBooleanExpression); |
114 | 0 | return myBooleanExpression; |
115 | |
} |
116 | |
|
117 | |
|
118 | |
public Expression createExpression(String language, String body) { |
119 | 0 | Expression myExpression = modelImpl.getUmlPackage().getDataTypes() |
120 | |
.getExpression().createExpression(language, body); |
121 | 0 | super.initialize(myExpression); |
122 | 0 | return myExpression; |
123 | |
} |
124 | |
|
125 | |
|
126 | |
public IterationExpression createIterationExpression(String language, String body) { |
127 | 0 | IterationExpression myIterationExpression = modelImpl.getUmlPackage() |
128 | |
.getDataTypes().getIterationExpression() |
129 | |
.createIterationExpression(language, body); |
130 | 0 | super.initialize(myIterationExpression); |
131 | 0 | return myIterationExpression; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
public MappingExpression createMappingExpression(String language, String body) { |
136 | 0 | MappingExpression myMappingExpression = modelImpl.getUmlPackage() |
137 | |
.getDataTypes().getMappingExpression().createMappingExpression( |
138 | |
language, body); |
139 | 0 | super.initialize(myMappingExpression); |
140 | 0 | return myMappingExpression; |
141 | |
} |
142 | |
|
143 | |
|
144 | |
public ObjectSetExpression createObjectSetExpression(String language, String body) { |
145 | 0 | ObjectSetExpression myObjectSetExpression = modelImpl.getUmlPackage() |
146 | |
.getDataTypes().getObjectSetExpression() |
147 | |
.createObjectSetExpression(language, body); |
148 | 0 | super.initialize(myObjectSetExpression); |
149 | 0 | return myObjectSetExpression; |
150 | |
} |
151 | |
|
152 | |
|
153 | |
public ProcedureExpression createProcedureExpression(String language, String body) { |
154 | 0 | ProcedureExpression myProcedureExpression = modelImpl.getUmlPackage() |
155 | |
.getDataTypes().getProcedureExpression() |
156 | |
.createProcedureExpression(language, body); |
157 | 0 | super.initialize(myProcedureExpression); |
158 | 0 | return myProcedureExpression; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
public TimeExpression createTimeExpression(String language, String body) { |
163 | 0 | TimeExpression myTimeExpression = modelImpl.getUmlPackage() |
164 | |
.getDataTypes().getTimeExpression() |
165 | |
.createTimeExpression(language, body); |
166 | 0 | super.initialize(myTimeExpression); |
167 | 0 | return myTimeExpression; |
168 | |
} |
169 | |
|
170 | |
|
171 | |
public TypeExpression createTypeExpression(String language, String body) { |
172 | 0 | TypeExpression myTypeExpression = modelImpl.getUmlPackage() |
173 | |
.getDataTypes().getTypeExpression() |
174 | |
.createTypeExpression(language, body); |
175 | 0 | super.initialize(myTypeExpression); |
176 | 0 | return myTypeExpression; |
177 | |
} |
178 | |
|
179 | |
|
180 | |
@Deprecated |
181 | |
public Multiplicity createMultiplicity(int lower, int upper) { |
182 | 0 | return createMultiplicityInternal(lower, upper); |
183 | |
} |
184 | |
|
185 | |
Multiplicity createMultiplicityInternal(int lower, int upper) { |
186 | 0 | Multiplicity multiplicity = modelImpl.getUmlPackage().getDataTypes() |
187 | |
.getMultiplicity().createMultiplicity(); |
188 | 0 | if (LOG.isDebugEnabled()) { |
189 | 0 | LOG.debug("Multiplicity created for range " + lower + ".." + upper); |
190 | |
} |
191 | 0 | multiplicity.getRange().add(createMultiplicityRange(lower, upper)); |
192 | 0 | super.initialize(multiplicity); |
193 | 0 | return multiplicity; |
194 | |
} |
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
@Deprecated |
204 | |
public Multiplicity createMultiplicity(final List range) { |
205 | 0 | return createMultiplicityInternal(range); |
206 | |
} |
207 | |
|
208 | |
Multiplicity createMultiplicityInternal(final List<MultiplicityRange> range) { |
209 | 0 | Multiplicity multiplicity = modelImpl.getUmlPackage().getDataTypes() |
210 | |
.getMultiplicity().createMultiplicity(); |
211 | 0 | if (LOG.isDebugEnabled()) { |
212 | 0 | LOG.debug("Multiplicity created for list " + range); |
213 | |
} |
214 | 0 | multiplicity.getRange().addAll(range); |
215 | 0 | super.initialize(multiplicity); |
216 | 0 | return multiplicity; |
217 | |
} |
218 | |
|
219 | |
@Deprecated |
220 | |
public Multiplicity createMultiplicity(final String str) { |
221 | 0 | return createMultiplicityInternal(str); |
222 | |
} |
223 | |
|
224 | |
Multiplicity createMultiplicityInternal(final String str) { |
225 | 0 | List<MultiplicityRange> ranges = |
226 | |
Collections.unmodifiableList(parseRanges(str)); |
227 | 0 | return createMultiplicity(ranges); |
228 | |
} |
229 | |
|
230 | |
private List<MultiplicityRange> parseRanges(String str) { |
231 | 0 | List<MultiplicityRange> rc = new ArrayList<MultiplicityRange>(); |
232 | |
|
233 | 0 | if ("".equals(str)) { |
234 | 0 | rc.add(createMultiplicityRange("1..1")); |
235 | 0 | return rc; |
236 | |
} |
237 | 0 | StringTokenizer stk = new StringTokenizer(str, ","); |
238 | 0 | while (stk.hasMoreTokens()) { |
239 | 0 | rc.add(createMultiplicityRange(stk.nextToken())); |
240 | |
} |
241 | 0 | if (rc.size() > 1) { |
242 | 0 | LOG.debug("UML 2.x does not support multiple multiplicity ranges. " |
243 | |
+ str); |
244 | |
} |
245 | 0 | return rc; |
246 | |
} |
247 | |
|
248 | |
|
249 | |
@Deprecated |
250 | |
public MultiplicityRange createMultiplicityRange(String str) { |
251 | 0 | StringTokenizer stk = new StringTokenizer(str, ". "); |
252 | 0 | if (!stk.hasMoreTokens()) { |
253 | 0 | throw new IllegalArgumentException("empty multiplicity range"); |
254 | |
} |
255 | 0 | int lower = stringToBound(stk.nextToken()); |
256 | 0 | int upper = 0; |
257 | 0 | if (!stk.hasMoreTokens()) { |
258 | 0 | upper = lower; |
259 | |
|
260 | 0 | if (lower == -1) { |
261 | 0 | lower = 0; |
262 | |
} |
263 | |
} else { |
264 | 0 | upper = stringToBound(stk.nextToken()); |
265 | 0 | if (stk.hasMoreTokens()) { |
266 | 0 | throw new IllegalArgumentException( |
267 | |
"illegal range specification"); |
268 | |
} |
269 | |
} |
270 | 0 | return createMultiplicityRange(lower, upper); |
271 | |
} |
272 | |
|
273 | |
|
274 | |
@Deprecated |
275 | |
public MultiplicityRange createMultiplicityRange(final int lower, |
276 | |
final int upper) { |
277 | 0 | MultiplicityRange range = |
278 | |
modelImpl.getUmlPackage().getDataTypes().getMultiplicityRange() |
279 | |
.createMultiplicityRange(lower, upper); |
280 | 0 | return range; |
281 | |
} |
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
static String boundToString(int i) { |
290 | 0 | if (i == -1) { |
291 | 0 | return "*"; |
292 | |
} else { |
293 | 0 | return "" + i; |
294 | |
} |
295 | |
} |
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
private static int stringToBound(String b) { |
304 | |
try { |
305 | 0 | if (b.equals("n") || b.equals("*")) { |
306 | 0 | return -1; |
307 | |
} else { |
308 | 0 | return Integer.parseInt(b); |
309 | |
} |
310 | 0 | } catch (Exception ex) { |
311 | 0 | throw new IllegalArgumentException("illegal range bound : " |
312 | |
+ (b == null ? "null" : b)); |
313 | |
} |
314 | |
} |
315 | |
} |