My favorites | Sign in
Project Home Wiki Issues Source
Checkout   Browse   Changes    
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
/**
* Completes the functionality of {@model SetWire}s.
*/
package org.openiaml.model.drools.rules.set_wires

#list any import classes here.
import org.openiaml.model.drools.*;

import org.openiaml.model.inference.*;
import org.openiaml.model.model.*;
import org.openiaml.model.model.impl.*;
import org.openiaml.model.model.wires.*;
import org.openiaml.model.model.visual.*;
import org.openiaml.model.model.operations.*;
import org.openiaml.model.model.scopes.*;
import org.openiaml.model.model.domain.*;
import org.openiaml.model.model.messaging.*;

import org.eclipse.emf.ecore.*;

#declare any global variables here
global OverridableCreateElementsHelper handler;
global DroolsInsertionQueue queue;
global DroolsHelperFunctions functions;

/**
* @inference SetWire,CanBeSynced
* A {@model SetWire} connecting two objects will create sub-{@model SetWire}s between
* every contained object within these parent objects which have matching {@model CanBeSynced#name names}.
*/
rule "Set wires between objects should create set wires between all elements inside each object that matches [set]"
when
p1 : CanBeSynced( )
p2 : CanBeSynced( this != p1 )
source : SetWire( from == p1, to == p2, overriddenNames not contains "set" )

e1 : CanBeSynced( eContainer == p1 )
e2 : CanBeSynced( eContainer == p2, eval(functions.nameMatches(e1, e2)) )

not (sw : SetWire( eContainer == source, from == e1, to == e2 ))

eval ( handler.veto( source ))

then
SetWire sw = handler.generatedSetWire(source, source, e1, e2);
handler.setName(sw, "set");
handler.setExecuteOnInput(sw, source.isExecuteOnInput());
queue.add(sw, drools);

end

/**
* @inference SetWire,CanBeSynced
* A {@model SetWire} connecting an {@model DomainIterator} to a {@model CanBeSynced} object
* will create sub-{@model SetWire}s between every contained object within the contained {@model DomainInstance}
* to every contained {@model CanBeSynced} object which have matching {@model CanBeSynced#name names}.
*/
rule "Copy set wires: Domain Instances (source)"
when
p1_container : DomainIterator ( )
p1 : DomainInstance( p1_container.currentInstance == p1 )
p2 : CanBeSynced( this != p1 )
source : SetWire( from == p1_container, to == p2, overriddenNames not contains "set" )

e1 : CanBeSynced( eContainer == p1 )
e2 : CanBeSynced( eContainer == p2, eval(functions.nameMatches(e1, e2)) )

not (sw : SetWire( eContainer == source, from == e1, to == e2 ))

eval ( handler.veto( source ))

then
SetWire sw = handler.generatedSetWire(source, source, e1, e2);
handler.setName(sw, "set");
handler.setExecuteOnInput(sw, source.isExecuteOnInput());
queue.add(sw, drools);

end

/**
* @inference SetWire,CanBeSynced
* A {@model SetWire} connecting an {@model CanBeSynced} object to a {@model DomainIterator}
* will create sub-{@model SetWire}s between every contained {@model CanBeSynced} object to
* every contained object within the contained {@model DomainInstance}
* which have matching {@model CanBeSynced#name names}.
*/
rule "Copy set wires: Domain Instances (target)"
when
p1 : CanBeSynced( )
p2_container : DomainIterator ( )
p2 : DomainInstance( p2_container.currentInstance == p2, this != p1 )
source : SetWire( from == p1, to == p2_container, overriddenNames not contains "set" )

e1 : CanBeSynced( eContainer == p1 )
e2 : CanBeSynced( eContainer == p2, eval(functions.nameMatches(e1, e2)) )

not (sw : SetWire( eContainer == source, from == e1, to == e2 ))

eval ( handler.veto( source ))

then
SetWire sw = handler.generatedSetWire(source, source, e1, e2);
handler.setName(sw, "set");
handler.setExecuteOnInput(sw, source.isExecuteOnInput());
queue.add(sw, drools);

end

/**
* @inference SetWire
* When a {@model Changeable} is connected to a {@model ContainsOperations} by a
* {@model SetWire}, the source element will {@model ECARule call} the 'update' {@model Operation} on the
* target when the source {@model Changeable#onChange changes}.
*/
rule "Run instance wire from edit to update (onChange) [set]"
when
source : Changeable( )
target : ContainsOperations( )
sw : SetWire( from == source, to == target, overriddenNames not contains "run" )

event : Event( source.onChange == event )
operation : Operation( eContainer == target, name=="update" )

not (ECARule( eContainer == sw, trigger == event, target == operation ))

eval ( handler.veto( sw ))

then
ECARule rw = handler.generatedECARule(sw, sw, event, operation);
handler.setName(rw, "run");
queue.add(rw, drools);

end

/**
* Solves issue 209: Allow Properties to be set directly by SetWires or SyncWires.
*
* @inference SetWire,Changeable,Value
* When a {@model Changeable} is connected to a {@model Value} by a
* {@model SetWire}, the source element will {@model ECARule call} the 'set value XXX' {@model Operation} on the
* target when the source {@model Changeable#onChange changes}.
*/
rule "Run instance wire from edit to Value update (onChange) [set]"
when
source : Changeable( )

targetContainer : ContainsOperations ( )
target : Value ( eContainer == targetContainer )
sw : SetWire( from == source, to == target, overriddenNames not contains "run" )

event : Event( source.onChange == event )
operation : Operation( eContainer == targetContainer,
name != null,
eval( ("set value " + target.getName()).equals(operation.getName()) ) )

not (ECARule( eContainer == sw, trigger == event, target == operation ))

eval ( handler.veto( sw ))

then
ECARule rw = handler.generatedECARule(sw, sw, event, operation);
handler.setName(rw, "run");
queue.add(rw, drools);

end

/**
* @inference SetWire,InputTextField
* When an {@model InputTextField} is connected to a {@model ContainsOperations} by an {@model SetWire#executeOnInput instant}
* {@model SetWire}, the source element will {@model ECARule call} the 'update' {@model Operation} on the
* target when the source {@model InputTextField#onInput input changes}.
*/
rule "Run instance wire from edit to update, instant SetWire (onInput)"
when
source : InputTextField( )
target : ContainsOperations( )
sw : SetWire( from == source, to == target, executeOnInput == true, overriddenNames not contains "run" )

event : Event( source.onInput == event )
operation : Operation( eContainer == target, name=="update" )

not (ECARule( eContainer == sw, trigger == event, target == operation, name == "run" ))

eval ( handler.veto( sw ))

then
ECARule rw = handler.generatedECARule(sw, sw, event, operation);
handler.setName(rw, "run");
queue.add(rw, drools);

end

/**
* TODO Ideally, these two commands would be joined together into one
*
* @inference SetWire,CanBeSynced,Parameter
* When a {@model CanBeSynced} element is connected to an {@model CanBeSynced} element by a
* {@model SetWire}, the {@model CanBeSynced#fieldValue value} of the source element
* will be provided as a {@model Parameter} to the updating {@model ECARule}.
*/
rule "Connect parameter wire to: run instance wire from source.edit to target.update [set]"
when
source : CanBeSynced( )
target : CanBeSynced( )
sw : SetWire( from == source, to == target, overriddenNames not contains "[set] run instance parameter (source.edit)" )

event : Event( eContainer == source, name=="edit" )
operation : Operation( eContainer == target, name=="update" )
field : Value( source.fieldValue == field )
wire : ECARule( trigger == event, target == operation, name == "run", eContainer == sw )

not (Parameter( eContainer == sw, parameterValue == field, parameterTerm == wire ))

eval ( handler.veto( sw ))

then
Parameter pw = handler.generatedParameter(sw, sw, field, wire);
handler.setName(pw, "[set] run instance parameter (source.edit)");
queue.add(pw, drools);

end

/**
* TODO Ideally, these two commands would be joined together into one
*
* @inference SetWire,CanBeSynced,Changeable,Parameter
* When a {@model Changeable} element is connected to an {@model CanBeSynced} element by a
* {@model SetWire}, the {@model CanBeSynced#fieldValue value} of the source element
* will be provided as a {@model Parameter} to the updating {@model ECARule}.
*/
rule "Connect parameter wire to: run instance wire from source.edit to target.update [set] (onChange)"
when
source : Changeable( )
target : CanBeSynced( )
sw : SetWire( from == source, to == target, overriddenNames not contains "[set] run instance parameter (source.edit)" )

event : Event( source.onChange == event )
operation : Operation( eContainer == target, name=="update" )
field : Value( source.fieldValue == field )
wire : ECARule( trigger == event, target == operation, name == "run", eContainer == sw )

not (Parameter( eContainer == sw, parameterValue == field, parameterTerm == wire ))

eval ( handler.veto( sw ))

then
Parameter pw = handler.generatedParameter(sw, sw, field, wire);
handler.setName(pw, "[set] run instance parameter (source.edit)");
queue.add(pw, drools);

end

/**
* @inference SetWire,Changeable,Value,Parameter
* When a {@model Changeable} element is connected to a {@model Value} by a
* {@model SetWire}, the {@model CanBeSynced#fieldValue value} of the source element
* will be provided as a {@model Parameter} to the updating {@model ECARule}.
*/
rule "Connect parameter wire to: Run instance wire from edit to Value update (onChange)"
when
source : Changeable( )

targetContainer : ContainsOperations ( )
target : Value ( eContainer == targetContainer )
sw : SetWire( from == source, to == target, overriddenNames not contains "[set] run instance parameter (source.edit)" )

event : Event( source.onChange == event )
operation : Operation( eContainer == targetContainer,
name != null,
eval( ("set value " + target.getName()).equals(operation.getName()) ) )

field : Value( source.fieldValue == field )
wire : ECARule( trigger == event, target == operation, name == "run", eContainer == sw )

not (Parameter( eContainer == sw, parameterValue == field, parameterTerm == wire ))

eval ( handler.veto( sw ))

then
Parameter pw = handler.generatedParameter(sw, sw, field, wire);
handler.setName(pw, "[set] run instance parameter (source.edit)");
queue.add(pw, drools);


end

/**
* @inference SetWire,InputTextField,CanBeSynced,Parameter
* When an {@model InputTextField} is connected to a {@model CanBeSynced} element by an {@model SetWire#executeOnInput instant}
* {@model SetWire}, the {@model CanBeSynced#fieldValue value} of the source element
* will be provided as a {@model Parameter} to the updating {@model ECARule}.
*/
rule "Connect parameter wire to: run instance wire from source.edit to target.update [set], instant SetWire (onInput)"
when
source : InputTextField( )
target : CanBeSynced( )
sw : SetWire( executeOnInput == true, from == source, to == target, overriddenNames not contains "[set] run instance parameter, instant SetWire (source.edit)" )

event : Event( source.onInput == event )
operation : Operation( eContainer == target, name=="update" )
field : Value( source.currentInput == field )
wire : ECARule( trigger == event, target == operation, name == "run", eContainer == sw )

not (Parameter( eContainer == sw, parameterValue == field, parameterTerm == wire ))

eval ( handler.veto( sw ))

then
Parameter pw = handler.generatedParameter(sw, sw, field, wire);
handler.setName(pw, "[set] run instance parameter, instant SetWire (source.edit)");
queue.add(pw, drools);

end

/**
* TODO Ideally, these two commands would be joined together into one
*
* @inference SetWire
* When a {@model ContainsOperations} element is connected to an {@model Accessible} element by a
* {@model SetWire}, the source element will {@model ECARule call} the 'init' {@model Operation} on the
* target when the target {@model Accessible#onAccess is accessed}.
*/
rule "Run instance wire from target.access to target.init, when we have a value to provide as a parameter [set] (onAccess)"
when
source : ContainsOperations( )
target : Accessible( )
sw : SetWire( from == source, to == target, overriddenNames not contains "run" )

event : Event( target.onAccess == event )
operation : Operation( eContainer == target, name=="init" )
field : Value( source.fieldValue == field )

not (ECARule( eContainer == sw, trigger == event, target == operation, name == "run" ))

eval ( handler.veto( sw ))

then
ECARule rw = handler.generatedECARule(sw, sw, event, operation);
handler.setName(rw, "run");
queue.add(rw, drools);

end

/**
* @inference SetWire,SimpleCondition
* When a {@model ContainsOperations} element is connected to an {@model Accessible} element by a
* {@model SetWire}, the target element will {@model SimpleCondition only} be initialised if the source value is set.
*/
rule "Run instance wire from target.access to target.init, adding SimpleCondition to check it is set [set] (onAccess)"
when
source : ContainsOperations( )
target : Accessible( )
sw : SetWire( from == source, to == target )

event : Event( target.onAccess == event )
operation : Operation( eContainer == target, name=="init" )
field : Value( source.fieldValue == field )

run : ECARule( eContainer == sw, trigger == event, target == operation, name == "run" )
param : Parameter( parameterValue == field, parameterTerm == run )

# condition check
condition : Function ( eContainer == source, name == "fieldValue is set" )

not ( SimpleCondition ( function == condition, conditioned == run ))

eval ( handler.veto( sw ))

then
SimpleCondition cw = handler.generatedSimpleCondition(sw, sw, condition, run);
queue.add(cw, drools);

end

/**
* @inference SetWire,Parameter
* When a {@model CanBeSynced} element is connected to an {@model Accessible} element by a
* {@model SetWire}, the {@model CanBeSynced#fieldValue} of the source element will be used as a
* {@model Parameter} to initialise the target through the 'init' {@model Operation}.
*/
rule "Connect parameter wire to: run instance wire from target.access to target.init [set] (onAccess)"
when
source : CanBeSynced( )
target : Accessible( )
sw : SetWire( from == source, to == target, overriddenNames not contains "[set] run instance parameter (source.access)" )

event : Event( target.onAccess == event )
operation : Operation( eContainer == target, name=="init" )
field : Value( source.fieldValue == field )
wire : ECARule( trigger == event, target == operation, name == "run", eContainer == sw )

not (Parameter( eContainer == sw, parameterValue == field, parameterTerm == wire ))

eval ( handler.veto( sw ))

then
Parameter pw = handler.generatedParameter(sw, sw, field, wire);
handler.setName(pw, "[set] run instance parameter (source.access)");
queue.add(pw, drools);

end

/**
* I think that chained SetWires are generally impossible. Consider:
*
* page1 <--> page2 <--> unrelated
* condition on both SetWires, matching (page1, page2)
*
* If we allow for chaining, then the condition
* condition[page2, unrelated]
* will be copied onto
* condition[page1, page2]
* which means the SetWires will never satisfy all its conditions.
*
* --
*
* I think that chained SetWires are only possible *when* each
* SetWires has identical Conditions, so we don't have to combine
* the two conditions together into something impossible.
*
* However, trying to implement this did nothing. I think it is because
* without adding more information to the model, you cannot chain.
* The information you'd be adding is stuff like ChainedSetWire, but
* this defeats the purpose of having it in the model, because this should
* be handled by the code generation instead.
*/

/**
* @inference SetWire,SimpleCondition
* A sub-{@model SetWire} generated for a parent {@model SetWire}
* will also be restricted with all of the {@model SimpleCondition}s of the parent wire.
*/
rule "Cascaded SetWires: Conditions from parent to child [set]"
when

# the containing elements
source : CanBeSynced( )
target : CanBeSynced( )
sw : SetWire ( from == source, to == target )

# the elements contained
e1 : CanBeSynced( eContainer == source )
e2 : CanBeSynced( eContainer == target, eval(functions.nameMatches(e1, e2)) )
esw : SetWire( from == e1, to == e2 )

# there is a condition on the containing sync wire
condition : Function ( )
cw : SimpleCondition( function == condition, conditioned == sw )

# and there isn't one on the element sync wire
not (ecw : SimpleCondition( function == condition, conditioned == esw ))

eval ( handler.veto( cw ))

then
SimpleCondition ecw = handler.generatedSimpleCondition( cw, sw, condition, esw );
handler.setName(ecw, "[copied] from: " + cw.getId());
queue.add(ecw, drools);

end

/**
* @inference SetWire,SimpleCondition
* A sub-{@model SetWire} generated for a parent {@model SetWire} connected from a {@model DomainIterator}
* will also be restricted with all of the {@model SimpleCondition}s of the parent wire.
*/
rule "Cascaded SetWires: Conditions: Domain Iterator (source)"
when

# the containing elements
source_container : DomainIterator( )
source : DomainInstance( eContainer == source_container )
target : CanBeSynced( )
sw : SetWire ( from == source_container, to == target )

# the elements contained
e1 : CanBeSynced( eContainer == source )
e2 : CanBeSynced( eContainer == target, eval(functions.nameMatches(e1, e2)) )
esw : SetWire( from == e1, to == e2 )

# there is a condition on the containing sync wire
condition : Function ( )
cw : SimpleCondition( function == condition, conditioned == sw )

# and there isn't one on the element sync wire
not (ecw : SimpleCondition( function == condition, conditioned == esw ))

eval ( handler.veto( cw ))

then
SimpleCondition ecw = handler.generatedSimpleCondition( cw, sw, condition, esw );
handler.setName(ecw, "[copied] from: " + cw.getId());
queue.add(ecw, drools);

end

/**
* @inference SetWire,SimpleCondition
* A sub-{@model SetWire} generated for a parent {@model SetWire} connected to a {@model DomainIterator}
* will also be restricted with all of the {@model SimpleCondition}s of the parent wire.
*/
rule "Cascaded SetWires: Conditions: Domain Iterator (target)"
when

# the containing elements
source : CanBeSynced( )
target_container : DomainIterator( )
target : DomainInstance( eContainer == target_container )
sw : SetWire ( from == source, to == target_container )

# the elements contained
e1 : CanBeSynced( eContainer == source )
e2 : CanBeSynced( eContainer == target, eval(functions.nameMatches(e1, e2)) )
esw : SetWire( from == e1, to == e2 )

# there is a condition on the containing sync wire
condition : Function ( )
cw : SimpleCondition( function == condition, conditioned == sw )

# and there isn't one on the element sync wire
not (ecw : SimpleCondition( function == condition, conditioned == esw ))

eval ( handler.veto( cw ))

then
SimpleCondition ecw = handler.generatedSimpleCondition( cw, sw, condition, esw );
handler.setName(ecw, "[copied] from: " + cw.getId());
queue.add(ecw, drools);

end

/**
* @inference SetWire,SimpleCondition
* All restrictions derived by copying the {@model SimpleCondition}s of parent {@model SetWire}s
* to their sub-{@model SetWire}s will also be provided with the same {@model Parameter}s.
*/
rule "Cascaded SetWires: Parameters from parent to child [set]"
when

# the containing elements
source : CanBeSynced( )
target : CanBeSynced( )
sw : SetWire ( from == source, to == target )

# the elements contained
e1 : CanBeSynced( eContainer == source )
e2 : CanBeSynced( eContainer == target, eval(functions.nameMatches(e1, e2)) )
esw : SetWire( from == e1, to == e2 )

# there is a condition on the containing sync wire
condition : Function ( )
cw : SimpleCondition( function == condition, conditioned == sw )

# the generated condition wire
ecw : SimpleCondition( function == condition, conditioned == esw )

# there is a parameter on the condition wire
parameter : ParameterEdgesSource( )
pw : Parameter( parameterValue == parameter, parameterTerm == cw )

# and there isn't one on the element sync wire
not (epw : Parameter( parameterValue == parameter, parameterTerm == ecw ))

eval ( handler.veto( cw ))

then
# create it
Parameter epw = handler.generatedParameter( cw, sw, parameter, ecw );
handler.setName(epw, "[copied] from: " + pw.getId());
queue.add(epw, drools);

end

/**
* @inference SetWire,SimpleCondition
* All restrictions derived by copying the {@model SimpleCondition}s of parent {@model SetWire}s from a {@model DomainIterator}
* to their sub-{@model SetWire}s will also be provided with the same {@model Parameter}s.
*/
rule "Cascaded SetWires: Parameters: Domain Iterator (source)"
when

# the containing elements
source_container : DomainIterator( )
source : DomainInstance( eContainer == source_container )
target : CanBeSynced( )
sw : SetWire ( from == source_container, to == target )

# the elements contained
e1 : CanBeSynced( eContainer == source )
e2 : CanBeSynced( eContainer == target, eval(functions.nameMatches(e1, e2)) )
esw : SetWire( from == e1, to == e2 )

# there is a condition on the containing sync wire
condition : Function ( )
cw : SimpleCondition( function == condition, conditioned == sw )

# the generated condition wire
ecw : SimpleCondition( function == condition, conditioned == esw )

# there is a parameter on the condition wire
parameter : ParameterEdgesSource( )
pw : Parameter( parameterValue == parameter, parameterTerm == cw )

# and there isn't one on the element sync wire
not (epw : Parameter( parameterValue == parameter, parameterTerm == ecw ))

eval ( handler.veto( cw ))

then
# create it
Parameter epw = handler.generatedParameter( cw, sw, parameter, ecw );
handler.setName(epw, "[copied] from: " + pw.getId());
queue.add(epw, drools);

end

/**
* @inference SetWire,SimpleCondition
* All restrictions derived by copying the {@model SimpleCondition}s of parent {@model SetWire}s to a {@model DomainIterator}
* to their sub-{@model SetWire}s will also be provided with the same {@model Parameter}s.
*/
rule "Cascaded SetWires: Parameters: Domain Iterator (target)"
when

# the containing elements
source : CanBeSynced( )
target_container : DomainIterator( )
target : DomainInstance( eContainer == target_container )
sw : SetWire ( from == source, to == target_container )

# the elements contained
e1 : CanBeSynced( eContainer == source )
e2 : CanBeSynced( eContainer == target, eval(functions.nameMatches(e1, e2)) )
esw : SetWire( from == e1, to == e2 )

# there is a condition on the containing sync wire
condition : Function ( )
cw : SimpleCondition( function == condition, conditioned == sw )

# the generated condition wire
ecw : SimpleCondition( function == condition, conditioned == esw )

# there is a parameter on the condition wire
parameter : ParameterEdgesSource( )
pw : Parameter( parameterValue == parameter, parameterTerm == cw )

# and there isn't one on the element sync wire
not (epw : Parameter( parameterValue == parameter, parameterTerm == ecw ))

eval ( handler.veto( cw ))

then
# create it
Parameter epw = handler.generatedParameter( cw, sw, parameter, ecw );
handler.setName(epw, "[copied] from: " + pw.getId());
queue.add(epw, drools);

end

/**
* SetWires do not just connect the fields together; they can _also_
* connect the Frames together.
*
* @inference SetWire,Session
* A parent {@model SetWire} connecting a {@model Session}-contained {@model VisibleThing} to a {@model ContainsOperations} element
* outside of that {@model Session}, will {@model ECARule call} the 'init' {@model Operation} generated by each sub-{@model SetWire}
* when the {@model Session} is {@model Session#onInit initialised}.
*/
rule "Connect Session.init to incoming SetWires (contained in Frames) [set] (onChange 2)"
when
session : Session ( )
sourceFrame : VisibleThing( eval(!functions.containingSessionEquals(sourceFrame, session)) )
targetFrame : ContainsOperations( eval(functions.containingSessionEquals(targetFrame, session)) )
sw : SetWire( from == sourceFrame, to == targetFrame )

sourceElement : Changeable( eContainer == sourceFrame )
targetElement : ContainsOperations( eContainer == targetFrame )
sw2 : SetWire ( from == sourceElement, to == targetElement, eContainer == sw, overriddenNames not contains "run" )

event : Event( sourceElement.onChange == event )
operation : Operation( eContainer == targetElement, name == "update" )

rw : ECARule( eContainer == sw2, trigger == event, target == operation, name == "run" )
inite : Event (eContainer == session, session.onInit == inite )

not (ECARule( eContainer == sw2, trigger == inite, target == operation, name == "run" ))

eval ( handler.veto( sw2 ))

then
ECARule rw2 = handler.generatedECARule(sw2, sw2, inite, operation);
handler.setName(rw2, "run");
queue.add(rw2, drools);

end

/**
* VisibleThing != Frame
*
* @inference SetWire,Session
* A parent {@model SetWire} connecting a {@model Session}-contained {@model Frame} to a {@model ContainsOperations} element
* outside of that {@model Session}, will {@model ECARule call} the 'init' {@model Operation} generated by each sub-{@model SetWire}
* when the {@model Session} is {@model Session#onInit initialised}.
*/
rule "Connect Session.init to incoming SetWires (contained in Frames) [set] (onChange 3)"
when
session : Session ( )
sourceFrame : Frame( eval(!functions.containingSessionEquals(sourceFrame, session)) )
targetFrame : ContainsOperations( eval(functions.containingSessionEquals(targetFrame, session)) )
sw : SetWire( from == sourceFrame, to == targetFrame )

sourceElement : Changeable( eContainer == sourceFrame )
targetElement : ContainsOperations( eContainer == targetFrame )
sw2 : SetWire ( from == sourceElement, to == targetElement, eContainer == sw, overriddenNames not contains "run" )

event : Event( sourceElement.onChange == event )
operation : Operation( eContainer == targetElement, name == "update" )

rw : ECARule( eContainer == sw2, trigger == event, target == operation, name == "run" )
inite : Event (eContainer == session, session.onInit == inite )

not (ECARule( eContainer == sw2, trigger == inite, target == operation, name == "run" ))

eval ( handler.veto( sw2 ))

then
ECARule rw2 = handler.generatedECARule(sw2, sw2, inite, operation);
handler.setName(rw2, "run");
queue.add(rw2, drools);

end

/**
* @inference SetWire,Session,Parameter
* Every 'init' {@model Operation} executed when a {@model Session} is {@model Session#onInit initialised} due to
* a {@model SetWire} between a {@model VisibleThing} within that session, to {@model ContainsOperations another element}
* outside of that session, will be provided the {@model Changeable#fieldValue} of the source element as a {@model Parameter}.
*/
rule "Connect parameter for Session.init to incoming SetWires (contained in Frames) [set] (onChange 2)"
when
session : Session ( )
sourceFrame : VisibleThing( eval(!functions.containingSessionEquals(sourceFrame, session)) )
targetFrame : ContainsOperations( eval(functions.containingSessionEquals(targetFrame, session)) )
sw : SetWire( from == sourceFrame, to == targetFrame )

sourceElement : Changeable( eContainer == sourceFrame )
targetElement : ContainsOperations( eContainer == targetFrame )
sw2 : SetWire ( from == sourceElement, to == targetElement, eContainer == sw)

event : Event( sourceElement.onChange == event )
operation : Operation( eContainer == targetElement, name == "update" )

rw : ECARule( eContainer == sw2, trigger == event, target == operation, name == "run" )
inite : Event (eContainer == session, session.onInit == inite )

initrw : ECARule( eContainer == sw2, trigger == inite, target == operation, name == "run" )

field : Value( sourceElement.fieldValue == field )
pw : Parameter( eContainer == sw2, parameterValue == field, parameterTerm == rw )

not( Parameter ( eContainer == sw2, parameterValue == field, parameterTerm == initrw ))

eval ( handler.veto( sw ))

then
Parameter pw2 = handler.generatedParameter(sw, sw, field, initrw);
queue.add(pw2, drools);
end

/**
* @inference SetWire,Session,Parameter
* Every 'init' {@model Operation} executed when a {@model Session} is {@model Session#onInit initialised} due to
* a {@model SetWire} between a {@model Frame} within that session, to {@model ContainsOperations another element}
* outside of that session, will be provided the {@model Changeable#fieldValue} of the source element as a {@model Parameter}.
*/
rule "Connect parameter for Session.init to incoming SetWires (contained in Frames) [set] (onChange 3)"
when
session : Session ( )
sourceFrame : Frame( eval(!functions.containingSessionEquals(sourceFrame, session)) )
targetFrame : ContainsOperations( eval(functions.containingSessionEquals(targetFrame, session)) )
sw : SetWire( from == sourceFrame, to == targetFrame )

sourceElement : Changeable( eContainer == sourceFrame )
targetElement : ContainsOperations( eContainer == targetFrame )
sw2 : SetWire ( from == sourceElement, to == targetElement, eContainer == sw )

event : Event( sourceElement.onChange == event )
operation : Operation( eContainer == targetElement, name == "update" )

rw : ECARule( eContainer == sw2, trigger == event, target == operation, name == "run" )
inite : Event (eContainer == session, session.onInit == inite )

initrw : ECARule( eContainer == sw2, trigger == inite, target == operation, name == "run" )

field : Value( sourceElement.fieldValue == field )
pw : Parameter( eContainer == sw2, parameterValue == field, parameterTerm == rw )

not( Parameter ( eContainer == sw2, parameterValue == field, parameterTerm == initrw ))

eval ( handler.veto( sw ))

then
Parameter pw2 = handler.generatedParameter(sw, sw, field, initrw);
queue.add(pw2, drools);
end

/**
* @inference SetWire,DomainInstance
* An empty {@model InputForm} connected to a {@model DomainIterator} with a {@model SetWire}
* will create an {@model InputTextField} in that form for every {@model DomainAttributeInstance}
* that is not a {@model DomainAttribute#primaryKey primary key} or {@model DomainAttribute#isGenerated generated}.
*/
rule "Refresh New Instance Object mappings (except for generated primary keys) when Form sets an Instance: create text fields"
when
form : InputForm ( )
iterator : DomainIterator ( )
instance : DomainInstance ( iterator.currentInstance == instance )
sync : SetWire( from == form, to == iterator )

originalAttribute : DomainAttribute ( primaryKey == false || isGenerated == false )
attribute : DomainAttributeInstance( eContainer == instance )
ExtendsEdge ( from == attribute, to == originalAttribute )

not ( tf : VisibleThing( eContainer == form, eval(functions.nameMatches( attribute, tf )) ) )

eval ( !form.getOverriddenNames().contains(attribute.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
InputTextField text = handler.generatedInputTextField(sync, form);
handler.setName(text, attribute.getName());
queue.add(text, drools);

end

/**
* @inference SetWire,InputForm,Label
* An {@model InputForm} connected to another {@model InputForm} with a {@model SetWire}
* will create a {@model Label} in the target form for every {@model InputTextField} in the
* source form with the same {@model Label#name}.
*/
rule "Refresh mappings between InputForms connected to InputForms containing InputTextFields"
when
source : InputForm ( )
target : InputForm ( )
sync : SetWire( from == source, to == target )

sf : InputTextField ( eContainer == source )
not ( tf : VisibleThing ( eContainer == target, eval(functions.nameMatches( sf, tf ))) )

eval ( !target.getOverriddenNames().contains(sf.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
Label tf = handler.generatedLabel(sync, target);
handler.setName(tf, sf.getName());
queue.add(tf, drools);

end

/**
* @inference SetWire,InputForm,Label
* An {@model InputForm} connected to another {@model InputForm} with a {@model SetWire}
* will create a {@model Label} in the target form for every {@model Label} in the
* source form with the same {@model Label#name}.
*/
rule "Refresh mappings between InputForms connected to InputForms containing Labels [set]"
when
source : InputForm ( )
target : InputForm ( )
sync : SetWire( from == source, to == target )

sf : Label ( eContainer == source )
not ( tf : VisibleThing ( eContainer == target, eval(functions.nameMatches( sf, tf ))) )

eval ( !target.getOverriddenNames().contains(sf.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
Label tf = handler.generatedLabel(sync, target);
handler.setName(tf, sf.getName());
queue.add(tf, drools);

end

/**
* @inference SetWire,InputForm,Email
* An {@model InputForm} connected to an {@model Email} with a {@model SetWire}
* will create a {@model Label} in the target Email for every {@model InputTextField} in the
* source form with the same {@model Label#name}.
*/
rule "Refresh mappings between InputForms connected to Emails containing InputTextFields [set]"
when
source : InputForm ( )
target : Email ( )
sync : SetWire( from == source, to == target )

sf : InputTextField ( eContainer == source )
not ( tf : VisibleThing ( eContainer == target, eval(functions.nameMatches( sf, tf ))) )

eval ( !target.getOverriddenNames().contains(sf.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
Label tf = handler.generatedLabel(sync, target);
handler.setName(tf, sf.getName());
queue.add(tf, drools);

end

/**
* @inference SetWire,InputForm,Email
* An {@model InputForm} connected to an {@model Email} with a {@model SetWire}
* will create a {@model Label} in the target Email for every {@model Label} in the
* source form with the same {@model Label#name}.
*/
rule "Refresh mappings between InputForms connected to Emails containing Labels [set]"
when
source : InputForm ( )
target : Email ( )
sync : SetWire( from == source, to == target )

sf : Label ( eContainer == source )
not ( tf : VisibleThing ( eContainer == target, eval(functions.nameMatches( sf, tf ))) )

eval ( !target.getOverriddenNames().contains(sf.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
Label tf = handler.generatedLabel(sync, target);
handler.setName(tf, sf.getName());
queue.add(tf, drools);

end

/**
* @inference SetWire,InputForm,Email
* An {@model InputForm} connected to a {@model Map} with a {@model SetWire}
* will create a {@model MapPoint} in the target map for every {@model InputTextField} in the
* source form with the same {@model Label#name}.
*/
rule "Refresh mappings between InputForms connected to Maps containing InputTextFields [set]"
when
source : InputForm ( )
target : Map ( )
sync : SetWire( from == source, to == target )

sf : InputTextField ( eContainer == source )
not ( tf : VisibleThing ( eContainer == target, eval(functions.nameMatches( sf, tf ))) )

eval ( !target.getOverriddenNames().contains(sf.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
MapPoint tf = handler.generatedMapPoint(sync, target);
handler.setName(tf, sf.getName());
queue.add(tf, drools);

end


/**
* <strong>Depending on the orientation of a SetWire</strong>,
* SyncWires create InputTextFields; SetWires should create Labels, because they cannot
* be edited.
*
* @inference SetWire,Label
* When a {@model DomainIterator} is connected to an {@model InputForm} by a {@model SetWire},
* {@model Label}s will be generated for its non-generated, non-primary key {@model DomainAttributeInstance}s.
*/
rule "Refresh New Instance Object mappings (except for generated primary keys) when Instance sets a Form: create labels"
when
form : InputForm ( )
iterator : DomainIterator ( )
instance : DomainInstance ( iterator.currentInstance == instance )
sync : SetWire( from == iterator, to == form ) // backwards

originalAttribute : DomainAttribute ( primaryKey == false || isGenerated == false )
attribute : DomainAttributeInstance( eContainer == instance )
ExtendsEdge ( from == attribute, to == originalAttribute )

not ( tf : VisibleThing( eContainer == form, eval(functions.nameMatches( attribute, tf )) ) )

eval ( !form.getOverriddenNames().contains(attribute.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
Label text = handler.generatedLabel(sync, form);
handler.setName(text, attribute.getName());
handler.setType(text, attribute.getType());
queue.add(text, drools);

end

/**
* <strong>Depending on the orientation of a SetWire</strong>,
* SyncWires create InputTextFields; SetWires should create Labels, because they cannot
* be edited.
*
* @inference SetWire,DomainIterator
* When a {@model DomainIterator} is connected to an {@model IteratorList} by a {@model SetWire},
* {@model Label}s will be generated for its non-generated, non-primary key {@model DomainAttributeInstance}s.
*/
rule "Refresh Domain Object mappings (except for generated primary keys) when Instance sets a IteratorList: create labels"
when
form : IteratorList ( )
iterator : DomainIterator ( )
instance : DomainInstance ( iterator.currentInstance == instance )
sync : SetWire( from == iterator, to == form ) // backwards

originalAttribute : DomainAttribute ( primaryKey == false || isGenerated == false )
attribute : DomainAttributeInstance( eContainer == instance )
ExtendsEdge ( from == attribute, to == originalAttribute )

// not extending ANY kind of primary key
eval( functions.notExtendingPrimaryKey( originalAttribute ) )

not ( tf : VisibleThing( eContainer == form, eval(functions.nameMatches( attribute, tf )) ) )

eval ( !form.getOverriddenNames().contains(attribute.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
Label text = handler.generatedLabel(sync, form);
handler.setName(text, attribute.getName());
handler.setType(text, attribute.getType());
queue.add(text, drools);

end

/**
* @inference SetWire,DomainIterator
* When a {@model DomainIterator} is connected to an {@model IteratorList} by a {@model SetWire},
* a {@model Label#visible hidden} {@model Label} will be generated for the {@model DomainAttribute#primaryKey primary key}
* {@model DomainAttributeInstance}.
*/
rule "Refresh Domain Object mappings (primary keys) when Instance sets a IteratorList: create hiddens"
when
form : IteratorList ( )
iterator : DomainIterator ( )
instance : DomainInstance ( iterator.currentInstance == instance )
sync : SetWire( from == iterator, to == form ) // backwards

// only generated primary keys
originalAttribute : DomainAttribute ( primaryKey == true )
attribute : DomainAttributeInstance( eContainer == instance )
ExtendsEdge ( from == attribute, to == originalAttribute )

not ( tf : VisibleThing( eContainer == form, eval(functions.nameMatches( attribute, tf )) ) )

eval ( !form.getOverriddenNames().contains(attribute.getName()) )

eval ( handler.veto( sync ))

then
# create a new Label[visible = false]
Label text = handler.generatedLabel(sync, form);
handler.setName(text, attribute.getName());
handler.setType(text, attribute.getType());
handler.setVisible(text, false);
queue.add(text, drools);

end

/**
* @inference SetWire,DomainIterator
* A {@model SetWire} connecting a {@model DomainIterator} to an {@model InputForm} should only
* execute the 'init' {@model Operation} on the created {@model Label}s when the label is {@model Label#onAccess accessed}
* if the {@model DomainInstance} is {@model Function not empty}.
*/
rule "A SetWire between Attributes passed to a DomainIterator need to check that the attribute exists before initialising (onAccess)"
when
form : VisibleThing ( ) # InputForm, IteratorList
iterator : DomainIterator ( )
instance : DomainInstance ( iterator.currentInstance == instance )

# form -> Iterator
sync : SetWire( from == form, to == iterator )

# the instance is created through a NewInstanceWire
schema : DomainType ( )
domainSource : DomainSource ( )
schemaEdge : SchemaEdge ( from == domainSource, to == schema )

selectEdge : SelectEdge ( from == iterator, to == domainSource )

# contained attribute/field
attribute : DomainAttributeInstance( eContainer == instance )
tf : Label ( eContainer == form )

# Label -> attribute
sync2 : SetWire ( from == tf, to == attribute, overriddenNames not contains "check new instance exists" )

# text field access/init events
access : Event ( tf.onAccess == access )
initOp : Operation ( eContainer == tf, name == "init" )
run : ECARule ( trigger == access, target == initOp )

attributeValue : Value ( attribute.fieldValue == attributeValue )

param : Parameter ( parameterValue == attributeValue, parameterTerm == run )

# 'not empty' condition in the instance
existsCondition : Function ( eContainer == iterator, name == "not empty" )

# but not connected
not (SimpleCondition ( function == existsCondition, conditioned == run ))

eval ( handler.veto( sync2 ))

then
# connect it
SimpleCondition cw = handler.generatedSimpleCondition(sync2, sync2, existsCondition, run);
handler.setName(cw, "check new instance exists");
queue.add(cw, drools);

end

/**
* @inference SetWire,DomainIterator
* A {@model SetWire} connecting a {@model DomainIterator} to an {@model InputForm} should only
* execute the 'update' {@model Operation} on the created {@model Label}s when the label is {@model Label#onChange changed}
* if the {@model DomainInstance} is {@model Function not empty}.
*/
rule "A SetWire between Attributes selected from a DomainIterator need to check that the attribute exists before initialising (onChange)"
when
form : VisibleThing ( ) # InputForm, IteratorList
iterator : DomainIterator ( )
instance : DomainInstance ( iterator.currentInstance == instance )

# Iterator -> Form
sync : SetWire( from == iterator, to == form )

# the instance is created through a NewInstanceWire
schema : DomainType ( )
domainSource : DomainSource ( )
schemaEdge : SchemaEdge ( from == domainSource, to == schema )

selectEdge : SelectEdge ( from == iterator, to == domainSource )

# contained attribute/field
attribute : DomainAttributeInstance( eContainer == instance )
tf : Label ( eContainer == form )

# Attribute -> Label
sync2 : SetWire ( from == attribute, to == tf, overriddenNames not contains "check new instance exists" )

# text field access/init events
onChange : Event ( attribute.onChange == onChange )
initOp : Operation ( eContainer == tf, name == "update" )
run : ECARule ( trigger == onChange, target == initOp )

attributeValue : Value ( attribute.fieldValue == attributeValue )

param : Parameter ( parameterValue == attributeValue, parameterTerm == run )

# 'not empty' condition in the instance
existsCondition : Function ( eContainer == iterator, name == "not empty" )

# but not connected
not (SimpleCondition ( function == existsCondition, conditioned == run ))

eval ( handler.veto( sync2 ))

then
# connect it
SimpleCondition cw = handler.generatedSimpleCondition(sync2, sync2, existsCondition, run);
handler.setName(cw, "check new instance exists");
queue.add(cw, drools);

end

Change log

r3151 by soundasleep on Oct 13, 2011   Diff
additional model completion documentation
fixes
Go to: 
Project members, sign in to write a code review

Older revisions

r3087 by soundasleep on Sep 15, 2011   Diff
improving the grammar and structure of
the model completion rules
documentation
r2985 by soundasleep on Jun 27, 2011   Diff
 issue 263 : updating inference rules
and diagram helpers
r2962 by soundasleep on May 23, 2011   Diff
 issue 261 : removing unused SetWire and
SyncWire rules
All revisions of this file

File info

Size: 45553 bytes, 1188 lines
Powered by Google Project Hosting