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
/**
* Creates 'field value' {@model Value}s and the related 'is set' {@model Predicate}.
*/
#created on: 4/11/2008
package org.openiaml.model.drools.rules.base

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

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

rule "Create empty domain schema for 'test' InternetApplication"
when
a : InternetApplication ( name == "test" )
not (DomainType ( name=="test domain schema", eContainer == a ) )

eval ( handler.veto( a ))

then
#actions
// DomainStore ds = (DomainStore) handler.createElement( a, ModelPackage.eINSTANCE.getDomainStore(), ModelPackage.eINSTANCE.getInternetApplication_DomainStores() );
// ds.setIsGenerated(true);
// ds.setGeneratedBy(a);

DomainType ds = handler.generatedDomainType( a, a );
handler.setName(ds, "test domain schema");

queue.add(ds, drools); // possibly infer new knowledge (this is necessary)

# a schema also requires a DomainSource
DomainSource source = handler.generatedDomainSource(a, a);
handler.setName(source, "test domain schema source");
queue.add(source, drools);

SchemaEdge edge = handler.generatedSchemaEdge(a, a, source, ds);
queue.add(edge, drools);

end

/**
* Since an InputForm can not yet support having a fieldValue accessible at
* runtime (although in the future, this could be something like the title
* of the InputForm: TODO), we prevent the fieldValue from even being created
* to prevent a target onAccess.init using a fieldValue that can't ever be
* completed.
*
* <p>A DomainIterator also can not have a fieldValue, because it doesn't make
* any sense at the moment. Both DomainIterator and InputForm should have this
* incorrect inheritance of Changeable removed.
*
* @inference Changeable,Value
* A {@model Changeable}
* contains an untyped {@model Value} named {@model Changeable#fieldValue}.
* @inference Changeable,Value
* If set, the {@model Changeable#defaultValue defaultValue}
* is used as the default value of the created {@model Changeable#fieldValue} {@model Value}.
* @inference InputForm
* {@model InputForm}s do <em>not</em> have a {@model Value}
* named {@model Changeable#fieldValue} created by default.
* @inference DomainIterator
* {@model DomainIterator}s do <em>not</em> have a {@model Value}
* named {@model Changeable#fieldValue} created by default.
*/
rule "Create field value for Changeable (untyped)"
when
f : Changeable( )
not ( InputForm ( this == f ))
not ( DomainIterator ( this == f ))
not (prop : Value( eContainer == f, f.fieldValue != null, f.fieldValue == prop ))

eval ( handler.veto( f ))

then
Value fieldValue = handler.generatedValueFieldValue(f, f);
handler.setName(fieldValue, "fieldValue");
handler.setType(fieldValue, f.getType());
// set default to fieldValue ONLY if fieldValue is set
// (we want to get an error if we try to access an undefined variable)
if (f.getDefaultValue() != null) {
handler.setDefaultValue(fieldValue, f.getDefaultValue());
}

queue.add(fieldValue, drools);

end

/**
* @inference Condition,Value
* All {@model Value}s not {@model Value#name named} 'fieldValue'
* will have an {@model ActivityPredicate} in its container named 'XXX is set'.
*/
rule "Values will also have a related 'is set' condition (not fieldValue)"
when
container : ContainsFunctions ( )
containerGe : GeneratesElements ( this == container )
value : Value ( eContainer == container, name != "fieldValue" )

type : EXSDDataType( definition != null,
definition.name == "boolean" )

not ( Function ( eval(name.equals(value.getName() + " is set")), eContainer == container ))

eval ( handler.veto( containerGe ))

then
ActivityPredicate cond = handler.generatedActivityPredicate(containerGe, container);
handler.setName(cond, value.getName() + " is set");
handler.setType(cond, type);
queue.add(cond, drools);

end

/**
* @inference Condition,Value
* All {@model Value}s {@model Value#name named} 'fieldValue'
* will have a {@model BuiltinProperty} in its container named 'fieldValue is set'.
*/
rule "Values will also have a related 'is set' BuiltinProperty (fieldValue)"
when
container : ContainsFunctions ( )
containerGe : GeneratesElements ( this == container )
value : Value ( eContainer == container, name == "fieldValue" )

type : EXSDDataType( definition != null,
definition.name == "boolean" )

not ( Function ( name == "fieldValue is set", eContainer == container ))

eval ( handler.veto( containerGe ))

then
BuiltinProperty cond = handler.generatedBuiltinProperty(containerGe, container);
handler.setName(cond, "fieldValue is set");
handler.setType(cond, type);
queue.add(cond, drools);

end

/**
* @inference Operation,Value
* All non-{@model Value#readOnly} {@model Value}s, other than those {@model Value#name named} 'fieldValue',
* will have an {@model BuiltinOperation} in its container named 'set XXX'.
*/
rule "Properties will have a related 'set XXX' operation"
when
container : ContainsOperations ( )
containerGe : GeneratesElements ( this == container )
value : Value ( eContainer == container, name != "fieldValue", readOnly == false )

not ( Operation( eval(name.equals("set " + value.getName())), eContainer == container ))

eval ( handler.veto( containerGe ))

then
BuiltinOperation op = handler.generatedBuiltinOperation(containerGe, container);
handler.setName(op, "set " + value.getName());
queue.add(op, drools);

end

/**
* @inference ActivityPredicate
* An {@model ActivityPredicate} named 'XXX is set', used to set a {@model Value#name named} {@model Value},
* will be completed with the necessary {@model ActivityNode}s to implement this functionality.
*/
rule "Create contents of 'X is set' operation"
when
container : ContainsFunctions ( )
value : Value ( eContainer == container )

o : ActivityPredicate( eval(name.equals(value.getName() + " is set")), eContainer == container )

not ( StartNode ( eContainer == o ))

eval ( handler.veto( o ))

then

DecisionNode decision = handler.generatedDecisionNode(o, o);
handler.setName(decision, "is set?");
queue.add(decision, drools);

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

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

CancelNode cancel = handler.generatedCancelNode(o, o);
queue.add(cancel, drools);

ExternalValue ev_value = handler.generatedExternalValue(o, o);
handler.setValue(ev_value, value);
queue.add(ev_value, drools);

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

ExecutionEdge edge1 = handler.generatedExecutionEdge(o, o);
handler.setFrom(edge1, start);
handler.setTo(edge1, decision);
queue.add(edge1, drools);

ExecutionEdge edge2 = handler.generatedExecutionEdge(o, o);
handler.setName(edge2, "yes");
handler.setFrom(edge2, decision);
handler.setTo(edge2, finish);
queue.add(edge2, drools);

ExecutionEdge edge3 = handler.generatedExecutionEdge(o, o);
handler.setName(edge3, "no");
handler.setFrom(edge3, decision);
handler.setTo(edge3, cancel);
queue.add(edge3, drools);

end

Change log

r3147 by soundasleep on Oct 6, 2011   Diff
cleaning up Drools rule package
documentation
Go to: 
Project members, sign in to write a code review

Older revisions

r3101 by soundasleep on Sep 21, 2011   Diff
 issue 277 : updating inference rules
and codegen templates
r3087 by soundasleep on Sep 15, 2011   Diff
improving the grammar and structure of
the model completion rules
documentation
r2997 by soundasleep on Jul 5, 2011   Diff
 issue 268 : updating inference rules
All revisions of this file

File info

Size: 8014 bytes, 230 lines
Powered by Google Project Hosting