1 package org.nuiton.eugene.models.object.reader.yaml;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import org.nuiton.eugene.models.object.xml.ObjectModeImplAssociationClassParticipant;
26 import org.nuiton.eugene.models.object.xml.ObjectModelAssociationClassImpl;
27 import org.nuiton.eugene.models.object.xml.ObjectModelAttributeImpl;
28 import org.nuiton.eugene.models.object.xml.ObjectModelClassImpl;
29 import org.nuiton.eugene.models.object.xml.ObjectModelClassifierImpl;
30 import org.nuiton.eugene.models.object.xml.ObjectModelElementImpl;
31 import org.nuiton.eugene.models.object.xml.ObjectModelEnumerationImpl;
32 import org.nuiton.eugene.models.object.xml.ObjectModelImpl;
33 import org.nuiton.eugene.models.object.xml.ObjectModelImplRef;
34 import org.nuiton.eugene.models.object.xml.ObjectModelImplSuperClassRef;
35 import org.nuiton.eugene.models.object.xml.ObjectModelInterfaceImpl;
36 import org.nuiton.eugene.models.object.xml.ObjectModelOperationImpl;
37 import org.nuiton.eugene.models.object.xml.ObjectModelParameterImpl;
38
39 import java.util.List;
40 import java.util.Map;
41
42
43
44
45
46
47 public class LoadObjectModel implements KeyWords {
48
49 protected String packageL;
50
51 protected YamlObject modelYAMLO;
52
53 protected ObjectModelImpl modelOM;
54
55 protected Map<String, String> defaultValues;
56
57 public LoadObjectModel(YamlObject modelYAMLO, ObjectModelImpl modelOM, Map<String, String> defaultValues) {
58 this.packageL = "default";
59 this.modelOM = modelOM;
60 this.modelYAMLO = modelYAMLO;
61 this.defaultValues = defaultValues;
62
63
64
65 }
66
67 public void loadModel() {
68 String packageYAMLO = modelYAMLO.getFirstMapStringListString(PACKAGE);
69 if (packageYAMLO == null) {
70 String key = PACKAGE;
71 if (defaultValues.containsKey(key)) {
72 packageL = defaultValues.get(key);
73 }
74 } else {
75 packageL = packageYAMLO;
76 }
77
78 modelOM.addTagValue(PACKAGE, packageL);
79
80 String nameYAMLO = modelYAMLO.getFirstMapStringListString(NAME);
81 if (nameYAMLO == null) {
82 String key = NAME;
83 if (defaultValues.containsKey(key)) {
84 modelOM.setName(defaultValues.get(key));
85 }
86 } else {
87 modelOM.setName(nameYAMLO);
88 }
89
90
91 String versionYAMLO = modelYAMLO.getFirstMapStringListString(VERSION);
92 if (versionYAMLO == null) {
93 String key = VERSION;
94 if (defaultValues.containsKey(key)) {
95 modelOM.setVersion(defaultValues.get(key));
96 }
97 } else {
98 modelOM.setVersion(versionYAMLO);
99 }
100
101
102 YamlObject tagValues = modelYAMLO.getFirstMapStringListYamlObject(TAG_VALUES);
103 if (tagValues != null) {
104 for (Map.Entry<String, List<String>> tagValue : tagValues.getMapStringListString().entrySet()) {
105 if (!tagValue.getValue().isEmpty())
106 {
107 modelOM.addTagValue(tagValue.getKey(), tagValue.getValue().get(0));
108 }
109 }
110 }
111
112
113 for (YamlObject classYAMLO : modelYAMLO.getMapStringListYamlObject(CLASS)) {
114 ObjectModelClassImpl classOM = new ObjectModelClassImpl();
115 loadClass(classYAMLO, classOM);
116 modelOM.addClass(classOM);
117 }
118
119 for (YamlObject interfaceYAMLO : modelYAMLO.getMapStringListYamlObject(INTERFACE)) {
120 ObjectModelInterfaceImpl interfaceOM = new ObjectModelInterfaceImpl();
121 loadInterface(interfaceYAMLO, interfaceOM);
122 modelOM.addInterface(interfaceOM);
123 }
124
125 for (YamlObject associationClassYAMLO : modelYAMLO.getMapStringListYamlObject(ASSOCIATION_CLASS)) {
126 ObjectModelAssociationClassImpl associationClassOM = new ObjectModelAssociationClassImpl();
127 loadAssociationClass(associationClassYAMLO, associationClassOM);
128 modelOM.addAssociationClass(associationClassOM);
129 }
130
131 for (YamlObject enumerationYAMLO : modelYAMLO.getMapStringListYamlObject(ENUMERATION)) {
132 ObjectModelEnumerationImpl enumerationOM = new ObjectModelEnumerationImpl();
133 loadEnumeration(enumerationYAMLO, enumerationOM);
134 modelOM.addEnumeration(enumerationOM);
135 }
136 }
137
138 public void loadElement(YamlObject elementYAMLO, ObjectModelElementImpl elementOM) {
139
140 String nameYAMLO = elementYAMLO.getFirstMapStringListString(NAME);
141 if (nameYAMLO == null) {
142 String key = ELEMENT + SEPARATOR + NAME;
143 if (defaultValues.containsKey(key)) {
144 elementOM.setName(defaultValues.get(key));
145 }
146 } else {
147 elementOM.setName(nameYAMLO);
148 }
149
150
151 String staticYAMLO = elementYAMLO.getFirstMapStringListString(STATIC);
152 if (staticYAMLO == null) {
153 String key = ELEMENT + SEPARATOR + STATIC;
154 if (defaultValues.containsKey(key)) {
155 elementOM.setStatic(Boolean.valueOf(defaultValues.get(key)));
156 }
157 } else {
158 elementOM.setStatic(Boolean.valueOf(staticYAMLO));
159 }
160
161
162 String documentationYAMLO = elementYAMLO.getFirstMapStringListString(DOCUMENTATION);
163 if (documentationYAMLO == null) {
164 String key = ELEMENT + SEPARATOR + DOCUMENTATION;
165 if (defaultValues.containsKey(key)) {
166 elementOM.setDocumentation(defaultValues.get(key));
167 }
168 } else {
169 elementOM.setDocumentation(documentationYAMLO);
170 }
171
172
173 YamlObject tagValues = elementYAMLO.getFirstMapStringListYamlObject(TAG_VALUES);
174 if (tagValues != null) {
175 for (Map.Entry<String, List<String>> tagValue : tagValues.getMapStringListString().entrySet()) {
176 if (!tagValue.getValue().isEmpty())
177 {
178 elementOM.addTagValue(tagValue.getKey(), tagValue.getValue().get(0));
179 }
180 }
181 }
182
183
184 List<String> comments = elementYAMLO.getMapStringListString(COMMENTS);
185 for (String comment : comments) {
186 elementOM.addComment(comment);
187 }
188
189
190 List<String> stereotypes = elementYAMLO.getMapStringListString(STEREOTYPES);
191 for (String stereotype : stereotypes) {
192 ObjectModelImplRef stereotypeOM = new ObjectModelImplRef();
193 stereotypeOM.setName(stereotype);
194 elementOM.addStereotype(stereotypeOM);
195 }
196 }
197
198 public void loadClassifier(YamlObject classifierYAMLO, ObjectModelClassifierImpl classifierOM) {
199 loadElement(classifierYAMLO, classifierOM);
200
201
202 String packageYAMLO = classifierYAMLO.getFirstMapStringListString(PACKAGE);
203 if (packageYAMLO == null) {
204 classifierOM.setPackage(packageL);
205 } else {
206 classifierOM.setPackage(packageYAMLO);
207 }
208
209
210 String externYAMLO = classifierYAMLO.getFirstMapStringListString(EXTERN);
211 if (externYAMLO == null) {
212 String key = CLASSIFIER + SEPARATOR + EXTERN;
213 if (defaultValues.containsKey(key)) {
214 classifierOM.setExtern(Boolean.valueOf(defaultValues.get(key)));
215 }
216 } else {
217 classifierOM.setExtern(Boolean.valueOf(externYAMLO));
218
219 }
220
221
222 String innerYAMLO = classifierYAMLO.getFirstMapStringListString(INNER);
223 if (innerYAMLO == null) {
224 String key = CLASSIFIER + SEPARATOR + INNER;
225 if (defaultValues.containsKey(key)) {
226 classifierOM.setInner(Boolean.valueOf(defaultValues.get(key)));
227 }
228 } else {
229 classifierOM.setInner(Boolean.valueOf(innerYAMLO));
230 }
231
232
233 String typeYAMLO = classifierYAMLO.getFirstMapStringListString(TYPE);
234 if (typeYAMLO == null) {
235 String key = CLASSIFIER + SEPARATOR + TYPE;
236 if (defaultValues.containsKey(key)) {
237 classifierOM.setType(defaultValues.get(key));
238 }
239 } else {
240 classifierOM.setType(typeYAMLO);
241 }
242
243
244 for (YamlObject attributeYAMLO : classifierYAMLO.getMapStringListYamlObject(ATTRIBUTE)) {
245 ObjectModelAttributeImpl attributeOM = new ObjectModelAttributeImpl();
246 loadAttribute(attributeYAMLO, attributeOM);
247 classifierOM.addAttribute(attributeOM);
248 }
249
250
251 for (YamlObject operationYAMLO : classifierYAMLO.getMapStringListYamlObject(OPERATION)) {
252 ObjectModelOperationImpl operationOM = new ObjectModelOperationImpl();
253 loadOperation(operationYAMLO, operationOM);
254 classifierOM.addOperation(operationOM);
255 }
256
257
258 List<String> superInterfacesYAMLO = classifierYAMLO.getMapStringListString(SUPER_INTERFACES);
259 for (String superInterfaceYAMLO : superInterfacesYAMLO) {
260 ObjectModelImplRef superInterfaceOM = new ObjectModelImplRef();
261 superInterfaceOM.setName(superInterfaceYAMLO);
262 classifierOM.addInterface(superInterfaceOM);
263 }
264 }
265
266 public void loadClass(YamlObject classYAMLO, ObjectModelClassImpl classOM) {
267 loadClassifier(classYAMLO, classOM);
268
269
270 String abstractYAMLO = classYAMLO.getFirstMapStringListString(ABSTRACT);
271 if (abstractYAMLO == null) {
272 String key = CLASS + SEPARATOR + ABSTRACT;
273 if (defaultValues.containsKey(key)) {
274 classOM.setAbstract(Boolean.valueOf(defaultValues.get(key)));
275 }
276 } else {
277 classOM.setAbstract(Boolean.valueOf(abstractYAMLO));
278 }
279
280
281 List<String> superClassesYAMLO = classYAMLO.getMapStringListString(SUPER_CLASSES);
282 for (String superClassYAMLO : superClassesYAMLO) {
283 ObjectModelImplSuperClassRef superClassOM = new ObjectModelImplSuperClassRef();
284 superClassOM.setName(superClassYAMLO);
285 classOM.addSuperclass(superClassOM);
286 }
287 }
288
289 public void loadInterface(YamlObject interfaceYAMLO, ObjectModelInterfaceImpl interfaceOM) {
290 loadClassifier(interfaceYAMLO, interfaceOM);
291 }
292
293 public void loadAssociationClass(YamlObject associationClassYAML, ObjectModelAssociationClassImpl associationClassOM) {
294 loadClass(associationClassYAML, associationClassOM);
295
296
297
298
299 for (YamlObject participantYAMLO : associationClassYAML.getMapStringListYamlObject(PARTICIPANT)) {
300 ObjectModeImplAssociationClassParticipant participantOM = new ObjectModeImplAssociationClassParticipant();
301 participantOM.setAssociationClass(associationClassOM);
302
303 String nameYAMLO = participantYAMLO.getFirstMapStringListString(NAME);
304 if (nameYAMLO == null) {
305 String key = ASSOCIATION_CLASS + SEPARATOR + PARTICIPANT + SEPARATOR + NAME;
306 if (defaultValues.containsKey(key)) {
307 participantOM.setName(defaultValues.get(key));
308 }
309 } else {
310 participantOM.setName(nameYAMLO);
311 }
312
313 String attributeYAMLO = participantYAMLO.getFirstMapStringListString(ATTRIBUTE);
314 if (attributeYAMLO == null) {
315 String key = ASSOCIATION_CLASS + SEPARATOR + PARTICIPANT + SEPARATOR + ATTRIBUTE;
316 if (defaultValues.containsKey(key)) {
317 participantOM.setAttribute(defaultValues.get(key));
318 }
319 } else {
320 participantOM.setAttribute(attributeYAMLO);
321 }
322
323 associationClassOM.addParticipant(participantOM);
324 }
325 }
326
327 public void loadEnumeration(YamlObject enumerationYAMLO, ObjectModelEnumerationImpl enumerationOM) {
328 loadElement(enumerationYAMLO, enumerationOM);
329
330
331
332 List<String> literalsYAMLO = enumerationYAMLO.getMapStringListString(LITERALS);
333 for (String literalYAMLO : literalsYAMLO) {
334 ObjectModelImplRef literalOM = new ObjectModelImplRef();
335 literalOM.setName(literalYAMLO);
336 enumerationOM.addLiteral(literalOM);
337 }
338
339
340 String packageYAMLO = enumerationYAMLO.getFirstMapStringListString(PACKAGE);
341 if (packageYAMLO == null) {
342 enumerationOM.setPackage(packageL);
343 } else {
344 enumerationOM.setPackage(packageYAMLO);
345 }
346 }
347
348 public void loadParameter(YamlObject parameterYAMLO, ObjectModelParameterImpl parameterOM) {
349 loadElement(parameterYAMLO, parameterOM);
350
351
352 String orderingYAMLO = parameterYAMLO.getFirstMapStringListString(ORDERING);
353 if (orderingYAMLO == null) {
354 String key = PARAMETER + SEPARATOR + ORDERING;
355 if (defaultValues.containsKey(key)) {
356 parameterOM.setOrdering(defaultValues.get(key));
357 }
358 } else {
359 parameterOM.setOrdering(orderingYAMLO);
360 }
361
362
363 String typeYAMLO = parameterYAMLO.getFirstMapStringListString(TYPE);
364 if (typeYAMLO == null) {
365 String key = PARAMETER + SEPARATOR + TYPE;
366 if (defaultValues.containsKey(key)) {
367 parameterOM.setType(defaultValues.get(key));
368 }
369 } else {
370 parameterOM.setType(typeYAMLO);
371 }
372
373
374 String defaultValueYAMLO = parameterYAMLO.getFirstMapStringListString(DEFAULT_VALUE);
375 if (defaultValueYAMLO == null) {
376 String key = PARAMETER + SEPARATOR + DEFAULT_VALUE;
377 if (defaultValues.containsKey(key)) {
378 parameterOM.setDefaultValue(defaultValues.get(key));
379 }
380 } else {
381 parameterOM.setDefaultValue(defaultValueYAMLO);
382 }
383
384
385 String minMultiplicityYAMLO = parameterYAMLO.getFirstMapStringListString(MIN_MULTIPLICITY);
386 if (minMultiplicityYAMLO == null) {
387 String key = PARAMETER + SEPARATOR + MIN_MULTIPLICITY;
388 if (defaultValues.containsKey(key)) {
389 parameterOM.setMinMultiplicity(Integer.valueOf(defaultValues.get(key)));
390 }
391 } else {
392 parameterOM.setMinMultiplicity(Integer.valueOf(minMultiplicityYAMLO));
393 }
394
395
396 String maxMultiplicityYAMLO = parameterYAMLO.getFirstMapStringListString(MAX_MULTIPLICITY);
397 if (maxMultiplicityYAMLO == null) {
398 String key = PARAMETER + SEPARATOR + MAX_MULTIPLICITY;
399 if (defaultValues.containsKey(key)) {
400 parameterOM.setMaxMultiplicity(Integer.valueOf(defaultValues.get(key)));
401 }
402 } else {
403 parameterOM.setMaxMultiplicity(Integer.valueOf(maxMultiplicityYAMLO));
404
405 }
406
407
408 String orderedYAMLO = parameterYAMLO.getFirstMapStringListString(ORDERED);
409 if (orderedYAMLO == null) {
410 String key = PARAMETER + SEPARATOR + ORDERED;
411 if (defaultValues.containsKey(key)) {
412 parameterOM.setOrdered(Boolean.valueOf(defaultValues.get(key)));
413 }
414 } else {
415 parameterOM.setOrdered(Boolean.valueOf(orderedYAMLO));
416 }
417
418
419 String uniqueYAMLO = parameterYAMLO.getFirstMapStringListString(UNIQUE);
420 if (uniqueYAMLO == null) {
421 String key = PARAMETER + SEPARATOR + UNIQUE;
422 if (defaultValues.containsKey(key)) {
423 parameterOM.setUnique(Boolean.valueOf(defaultValues.get(key)));
424 }
425 } else {
426 parameterOM.setUnique(Boolean.valueOf(uniqueYAMLO));
427 }
428 }
429
430 public void loadAttribute(YamlObject attributeYAMLO, ObjectModelAttributeImpl attributeOM) {
431 loadParameter(attributeYAMLO, attributeOM);
432
433
434 String navigableYAMLO = attributeYAMLO.getFirstMapStringListString(NAVIGABLE);
435 if (navigableYAMLO == null) {
436 String key = ATTRIBUTE + SEPARATOR + NAVIGABLE;
437 if (defaultValues.containsKey(key)) {
438 attributeOM.setNavigable(Boolean.valueOf(defaultValues.get(key)));
439 }
440 } else {
441 attributeOM.setNavigable(Boolean.valueOf(navigableYAMLO));
442 }
443
444
445 String associationTypeYAMLO = attributeYAMLO.getFirstMapStringListString(ASSOCIATION_TYPE);
446 if (associationTypeYAMLO == null) {
447 String key = ATTRIBUTE + SEPARATOR + ASSOCIATION_TYPE;
448 if (defaultValues.containsKey(key)) {
449 attributeOM.setAssociationType(defaultValues.get(key));
450 }
451 } else {
452 attributeOM.setAssociationType(associationTypeYAMLO);
453 }
454
455
456 String finalYAMLO = attributeYAMLO.getFirstMapStringListString(FINAL);
457 if (finalYAMLO == null) {
458 String key = ATTRIBUTE + SEPARATOR + FINAL;
459 if (defaultValues.containsKey(key)) {
460 attributeOM.setFinal(Boolean.valueOf(defaultValues.get(key)));
461 }
462 } else {
463 attributeOM.setFinal(Boolean.valueOf(finalYAMLO));
464 }
465
466
467 String staticYAMLO = attributeYAMLO.getFirstMapStringListString(STATIC);
468 if (staticYAMLO == null) {
469 String key = ATTRIBUTE + SEPARATOR + STATIC;
470 if (defaultValues.containsKey(key)) {
471 attributeOM.setStatic(Boolean.valueOf(defaultValues.get(key)));
472 }
473 } else {
474 attributeOM.setStatic(Boolean.valueOf(staticYAMLO));
475 }
476
477
478 String associationClassNameYAMLO = attributeYAMLO.getFirstMapStringListString(ASSOCIATION_CLASS_NAME);
479 if (associationClassNameYAMLO == null) {
480 String key = ATTRIBUTE + SEPARATOR + ASSOCIATION_CLASS_NAME;
481 if (defaultValues.containsKey(key)) {
482 attributeOM.setAssociationClassName(defaultValues.get(key));
483 }
484 } else {
485 attributeOM.setAssociationClassName(associationClassNameYAMLO);
486 }
487
488
489 String reverseAttributeNameYAMLO = attributeYAMLO.getFirstMapStringListString(REVERSE_ATTRIBUTE_NAME);
490 if (reverseAttributeNameYAMLO == null) {
491 String key = ATTRIBUTE + SEPARATOR + REVERSE_ATTRIBUTE_NAME;
492 if (defaultValues.containsKey(key)) {
493 attributeOM.setReverseAttributeName(defaultValues.get(key));
494 }
495 } else {
496 attributeOM.setReverseAttributeName(reverseAttributeNameYAMLO);
497 }
498
499
500 String reverseMaxMultiplicityYAMLO = attributeYAMLO.getFirstMapStringListString(REVERSE_MAX_MULTIPLICITY);
501 if (reverseMaxMultiplicityYAMLO == null) {
502 String key = ATTRIBUTE + SEPARATOR + REVERSE_MAX_MULTIPLICITY;
503 if (defaultValues.containsKey(key)) {
504 attributeOM.setReverseMaxMultiplicity(Integer.valueOf(defaultValues.get(key)));
505 }
506 } else {
507 attributeOM.setReverseMaxMultiplicity(Integer.valueOf(reverseMaxMultiplicityYAMLO));
508 }
509
510
511 String transientYAMLO = attributeYAMLO.getFirstMapStringListString(TRANSIENT);
512 if (transientYAMLO == null) {
513 String key = ATTRIBUTE + SEPARATOR + TRANSIENT;
514 if (defaultValues.containsKey(key)) {
515 attributeOM.setTransient(Boolean.valueOf(defaultValues.get(key)));
516 }
517 } else {
518 attributeOM.setTransient(Boolean.valueOf(transientYAMLO));
519 }
520
521
522 String visibilityYAMLO = attributeYAMLO.getFirstMapStringListString(VISIBILITY);
523 if (visibilityYAMLO == null) {
524 String key = ATTRIBUTE + SEPARATOR + VISIBILITY;
525 if (defaultValues.containsKey(key)) {
526 attributeOM.setVisibility(defaultValues.get(key));
527 }
528 } else {
529 attributeOM.setVisibility(visibilityYAMLO);
530 }
531 }
532
533 public void loadOperation(YamlObject operationYAMLO, ObjectModelOperationImpl operationOM) {
534 loadElement(operationYAMLO, operationOM);
535
536
537 String abstractYAMLO = operationYAMLO.getFirstMapStringListString(ABSTRACT);
538 if (abstractYAMLO == null) {
539 String key = OPERATION + SEPARATOR + ABSTRACT;
540 if (defaultValues.containsKey(key)) {
541 operationOM.setAbstract(Boolean.valueOf(defaultValues.get(key)));
542 }
543 } else {
544 operationOM.setAbstract(Boolean.valueOf(abstractYAMLO));
545 }
546
547
548 String visibilityYAMLO = operationYAMLO.getFirstMapStringListString(VISIBILITY);
549 if (visibilityYAMLO == null) {
550 String key = OPERATION + SEPARATOR + VISIBILITY;
551 if (defaultValues.containsKey(key)) {
552 operationOM.setVisibility(defaultValues.get(key));
553 }
554 } else {
555 operationOM.setVisibility(visibilityYAMLO);
556 }
557
558
559 for (YamlObject returnParameterYAMLO : operationYAMLO.getMapStringListYamlObject(RETURN_PARAMETER)) {
560 ObjectModelParameterImpl returnParameterOM = new ObjectModelAttributeImpl();
561 loadParameter(returnParameterYAMLO, returnParameterOM);
562 operationOM.setReturnParameter(returnParameterOM);
563 }
564
565
566 for (YamlObject parameterYAMLO : operationYAMLO.getMapStringListYamlObject(PARAMETER)) {
567 ObjectModelParameterImpl parameterOM = new ObjectModelAttributeImpl();
568 loadParameter(parameterYAMLO, parameterOM);
569 operationOM.addParameter(parameterOM);
570 }
571
572
573 String bodyCodeYAMLO = operationYAMLO.getFirstMapStringListString(BODY_CODE);
574 if (bodyCodeYAMLO == null) {
575 String key = OPERATION + SEPARATOR + BODY_CODE;
576 if (defaultValues.containsKey(key)) {
577 operationOM.setBodyCode(defaultValues.get(key));
578 }
579 } else {
580 operationOM.setBodyCode(bodyCodeYAMLO);
581 }
582 }
583 }