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.Iterator; |
42 | |
|
43 | |
import javax.jmi.reflect.InvalidObjectException; |
44 | |
|
45 | |
import org.argouml.model.DataTypesHelper; |
46 | |
import org.argouml.model.InvalidElementException; |
47 | |
import org.omg.uml.foundation.datatypes.Expression; |
48 | |
import org.omg.uml.foundation.datatypes.Multiplicity; |
49 | |
import org.omg.uml.foundation.datatypes.MultiplicityRange; |
50 | |
import org.omg.uml.foundation.datatypes.PseudostateKind; |
51 | |
import org.omg.uml.foundation.datatypes.PseudostateKindEnum; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
class DataTypesHelperMDRImpl implements DataTypesHelper { |
61 | |
|
62 | |
private MDRModelImplementation modelImpl; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | 900 | public DataTypesHelperMDRImpl(MDRModelImplementation implementation) { |
69 | 900 | modelImpl = implementation; |
70 | 900 | } |
71 | |
|
72 | |
|
73 | |
public boolean equalsINITIALKind(Object kind) { |
74 | 0 | if (!(kind instanceof PseudostateKind)) { |
75 | 0 | throw new IllegalArgumentException(); |
76 | |
} |
77 | |
try { |
78 | 0 | return PseudostateKindEnum.PK_INITIAL.equals(kind); |
79 | 0 | } catch (InvalidObjectException e) { |
80 | 0 | throw new InvalidElementException(e); |
81 | |
} |
82 | |
} |
83 | |
|
84 | |
|
85 | |
public boolean equalsDeepHistoryKind(Object kind) { |
86 | 0 | if (!(kind instanceof PseudostateKind)) { |
87 | 0 | throw new IllegalArgumentException(); |
88 | |
} |
89 | |
try { |
90 | 0 | return PseudostateKindEnum.PK_DEEP_HISTORY.equals(kind); |
91 | 0 | } catch (InvalidObjectException e) { |
92 | 0 | throw new InvalidElementException(e); |
93 | |
} |
94 | |
} |
95 | |
|
96 | |
|
97 | |
public boolean equalsShallowHistoryKind(Object kind) { |
98 | 0 | if (!(kind instanceof PseudostateKind)) { |
99 | 0 | throw new IllegalArgumentException(); |
100 | |
} |
101 | |
try { |
102 | 0 | return PseudostateKindEnum.PK_SHALLOW_HISTORY.equals(kind); |
103 | 0 | } catch (InvalidObjectException e) { |
104 | 0 | throw new InvalidElementException(e); |
105 | |
} |
106 | |
} |
107 | |
|
108 | |
|
109 | |
public boolean equalsFORKKind(Object kind) { |
110 | 0 | if (!(kind instanceof PseudostateKind)) { |
111 | 0 | throw new IllegalArgumentException(); |
112 | |
} |
113 | |
try { |
114 | 0 | return PseudostateKindEnum.PK_FORK.equals(kind); |
115 | 0 | } catch (InvalidObjectException e) { |
116 | 0 | throw new InvalidElementException(e); |
117 | |
} |
118 | |
} |
119 | |
|
120 | |
|
121 | |
public boolean equalsJOINKind(Object kind) { |
122 | 0 | if (!(kind instanceof PseudostateKind)) { |
123 | 0 | throw new IllegalArgumentException(); |
124 | |
} |
125 | |
try { |
126 | 0 | return PseudostateKindEnum.PK_JOIN.equals(kind); |
127 | 0 | } catch (InvalidObjectException e) { |
128 | 0 | throw new InvalidElementException(e); |
129 | |
} |
130 | |
} |
131 | |
|
132 | |
|
133 | |
public boolean equalsCHOICEKind(Object kind) { |
134 | 0 | if (!(kind instanceof PseudostateKind)) { |
135 | 0 | throw new IllegalArgumentException(); |
136 | |
} |
137 | |
try { |
138 | 0 | return PseudostateKindEnum.PK_CHOICE.equals(kind); |
139 | 0 | } catch (InvalidObjectException e) { |
140 | 0 | throw new InvalidElementException(e); |
141 | |
} |
142 | |
} |
143 | |
|
144 | |
|
145 | |
public boolean equalsJUNCTIONKind(Object kind) { |
146 | 0 | if (!(kind instanceof PseudostateKind)) { |
147 | 0 | throw new IllegalArgumentException(); |
148 | |
} |
149 | |
try { |
150 | 0 | return PseudostateKindEnum.PK_JUNCTION.equals(kind); |
151 | 0 | } catch (InvalidObjectException e) { |
152 | 0 | throw new InvalidElementException(e); |
153 | |
} |
154 | |
} |
155 | |
|
156 | |
|
157 | |
public String multiplicityToString(Object multiplicity) { |
158 | 0 | if (!(multiplicity instanceof Multiplicity)) { |
159 | 0 | throw new IllegalArgumentException("Unrecognized object: " |
160 | |
+ multiplicity); |
161 | |
} |
162 | |
try { |
163 | 0 | String rc = ""; |
164 | 0 | Iterator i = ((Multiplicity) multiplicity).getRange().iterator(); |
165 | 0 | boolean first = true; |
166 | 0 | while (i.hasNext()) { |
167 | 0 | if (first) { |
168 | 0 | first = false; |
169 | |
} else { |
170 | 0 | rc += ","; |
171 | |
} |
172 | 0 | rc += multiplicityRangeToString((MultiplicityRange) i.next()); |
173 | |
} |
174 | 0 | return rc; |
175 | 0 | } catch (InvalidObjectException e) { |
176 | 0 | throw new InvalidElementException(e); |
177 | |
} |
178 | |
} |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
private String multiplicityRangeToString(MultiplicityRange range) { |
185 | 0 | if (range.getLower() == range.getUpper()) { |
186 | 0 | return DataTypesFactoryMDRImpl.boundToString(range.getLower()); |
187 | |
} else { |
188 | 0 | return DataTypesFactoryMDRImpl.boundToString( |
189 | |
range.getLower()) |
190 | |
+ ".." |
191 | |
+ DataTypesFactoryMDRImpl.boundToString(range.getUpper()); |
192 | |
} |
193 | |
} |
194 | |
|
195 | |
|
196 | |
public Object setBody(Object handle, String body) { |
197 | 0 | if (handle instanceof Expression) { |
198 | 0 | ((Expression) handle).setBody(body); |
199 | 0 | return handle; |
200 | |
} |
201 | 0 | throw new IllegalArgumentException("handle: " + handle + " body:" |
202 | |
+ body); |
203 | |
} |
204 | |
|
205 | |
|
206 | |
public String getBody(Object handle) { |
207 | |
try { |
208 | 0 | if (handle instanceof Expression) { |
209 | 0 | return ((Expression) handle).getBody(); |
210 | |
} |
211 | 0 | } catch (InvalidObjectException e) { |
212 | 0 | throw new InvalidElementException(e); |
213 | 0 | } |
214 | 0 | throw new IllegalArgumentException("handle: " + handle); |
215 | |
} |
216 | |
|
217 | |
|
218 | |
public Object setLanguage(Object handle, String language) { |
219 | 0 | if (handle instanceof Expression) { |
220 | 0 | ((Expression) handle).setLanguage(language); |
221 | 0 | return handle; |
222 | |
} |
223 | 0 | throw new IllegalArgumentException("handle: " + handle + " language: " |
224 | |
+ language); |
225 | |
} |
226 | |
|
227 | |
|
228 | |
public String getLanguage(Object handle) { |
229 | |
try { |
230 | 0 | if (handle instanceof Expression) { |
231 | 0 | return ((Expression) handle).getLanguage(); |
232 | |
} |
233 | 0 | } catch (InvalidObjectException e) { |
234 | 0 | throw new InvalidElementException(e); |
235 | 0 | } |
236 | 0 | throw new IllegalArgumentException("handle: " + handle); |
237 | |
} |
238 | |
|
239 | |
} |