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.persistence; |
40 | |
|
41 | |
import java.io.Reader; |
42 | |
import java.util.ArrayList; |
43 | |
import java.util.List; |
44 | |
|
45 | |
import org.apache.log4j.Logger; |
46 | |
import org.argouml.kernel.Project; |
47 | |
import org.argouml.kernel.ProjectSettings; |
48 | |
import org.argouml.notation.NotationSettings; |
49 | |
import org.argouml.uml.diagram.DiagramSettings; |
50 | |
import org.xml.sax.InputSource; |
51 | |
import org.xml.sax.SAXException; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
class ArgoParser extends SAXParserBase { |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | 0 | private static final Logger LOG = Logger.getLogger(ArgoParser.class); |
63 | |
|
64 | |
private Project project; |
65 | |
|
66 | |
private ProjectSettings ps; |
67 | |
|
68 | |
private DiagramSettings diagramDefaults; |
69 | |
|
70 | |
private NotationSettings notationSettings; |
71 | |
|
72 | 0 | private ArgoTokenTable tokens = new ArgoTokenTable(); |
73 | |
|
74 | 0 | private List<String> memberList = new ArrayList<String>(); |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public ArgoParser() { |
81 | 0 | super(); |
82 | 0 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public void readProject(Project theProject, InputSource source) |
90 | |
throws SAXException { |
91 | |
|
92 | 0 | if (source == null) { |
93 | 0 | throw new IllegalArgumentException( |
94 | |
"An InputSource must be supplied"); |
95 | |
} |
96 | |
|
97 | 0 | preRead(theProject); |
98 | |
|
99 | |
try { |
100 | 0 | parse(source); |
101 | 0 | } catch (SAXException e) { |
102 | 0 | logError(source.toString(), e); |
103 | 0 | throw e; |
104 | 0 | } |
105 | 0 | } |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public void readProject(Project theProject, Reader reader) |
113 | |
throws SAXException { |
114 | |
|
115 | 0 | if (reader == null) { |
116 | 0 | throw new IllegalArgumentException( |
117 | |
"A reader must be supplied"); |
118 | |
} |
119 | |
|
120 | 0 | preRead(theProject); |
121 | |
|
122 | |
try { |
123 | 0 | parse(reader); |
124 | 0 | } catch (SAXException e) { |
125 | 0 | logError(reader.toString(), e); |
126 | 0 | throw e; |
127 | 0 | } |
128 | 0 | } |
129 | |
|
130 | |
private void preRead(Project theProject) { |
131 | 0 | LOG.info("======================================="); |
132 | 0 | LOG.info("== READING PROJECT " + theProject); |
133 | 0 | project = theProject; |
134 | 0 | ps = project.getProjectSettings(); |
135 | 0 | diagramDefaults = ps.getDefaultDiagramSettings(); |
136 | 0 | notationSettings = ps.getNotationSettings(); |
137 | 0 | } |
138 | |
|
139 | |
private void logError(String projectName, SAXException e) { |
140 | 0 | LOG.error("Exception reading project================", e); |
141 | 0 | LOG.error(projectName); |
142 | 0 | } |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
public Project getProject() { |
149 | 0 | return project; |
150 | |
} |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
public void setProject(Project newProj) { |
157 | 0 | project = newProj; |
158 | 0 | ps = project.getProjectSettings(); |
159 | 0 | } |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
public void handleStartElement(XMLElement e) throws SAXException { |
166 | |
if (DBG) { |
167 | |
LOG.debug("NOTE: ArgoParser handleStartTag:" + e.getName()); |
168 | |
} |
169 | 0 | switch (tokens.toToken(e.getName(), true)) { |
170 | |
case ArgoTokenTable.TOKEN_ARGO: |
171 | 0 | handleArgo(e); |
172 | 0 | break; |
173 | |
case ArgoTokenTable.TOKEN_DOCUMENTATION: |
174 | 0 | handleDocumentation(e); |
175 | 0 | break; |
176 | |
case ArgoTokenTable.TOKEN_SETTINGS: |
177 | 0 | handleSettings(e); |
178 | 0 | break; |
179 | |
default: |
180 | |
if (DBG) { |
181 | |
LOG.warn("WARNING: unknown tag:" + e.getName()); |
182 | |
} |
183 | |
break; |
184 | |
} |
185 | 0 | } |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
@SuppressWarnings("deprecation") |
192 | |
public void handleEndElement(XMLElement e) throws SAXException { |
193 | |
if (DBG) { |
194 | |
LOG.debug("NOTE: ArgoParser handleEndTag:" + e.getName() + "."); |
195 | |
} |
196 | 0 | switch (tokens.toToken(e.getName(), false)) { |
197 | |
case ArgoTokenTable.TOKEN_MEMBER: |
198 | 0 | handleMember(e); |
199 | 0 | break; |
200 | |
case ArgoTokenTable.TOKEN_AUTHORNAME: |
201 | 0 | handleAuthorName(e); |
202 | 0 | break; |
203 | |
case ArgoTokenTable.TOKEN_AUTHOREMAIL: |
204 | 0 | handleAuthorEmail(e); |
205 | 0 | break; |
206 | |
case ArgoTokenTable.TOKEN_VERSION: |
207 | 0 | handleVersion(e); |
208 | 0 | break; |
209 | |
case ArgoTokenTable.TOKEN_DESCRIPTION: |
210 | 0 | handleDescription(e); |
211 | 0 | break; |
212 | |
case ArgoTokenTable.TOKEN_SEARCHPATH: |
213 | 0 | handleSearchpath(e); |
214 | 0 | break; |
215 | |
case ArgoTokenTable.TOKEN_HISTORYFILE: |
216 | 0 | handleHistoryfile(e); |
217 | 0 | break; |
218 | |
case ArgoTokenTable.TOKEN_NOTATIONLANGUAGE: |
219 | 0 | handleNotationLanguage(e); |
220 | 0 | break; |
221 | |
case ArgoTokenTable.TOKEN_SHOWBOLDNAMES: |
222 | 0 | handleShowBoldNames(e); |
223 | 0 | break; |
224 | |
case ArgoTokenTable.TOKEN_USEGUILLEMOTS: |
225 | 0 | handleUseGuillemots(e); |
226 | 0 | break; |
227 | |
case ArgoTokenTable.TOKEN_SHOWVISIBILITY: |
228 | 0 | handleShowVisibility(e); |
229 | 0 | break; |
230 | |
case ArgoTokenTable.TOKEN_SHOWMULTIPLICITY: |
231 | 0 | handleShowMultiplicity(e); |
232 | 0 | break; |
233 | |
case ArgoTokenTable.TOKEN_SHOWINITIALVALUE: |
234 | 0 | handleShowInitialValue(e); |
235 | 0 | break; |
236 | |
case ArgoTokenTable.TOKEN_SHOWPROPERTIES: |
237 | 0 | handleShowProperties(e); |
238 | 0 | break; |
239 | |
case ArgoTokenTable.TOKEN_SHOWTYPES: |
240 | 0 | handleShowTypes(e); |
241 | 0 | break; |
242 | |
case ArgoTokenTable.TOKEN_SHOWSTEREOTYPES: |
243 | 0 | handleShowStereotypes(e); |
244 | 0 | break; |
245 | |
case ArgoTokenTable.TOKEN_SHOWSINGULARMULTIPLICITIES: |
246 | 0 | handleShowSingularMultiplicities(e); |
247 | 0 | break; |
248 | |
case ArgoTokenTable.TOKEN_DEFAULTSHADOWWIDTH: |
249 | 0 | handleDefaultShadowWidth(e); |
250 | 0 | break; |
251 | |
case ArgoTokenTable.TOKEN_FONTNAME: |
252 | 0 | handleFontName(e); |
253 | 0 | break; |
254 | |
case ArgoTokenTable.TOKEN_FONTSIZE: |
255 | 0 | handleFontSize(e); |
256 | 0 | break; |
257 | |
case ArgoTokenTable.TOKEN_GENERATION_OUTPUT_DIR: |
258 | |
|
259 | 0 | break; |
260 | |
case ArgoTokenTable.TOKEN_SHOWASSOCIATIONNAMES: |
261 | 0 | handleShowAssociationNames(e); |
262 | 0 | break; |
263 | |
case ArgoTokenTable.TOKEN_HIDEBIDIRECTIONALARROWS: |
264 | 0 | handleHideBidirectionalArrows(e); |
265 | 0 | break; |
266 | |
case ArgoTokenTable.TOKEN_ACTIVE_DIAGRAM: |
267 | 0 | handleActiveDiagram(e); |
268 | 0 | break; |
269 | |
default: |
270 | |
if (DBG) { |
271 | |
LOG.warn("WARNING: unknown end tag:" + e.getName()); |
272 | |
} |
273 | |
break; |
274 | |
} |
275 | 0 | } |
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
@Override |
281 | |
protected boolean isElementOfInterest(String name) { |
282 | 0 | return tokens.contains(name); |
283 | |
} |
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
protected void handleArgo(@SuppressWarnings("unused") XMLElement e) { |
289 | |
|
290 | 0 | } |
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
protected void handleDocumentation( |
296 | |
@SuppressWarnings("unused") XMLElement e) { |
297 | |
|
298 | 0 | } |
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
protected void handleSettings(@SuppressWarnings("unused") XMLElement e) { |
304 | |
|
305 | 0 | } |
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
protected void handleAuthorName(XMLElement e) { |
311 | 0 | String authorname = e.getText().trim(); |
312 | 0 | project.setAuthorname(authorname); |
313 | 0 | } |
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
protected void handleAuthorEmail(XMLElement e) { |
319 | 0 | String authoremail = e.getText().trim(); |
320 | 0 | project.setAuthoremail(authoremail); |
321 | 0 | } |
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
protected void handleVersion(XMLElement e) { |
327 | 0 | String version = e.getText().trim(); |
328 | 0 | project.setVersion(version); |
329 | 0 | } |
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
protected void handleDescription(XMLElement e) { |
335 | 0 | String description = e.getText().trim(); |
336 | 0 | project.setDescription(description); |
337 | 0 | } |
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
protected void handleSearchpath(XMLElement e) { |
343 | 0 | String searchpath = e.getAttribute("href").trim(); |
344 | 0 | project.addSearchPath(searchpath); |
345 | 0 | } |
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
protected void handleMember(XMLElement e) throws SAXException { |
352 | 0 | if (e == null) { |
353 | 0 | throw new SAXException("XML element is null"); |
354 | |
} |
355 | 0 | String type = e.getAttribute("type"); |
356 | 0 | memberList.add(type); |
357 | 0 | } |
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
protected void handleHistoryfile(XMLElement e) { |
363 | 0 | if (e.getAttribute("name") == null) { |
364 | 0 | return; |
365 | |
} |
366 | 0 | String historyfile = e.getAttribute("name").trim(); |
367 | 0 | project.setHistoryFile(historyfile); |
368 | 0 | } |
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
protected void handleNotationLanguage(XMLElement e) { |
374 | 0 | String language = e.getText().trim(); |
375 | 0 | boolean success = ps.setNotationLanguage(language); |
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | 0 | } |
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
protected void handleShowBoldNames(XMLElement e) { |
387 | 0 | String ug = e.getText().trim(); |
388 | 0 | diagramDefaults.setShowBoldNames(Boolean.parseBoolean(ug)); |
389 | 0 | } |
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | |
protected void handleUseGuillemots(XMLElement e) { |
395 | 0 | String ug = e.getText().trim(); |
396 | 0 | ps.setUseGuillemots(ug); |
397 | 0 | } |
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
protected void handleShowVisibility(XMLElement e) { |
403 | 0 | String showVisibility = e.getText().trim(); |
404 | 0 | notationSettings.setShowVisibilities( |
405 | |
Boolean.parseBoolean(showVisibility)); |
406 | 0 | } |
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
protected void handleShowMultiplicity(XMLElement e) { |
412 | 0 | String showMultiplicity = e.getText().trim(); |
413 | 0 | notationSettings.setShowMultiplicities( |
414 | |
Boolean.parseBoolean(showMultiplicity)); |
415 | 0 | } |
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
protected void handleShowInitialValue(XMLElement e) { |
421 | 0 | String showInitialValue = e.getText().trim(); |
422 | 0 | notationSettings.setShowInitialValues( |
423 | |
Boolean.parseBoolean(showInitialValue)); |
424 | 0 | } |
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
protected void handleShowProperties(XMLElement e) { |
430 | 0 | String showproperties = e.getText().trim(); |
431 | 0 | notationSettings.setShowProperties( |
432 | |
Boolean.parseBoolean(showproperties)); |
433 | 0 | } |
434 | |
|
435 | |
|
436 | |
|
437 | |
|
438 | |
protected void handleShowTypes(XMLElement e) { |
439 | 0 | String showTypes = e.getText().trim(); |
440 | 0 | notationSettings.setShowTypes(Boolean.parseBoolean(showTypes)); |
441 | 0 | } |
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | |
protected void handleShowStereotypes(XMLElement e) { |
447 | 0 | String showStereotypes = e.getText().trim(); |
448 | 0 | ps.setShowStereotypes(Boolean.parseBoolean(showStereotypes)); |
449 | 0 | } |
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
protected void handleShowSingularMultiplicities(XMLElement e) { |
455 | 0 | String showSingularMultiplicities = e.getText().trim(); |
456 | 0 | notationSettings.setShowSingularMultiplicities( |
457 | |
Boolean.parseBoolean(showSingularMultiplicities)); |
458 | 0 | } |
459 | |
|
460 | |
|
461 | |
|
462 | |
|
463 | |
protected void handleDefaultShadowWidth(XMLElement e) { |
464 | 0 | String dsw = e.getText().trim(); |
465 | 0 | diagramDefaults.setDefaultShadowWidth(Integer.parseInt(dsw)); |
466 | 0 | } |
467 | |
|
468 | |
|
469 | |
|
470 | |
|
471 | |
protected void handleFontName(XMLElement e) { |
472 | 0 | String dsw = e.getText().trim(); |
473 | 0 | diagramDefaults.setFontName(dsw); |
474 | 0 | } |
475 | |
|
476 | |
|
477 | |
|
478 | |
|
479 | |
protected void handleFontSize(XMLElement e) { |
480 | 0 | String dsw = e.getText().trim(); |
481 | |
try { |
482 | 0 | diagramDefaults.setFontSize(Integer.parseInt(dsw)); |
483 | 0 | } catch (NumberFormatException e1) { |
484 | 0 | LOG.error("NumberFormatException while parsing Font Size", e1); |
485 | 0 | } |
486 | 0 | } |
487 | |
|
488 | |
|
489 | |
|
490 | |
|
491 | |
protected void handleShowAssociationNames(XMLElement e) { |
492 | 0 | String showAssociationNames = e.getText().trim(); |
493 | 0 | notationSettings.setShowAssociationNames( |
494 | |
Boolean.parseBoolean(showAssociationNames)); |
495 | 0 | } |
496 | |
|
497 | |
|
498 | |
|
499 | |
|
500 | |
protected void handleHideBidirectionalArrows(XMLElement e) { |
501 | 0 | String hideBidirectionalArrows = e.getText().trim(); |
502 | |
|
503 | |
|
504 | 0 | diagramDefaults.setShowBidirectionalArrows(! |
505 | |
Boolean.parseBoolean(hideBidirectionalArrows)); |
506 | 0 | } |
507 | |
|
508 | |
|
509 | |
protected void handleActiveDiagram(XMLElement e) { |
510 | |
|
511 | |
|
512 | 0 | project.setSavedDiagramName(e.getText().trim()); |
513 | 0 | } |
514 | |
|
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
public List<String> getMemberList() { |
520 | 0 | return memberList; |
521 | |
} |
522 | |
} |