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
/**
* Creates the default {@model Operation}s for {@model Changeable} elements, and
* the implementation of certain {@model ActivityOperation}s.
*/
package org.openiaml.model.drools.rules.operations

#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.domain.*;

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

/**
* Issue 210: Create BuiltinOperations rather than ActivityOperations.
* TODO do not create 'update' operation for {@model Value#readOnly} Properties.
*
* @inference VisibleThing,Operation
* All {@model VisibleThing}s (except {@model IteratorList}s and {@model InputForm}s) will contain an {@model Operation} named "update".
*/
rule "Create 'update' operation for VisibleThings"
when
f : VisibleThing( )
not ( IteratorList ( this == f )) # not IteratorLists
not ( InputForm ( this == f )) # not InputForms
not (Operation( eContainer == f, name=="update" ))

eval ( handler.veto( f ))

then
BuiltinOperation operation = handler.generatedBuiltinOperation(f, f);
handler.setName(operation, "update");
queue.add(operation, drools);

end

/**
* @inference DomainAttributeInstance,Operation
* All {@model DomainAttributeInstance}s will contain an {@model Operation} named "update".
*/
rule "Create 'update' operation for domain attribute instance"
when
f : DomainAttributeInstance( )
not (Operation( eContainer == f, name=="update" ))

eval ( handler.veto( f ))

then
BuiltinOperation operation = handler.generatedBuiltinOperation(f, f);
handler.setName(operation, "update");
queue.add(operation, drools);

end

/**
* Issue 210: Create BuiltinOperations rather than ActivityOperations.
*
* @inference VisibleThing
* All {@model VisibleThing}s (except {@model IteratorList}s and {@model InputForm}s) will contain an {@model Operation} named "init".
*/
rule "Create 'init' operation for VisibleThings"
when
f : VisibleThing( )
not ( IteratorList ( this == f )) # not IteratorLists
not ( InputForm ( this == f )) # not InputForms
not (Operation( eContainer == f, name=="init" ))

eval ( handler.veto( f ))

then
BuiltinOperation operation = handler.generatedBuiltinOperation(f, f);
handler.setName(operation, "init");
queue.add(operation, drools);

end

/**
* @inference SetWire,Value,Operation
* An {@model Operation} 'set value XXX' is created in the container of all {@model Value}s
* that are the target of {@model SetWire}s.
*/
rule "Create 'set value XXX' Operation for all Properties, except fieldValue"
when
container : ContainsOperations ( )
gen : GeneratesElements ( this == container )
p : Value ( eContainer == container, name != "fieldValue" )

exists ( setWire : SetWire ( to == p ) )

not ( op : Operation ( eContainer == container, name != null, eval( ("set value " + p.getName()).equals(op.getName()) ) ) )

eval ( handler.veto( gen ))

then
ActivityOperation op = handler.generatedActivityOperation(gen, container);
handler.setName(op, "set value " + p.getName());
queue.add(op, drools);

end

/**
* @inference Changeable,ActivityOperation
* An empty {@model ActivityOperation} named "update", "refresh" or "init", contained within a
* {@model Changeable}, will be completed with {@model ActivityNode}s to implement
* the particular operation.
*/
rule "Create components of 'update', 'refresh', 'init' operations"
when
c : Changeable ( )
o : ActivityOperation((name == "update" || name == "refresh" || name == "init"), eContainer == c)
field : Value( c.fieldValue == field )

not ( StartNode ( eContainer == o ))

eval ( handler.veto( o ))

then
ActivityParameter parameter = handler.generatedActivityParameter(o, o);
handler.setName(parameter, "setValueTo");
queue.add(parameter, drools);

ExternalValue ev_field = handler.generatedExternalValue(o, o);
handler.setValue(ev_field, field);
queue.add(ev_field, drools);

// need to add 'cast' node
CastNode cast = handler.generatedCastNode(o, o);
queue.add(cast, drools);

DecisionNode check = handler.generatedDecisionNode(o, o);
handler.setName(check, "can cast?");
queue.add(check, drools);

DataFlowEdge castIn = handler.generatedDataFlowEdge(o, o, parameter, cast);
queue.add(castIn, drools);

DataFlowEdge castOut = handler.generatedDataFlowEdge(o, o, cast, ev_field);
queue.add(castOut, drools);

DataFlowEdge castCheck = handler.generatedDataFlowEdge(o, o, cast, check);
queue.add(castCheck, drools);

CancelNode cancel = handler.generatedCancelNode(o, o);
handler.setExceptionText(cancel, "Could not cast successfully.");
queue.add(cancel, drools);
// end add 'cast' node

SetNode op = handler.generatedSetNode(o, o);
queue.add(op, drools);

StartNode start = handler.generatedStartNode(o, o);
queue.add(start, drools);

FinishNode finish = handler.generatedFinishNode(o, o);
queue.add(finish, drools);

DataFlowEdge data1 = handler.generatedDataFlowEdge(o, o);
handler.setFrom(data1, cast);
handler.setTo(data1, op);
queue.add(data1, drools);

DataFlowEdge data2 = handler.generatedDataFlowEdge(o, o);
handler.setFrom(data2, op);
handler.setTo(data2, ev_field);
queue.add(data2, drools);

ExecutionEdge edge1 = handler.generatedExecutionEdge(o, o, start, check);
queue.add(edge1, drools);

ExecutionEdge checkFail = handler.generatedExecutionEdge(o, o, check, cancel);
handler.setName(checkFail, "no");
queue.add(checkFail, drools);

ExecutionEdge checkPass = handler.generatedExecutionEdge(o, o, check, op);
handler.setName(checkPass, "yes");
queue.add(checkPass, drools);

ExecutionEdge edge2 = handler.generatedExecutionEdge(o, o, op, finish);
queue.add(edge2, drools);

end

/**
* @inference Changeable,ActivityOperation,Value
* An empty {@model ActivityOperation} named "set value XXX", contained within a
* {@model Changeable}, used to set a {@model Value} other than {@model Changeable#fieldValue},
* will be completed with {@model ActivityNode}s to implement
* the particular operation.
*/
rule "Create components of 'set value XXX' operations"
when
container : ContainsOperations ( )
field : Value ( eContainer == container, name != "fieldValue" )

o : ActivityOperation ( eContainer == container, name != null, eval( ("set value " + field.getName()).equals(o.getName()) ) )

not ( StartNode ( eContainer == o ))

eval ( handler.veto( o ))

then
ActivityParameter parameter = handler.generatedActivityParameter(o, o);
handler.setName(parameter, "setValueTo");
queue.add(parameter, drools);

ExternalValue ev_field = handler.generatedExternalValue(o, o);
handler.setValue(ev_field, field);
queue.add(ev_field, drools);

// need to add 'cast' node
CastNode cast = handler.generatedCastNode(o, o);
queue.add(cast, drools);

DecisionNode check = handler.generatedDecisionNode(o, o);
handler.setName(check, "can cast?");
queue.add(check, drools);

DataFlowEdge castIn = handler.generatedDataFlowEdge(o, o, parameter, cast);
queue.add(castIn, drools);

DataFlowEdge castOut = handler.generatedDataFlowEdge(o, o, cast, ev_field);
queue.add(castOut, drools);

DataFlowEdge castCheck = handler.generatedDataFlowEdge(o, o, cast, check);
queue.add(castCheck, drools);

CancelNode cancel = handler.generatedCancelNode(o, o);
handler.setExceptionText(cancel, "Could not cast successfully.");
queue.add(cancel, drools);
// end add 'cast' node

SetNode op = handler.generatedSetNode(o, o);
queue.add(op, drools);

StartNode start = handler.generatedStartNode(o, o);
queue.add(start, drools);

FinishNode finish = handler.generatedFinishNode(o, o);
queue.add(finish, drools);

DataFlowEdge data1 = handler.generatedDataFlowEdge(o, o);
handler.setFrom(data1, cast);
handler.setTo(data1, op);
queue.add(data1, drools);

DataFlowEdge data2 = handler.generatedDataFlowEdge(o, o);
handler.setFrom(data2, op);
handler.setTo(data2, ev_field);
queue.add(data2, drools);

ExecutionEdge edge1 = handler.generatedExecutionEdge(o, o, start, check);
queue.add(edge1, drools);

ExecutionEdge checkFail = handler.generatedExecutionEdge(o, o, check, cancel);
handler.setName(checkFail, "no");
queue.add(checkFail, drools);

ExecutionEdge checkPass = handler.generatedExecutionEdge(o, o, check, op);
handler.setName(checkPass, "yes");
queue.add(checkPass, drools);

ExecutionEdge edge2 = handler.generatedExecutionEdge(o, o, op, finish);
queue.add(edge2, drools);

end

Change log

r3153 by soundasleep on Oct 13, 2011   Diff
more minor changes to rule documentation
Go to: 
Project members, sign in to write a code review

Older revisions

r3147 by soundasleep on Oct 6, 2011   Diff
cleaning up Drools rule package
documentation
r3101 by soundasleep on Sep 21, 2011   Diff
 issue 277 : updating inference rules
and codegen templates
r2948 by soundasleep on May 19, 2011   Diff
some simple substitutions to remove
reference to old Property type
All revisions of this file

File info

Size: 9212 bytes, 274 lines
Powered by Google Project Hosting