@@ -49,10 +49,13 @@ tJson2PumlRecursionRecord = record
49
49
ParentIsRelationship: Boolean;
50
50
StopRecursion: Boolean;
51
51
Level: Integer;
52
+ ArrayIndex: Integer;
52
53
ObjectLevel: Integer;
53
54
CharacteristicParentPropertyName: string;
54
55
CharacteristicObject: tPumlCharacteristicObject;
55
- procedure Init (iLeadingObject: string);
56
+ CharacteristicValue: tPumlCharacteristicValue;
57
+ CharacteristicRecord: tPumlCharacteristicRecord;
58
+ procedure Init (iLeadingObject: string);
56
59
function GetParentObjectType : string;
57
60
function GetInCharacteristicMode : Boolean;
58
61
function GetCurrentCharacteristicDefinition : tJson2PumlCharacteristicDefinition;
@@ -150,9 +153,11 @@ procedure TJson2PumlConverter.BuildObjectRelationships (iHierarchieParentObject,
150
153
ArrowFormat: string;
151
154
GroupFromCondition, GroupToCondition, ArrowCondition: string;
152
155
begin
153
- GroupObjectTo:= Definition.IsGroupProperty (iPumlObject.ObjectType, iHierarchieParentObject.ObjectType, ' ' , GroupFromCondition);
154
- // GroupObjectFrom := Definition.IsGroupProperty (iHierarchieParentObject.ObjectType, iPumlObject.ObjectType, '', GroupToCondition);
155
- GroupObjectFrom := Definition.IsGroupProperty (iPumlObject.ObjectType, iHierarchieParentObject.ObjectType, ' ' , GroupFromCondition);
156
+ GroupObjectTo := Definition.IsGroupProperty (iPumlObject.ObjectType, iHierarchieParentObject.ObjectType, ' ' ,
157
+ GroupFromCondition);
158
+ // GroupObjectFrom := Definition.IsGroupProperty (iHierarchieParentObject.ObjectType, iPumlObject.ObjectType, '', GroupToCondition);
159
+ GroupObjectFrom := Definition.IsGroupProperty (iPumlObject.ObjectType, iHierarchieParentObject.ObjectType, ' ' ,
160
+ GroupFromCondition);
156
161
ArrowFormat := Definition.RelationshipTypeArrowFormats.GetFormat (iPumlObject.ObjectType, iRelationshipProperty,
157
162
iRelationshipType, ArrowCondition);
158
163
added := iHierarchieParentObject.addRelationship (iRelationshipProperty, iRelationshipType, iRelationshipTypeProperty,
@@ -213,17 +218,17 @@ procedure TJson2PumlConverter.ConvertArray (iJsonArray: TJSONArray; iInfo: tJson
213
218
begin
214
219
if not Assigned (iJsonArray) then
215
220
Exit;
216
- for i := 0 to iJsonArray.Count - 1 do
217
- begin
218
- SaveRecursionRecord := IncRecursionRecord (iInfo, trpArray);
219
- try
220
- if iInfo.CurrentCharacteristicType = jctList then
221
- iInfo.CharacteristicParentPropertyName :=
222
- Format ( ' %s[%s] ' , [ iInfo.CharacteristicParentPropertyName, (i + 1 ).ToString.PadLeft((i mod 10 ) + 1 )] );
221
+ SaveRecursionRecord := IncRecursionRecord (iInfo, trpArray);
222
+ try
223
+ for i := 0 to iJsonArray.Count - 1 do
224
+ begin
225
+ iInfo.ArrayIndex := i;
226
+ if iInfo.InCharacteristicMode then
227
+ iInfo.CharacteristicRecord := iInfo.CharacteristicValue.AddDetailRecord (i );
223
228
ConvertValue (iJsonArray.Items[i], iInfo, trpArray);
224
- finally
225
- DecRecursionRecord (iInfo, SaveRecursionRecord, trpArray);
226
229
end ;
230
+ finally
231
+ DecRecursionRecord (iInfo, SaveRecursionRecord, trpArray);
227
232
end ;
228
233
end ;
229
234
@@ -435,11 +440,22 @@ procedure TJson2PumlConverter.ConvertObject (iJsonObject: TJsonObject; iInfo: tJ
435
440
RelationshipType := ' ' ;
436
441
RelationshipTypeProperty := ' ' ;
437
442
end ;
438
- if IsCharacteristic and not IsObjectDetail then
439
- begin
440
- iInfo.CharacteristicParentPropertyName := ' ' ;
441
- iInfo.CharacteristicObject := iInfo.ParentObject.AddCharacteristic (iInfo.PropertyName, CharacteristicDefinition);
442
- end ;
443
+ if not IsObjectDetail then
444
+ if IsCharacteristic then
445
+ begin
446
+ iInfo.CharacteristicParentPropertyName := ' ' ;
447
+ iInfo.CharacteristicObject := iInfo.ParentObject.AddCharacteristic (iInfo.PropertyName,
448
+ CharacteristicDefinition);
449
+ iInfo.CharacteristicValue := iInfo.CharacteristicObject;
450
+ iInfo.CharacteristicRecord := iInfo.CharacteristicValue.AddDetailRecord (iInfo.ArrayIndex);
451
+ end
452
+ else if iInfo.InCharacteristicMode then
453
+ begin
454
+ // iInfo.CharacteristicValue := iInfo.CharacteristicRecord.AddValue (iInfo.PropertyName, '');
455
+ // iInfo.CharacteristicRecord := iInfo.CharacteristicValue.AddDetailRecord (iInfo.ArrayIndex);
456
+ iInfo.CharacteristicParentPropertyName :=
457
+ string.join (' .' , [iInfo.CharacteristicParentPropertyName, iInfo.PropertyName]).TrimLeft ([' .' ]);
458
+ end ;
443
459
if Assigned (PumlObject) then
444
460
begin
445
461
if not ObjectIdent.IsEmpty then
@@ -461,15 +477,13 @@ procedure TJson2PumlConverter.ConvertObject (iJsonObject: TJsonObject; iInfo: tJ
461
477
iInfo.ParentRelationshipType := RelationshipType;
462
478
iInfo.ParentRelationShipTypeProperty := RelationshipTypeProperty;
463
479
iInfo.ParentIsRelationship := IsRelationShip;
464
- if iInfo.InCharacteristicMode and not IsCharacteristic then
465
- iInfo.CharacteristicParentPropertyName :=
466
- string.join (' .' , [iInfo.CharacteristicParentPropertyName, iInfo.PropertyName]).TrimLeft ([' .' ]);
467
480
iInfo.ParentPropertyName := iInfo.PropertyName;
468
481
if Definition.ContinueAfterUnhandledObjects or (iInfo.CurrentCharacteristicType = jctrecord) then
469
482
iInfo.StopRecursion := false
470
483
else
471
484
iInfo.StopRecursion := (not (Assigned(PumlObject) or IsObjectDetail or IsRelationShip) and
472
485
Assigned(iInfo.HierarchieParentObject)) or (iInfo.CurrentCharacteristicType = jctList);
486
+ iInfo.ArrayIndex := - 1 ;
473
487
for i := 0 to iJsonObject.Count - 1 do
474
488
begin
475
489
cName := iJsonObject.Pairs[i].JsonString.Value ;
@@ -483,8 +497,6 @@ procedure TJson2PumlConverter.ConvertObject (iJsonObject: TJsonObject; iInfo: tJ
483
497
AddFileLog (' Stop property handling, property [%s.%s] is hidden %s' ,
484
498
[iInfo.ParentPropertyName, cName, FoundCondition]);
485
499
end ;
486
- if iInfo.CurrentCharacteristicType = jctList then
487
- iInfo.CharacteristicObject.AddRecord;
488
500
finally
489
501
DecRecursionRecord (iInfo, SaveRecursionRecord, trpObject);
490
502
end ;
@@ -501,17 +513,62 @@ procedure TJson2PumlConverter.ConvertValue (iJsonValue: TJSONValue; iInfo: tJson
501
513
IsRelationShip: Boolean;
502
514
LogMessage: string;
503
515
FoundCondition: string;
516
+ ValuePropertyName: string;
517
+
518
+ function IsCharacteristicPropertyAllowed (iPropertyName, iParentPropertyName: string;
519
+ var oFoundCondition: string): Boolean;
520
+ begin
521
+ Result := iInfo.CurrentCharacteristicDefinition.IsPropertyAllowed (iPropertyName, iParentPropertyName,
522
+ oFoundCondition);
523
+ if Result then
524
+ AddFileLog (' characteristic property [%s] found %s' , [iPropertyName, oFoundCondition])
525
+ else
526
+ AddFileLog (' property [%s] not allowed and skipped %s' , [iPropertyName, oFoundCondition]);
527
+ end ;
528
+
504
529
begin
505
530
if not Assigned (iJsonValue) then
506
531
Exit;
532
+ if iInfo.InCharacteristicMode then
533
+ if iRecursionParent = trpArray then
534
+ ValuePropertyName := Format (' [%d]' , [iInfo.ArrayIndex])
535
+ else
536
+ ValuePropertyName := iInfo.PropertyName
537
+ else
538
+ ValuePropertyName := ' ' ;
507
539
SaveRecursionRecord := IncRecursionRecord (iInfo, trpValue);
508
540
try
509
541
if iJsonValue is TJSONArray then
510
- ConvertArray (iJsonValue as TJSONArray, iInfo)
542
+ begin
543
+ if iInfo.InCharacteristicMode then
544
+ begin
545
+ if IsCharacteristicPropertyAllowed (ValuePropertyName, iInfo.CharacteristicParentPropertyName, FoundCondition)
546
+ then
547
+ begin
548
+ iInfo.CharacteristicValue := iInfo.CharacteristicRecord.AddValue (ValuePropertyName, ' ' );
549
+ ConvertArray (iJsonValue as TJSONArray, iInfo);
550
+ end ;
551
+ end
552
+ else
553
+ ConvertArray (iJsonValue as TJSONArray, iInfo);
554
+ end
511
555
else if iJsonValue is TJsonObject then
512
556
begin
513
557
if not iInfo.StopRecursion then
514
- ConvertObject (iJsonValue as TJsonObject, iInfo)
558
+ begin
559
+ if iInfo.InCharacteristicMode then
560
+ begin
561
+ if IsCharacteristicPropertyAllowed (ValuePropertyName, iInfo.CharacteristicParentPropertyName, FoundCondition)
562
+ then
563
+ begin
564
+ iInfo.CharacteristicValue := iInfo.CharacteristicRecord.AddValue (ValuePropertyName, ' ' );
565
+ iInfo.CharacteristicRecord := iInfo.CharacteristicValue.AddDetailRecord ( - 1 );
566
+ ConvertObject (iJsonValue as TJsonObject, iInfo)
567
+ end ;
568
+ end
569
+ else
570
+ ConvertObject (iJsonValue as TJsonObject, iInfo)
571
+ end ;
515
572
end
516
573
else if IsJsonSimple (iJsonValue) then
517
574
begin
@@ -546,16 +603,11 @@ procedure TJson2PumlConverter.ConvertValue (iJsonValue: TJSONValue; iInfo: tJson
546
603
begin
547
604
if iInfo.InCharacteristicMode then
548
605
begin
549
- if iInfo.CurrentCharacteristicDefinition.IsPropertyAllowed ( iInfo.PropertyName ,
550
- iInfo.CharacteristicParentPropertyName, FoundCondition) then
606
+ if IsCharacteristicPropertyAllowed (ValuePropertyName, iInfo.CharacteristicParentPropertyName ,
607
+ FoundCondition) then
551
608
begin
552
- iInfo.CharacteristicObject.AddRecordProperty (iInfo.PropertyName, Value ,
553
- iInfo.CharacteristicParentPropertyName);
554
- AddFileLog (' characteristic property [%s] value [%s] found %s' ,
555
- [iInfo.PropertyName, Value , FoundCondition]);
609
+ iInfo.CharacteristicValue := iInfo.CharacteristicRecord.AddValue (ValuePropertyName, Value );
556
610
end
557
- else
558
- AddFileLog (' property [%s] not allowed and skipped %s' , [iInfo.PropertyName, FoundCondition]);
559
611
end
560
612
else
561
613
begin
@@ -831,7 +883,7 @@ function TJson2PumlConverter.Convert: Boolean;
831
883
[InputHandlerRecord.InputFile.OutputFileName])
832
884
else
833
885
begin
834
- InfoRec.Init(LeadingObject);
886
+ InfoRec.Init (LeadingObject);
835
887
ConvertValue (jValue, InfoRec, trpStart);
836
888
GeneratePuml;
837
889
Result := true;
@@ -986,7 +1038,7 @@ function tJson2PumlRecursionParentHelper.OperationName: string;
986
1038
Result := cJson2PumlRecursionParentFunction[self];
987
1039
end ;
988
1040
989
- procedure tJson2PumlRecursionRecord.Init (iLeadingObject: string);
1041
+ procedure tJson2PumlRecursionRecord.Init (iLeadingObject: string);
990
1042
begin
991
1043
ParentObject := nil ;
992
1044
HierarchieParentObject := nil ;
@@ -1000,6 +1052,7 @@ procedure tJson2PumlRecursionRecord.Init(iLeadingObject: string);
1000
1052
StopRecursion := false;
1001
1053
Level := 0 ;
1002
1054
ObjectLevel := 0 ;
1055
+ ArrayIndex := - 1 ;
1003
1056
CharacteristicParentPropertyName := ' ' ;
1004
1057
CharacteristicObject := nil ;
1005
1058
end ;
0 commit comments