/
Definitions.xpt
531 lines (443 loc) · 15.4 KB
/
Definitions.xpt
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
«IMPORT iaml»
/**
* Method definitions for accessing Domain objects and attributes.
*/
«EXTENSION template::GeneratorExtensions»
/**
* Expand out all domain object, instance and attribute
* information for this InternetApplication.
*
* Expected to be in PHP mode.
*/
«DEFINE domainDefinitions FOR model::InternetApplication»
«EXPAND domainObjectDefinitions(true)»
«EXPAND domainAttributeDefinitions(true)»
«ENDDEFINE»
/**
* Expand out all domain object instances.
*/
«DEFINE domainObjectDefinitions(Boolean php) FOR model::InternetApplication»
«IF php»
require_once(ROOT_PATH . "domain/all_domain_objects.php");
«ELSE»
<!-- empty -->
«ENDIF»
«ENDDEFINE»
«DEFINE allDomainObjectDefinitions FOR model::InternetApplication»
«FILE "output/domain/all_domain_objects.php"»
<?php
«EXPAND template::Template::phpCheck»
«EXPAND GetDefinitions::getDomainObject FOREACH getRoot().getAllDomainIterators()»
«EXPAND StoreDefinitions::storeDomainObject FOREACH getRoot().getAllDomainIterators()»
«EXPAND IterateDefinitions::iterateDefinitions FOREACH getRoot().getAllDomainIterators()»
«EXPAND domainSchemaDefinition FOREACH getRoot().getAllDomainTypes()»
«EXPAND domainAttributeDefinition FOREACH getRoot().eAllContents.typeSelect(model::domain::DomainAttribute)»
«EXPAND domainSourceDefinition FOREACH getRoot().eAllContents.typeSelect(model::domain::DomainSource)»
«FOREACH sources AS source»
«FOREACH source.outSchemas.to AS schema»
«FOREACH source.inSelects.from AS iterator»
«EXPAND domainIteratorDefinition(schema, source) FOR iterator»
«ENDFOREACH»
«ENDFOREACH»
«ENDFOREACH»
/* role defintions */
«EXPAND domainUserDefinition»
«ENDFILE»
«ENDDEFINE»
/**
* Definitions for DomainSources which also provide User instances.
* @implementation Role
* Currently, we can only have <em>one</em> root {@model Role} in a given
* {@model InternetApplication}.
*/
«DEFINE domainUserDefinition FOR model::InternetApplication»
/**
* Root User Role for Internet Application '«escapeString(name)»'
* TODO Currently we can only have one root User Role in a system
*/
class DomainType_UserRoot extends DomainType {
private function __construct() {
$this->addAttribute(DomainAttribute_UserRoot_ID::getInstance());
// list of permissions: boolean
«FOREACH eAllContents.typeSelect(model::users::Permission) AS p»
$this->addAttribute(Permission_«safeName(p)»::getInstance());
«ENDFOREACH»
$this->table_name = "iaml_user_root";
$this->source_id = $this->table_name . "_id";
}
// the current instance
static $instance = null;
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new DomainType_UserRoot();
}
return self::$instance;
}
}
/**
* Domain Attribute ID for Root User Role in Internet Application '«escapeString(name)»'
*/
class DomainAttribute_UserRoot_ID extends DomainAttribute {
private function __construct() {
$this->isPrimaryKey = true;
$this->type = 'iamlInteger';
$this->name = 'id';
}
// the current instance
static $instance = null;
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new DomainAttribute_UserRoot_ID();
}
return self::$instance;
}
}
class DomainAttribute_UserRole_Link extends DomainAttribute {
private function __construct() {
$this->isPrimaryKey = false;
$this->type = 'iamlInteger';
$this->name = 'root_user_id';
$this->extends = DomainAttribute_UserRoot_ID::getInstance();
}
// the current instance
static $instance = null;
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new DomainAttribute_UserRole_Link();
}
return self::$instance;
}
}
«FOREACH eAllContents.typeSelect(model::users::Permission) AS p»
/**
* Permission '«escapeString(p.name)»' in Internet Application «escapeString(name)»
*/
class Permission_«safeName(p)» extends DomainAttribute {
private function __construct() {
$this->isPrimaryKey = false;
$this->type = 'iamlBoolean';
$this->name = '«safeNameString(p.name)»';
}
// the current instance
static $instance = null;
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new Permission_«safeName(p)»();
}
return self::$instance;
}
}
«ENDFOREACH»
/**
* Permission checks.
*/
«EXPAND template::users::Permissions::permissionChecks»
«ENDDEFINE»
«DEFINE domainSchemaDefinition FOR model::domain::DomainType»
/**
* Domain Schema '«escapeString(name)»'
*/
class DomainType_«safeName()» extends DomainType {
private function __construct() {
«FOREACH eStructuralFeatures.typeSelect(model::domain::DomainAttribute).select(a2|a2.outExtendsEdges.to.typeSelect(model::domain::DomainAttribute).select(a|!a.primaryKey).isEmpty) AS a»
$this->addAttribute(DomainAttribute_«safeName(a)»::getInstance());
«ENDFOREACH»
«IF model::users::Role.isInstance(this)»
«IF eStructuralFeatures.typeSelect(model::domain::DomainAttribute).outExtendsEdges.to.eContainer.typeSelect(model::users::Role).isEmpty»
/* this Role does not extend any other Roles: we need to add a link to the root role */
$this->addAttribute(DomainAttribute_UserRole_Link::getInstance());
«ENDIF»
«ENDIF»
$this->table_name = "«safeNameString(name)»";
$this->source_id = $this->table_name . "_id";
}
// the current instance
static $instance = null;
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new DomainType_«safeName()»();
}
return self::$instance;
}
}
«IF model::users::Role.isInstance(this)»
«FOREACH getRoot().eAllContents.typeSelect(model::domain::DomainSource) AS source»
/**
* A simple DomainIterator to see if a given Role exists for the given root ID.
*/
class HasRole_«safeName()»_«safeName(source)» extends DomainIterator {
var $root_user_id;
private function __construct($root_user_id) {
$this->schema = DomainType_«safeName()»::getInstance();
$this->source = DomainSource_«safeName(source)»::getInstance();
$this->order_by = null;
$this->order_ascending = true;
$this->query = "iaml_user_root.id = :id";
$this->is_new = false;
$this->autosave = false;
$this->limit = 1;
$this->root_user_id = $root_user_id;
}
public function constructArgs() {
return array(
"id" => $this->root_user_id
);
}
public function getOffset() {
return 0;
}
public function setOffset($value) {
throw new IamlDomainException("Cannot set an offset for this Role query: " . get_class($this));
}
public function getNewInstanceID($key) {
throw new IamlDomainException("Cannot get the new instance ID for a non-new object: " . get_class($this));
}
public function setNewInstanceID($key, $value) {
throw new IamlDomainException("Cannot set the new instance ID for a non-new object: " . get_class($this));
}
«EXPAND domainIteratorGetStoredValues FOR this»
// the current instance
static $instance = null;
public static function getInstance($root_user_id) {
if (self::$instance == null) {
self::$instance = new HasRole_«safeName()»_«safeName(source)»($root_user_id);
}
return self::$instance;
}
}
«ENDFOREACH»
«ENDIF»
«ENDDEFINE»
«DEFINE domainAttributeDefinition FOR ecore::EStructuralFeature»
«throwException("domainAttributeDefinition not yet implemented for generic EStructuralFeatures")»
«ENDDEFINE»
«DEFINE domainAttributeDefinition FOR model::domain::DomainAttribute»
«IF !outExtendsEdges.to.typeSelect(model::domain::DomainAttribute).select(a|!a.primaryKey).isEmpty»
/* ignoring DomainAttribute '«escapeString(name)»': it is an extension of a non-primary key (i.e. derived) */
«ELSE»
/**
* Domain Attribute '«escapeString(name)»'
*/
class DomainAttribute_«safeName()» extends DomainAttribute {
private function __construct() {
$this->isPrimaryKey = «primaryKey ? "true" : "false"»;
$this->type = «EXPAND template::operations::Parameters::getTypeURI FOR eType»;
$this->name = "«safeNameString(name)»";
«FOREACH outExtendsEdges AS extends»
$this->extends = DomainAttribute_«safeName(extends.to)»::getInstance();
«ENDFOREACH»
/* TODO is this even necessary?
$this->table_name = "«safeNameString(name)»";
$this->source_id = $this->table_name . "_id";
*/
}
// the current instance
static $instance = null;
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new DomainAttribute_«safeName()»();
}
return self::$instance;
}
}
«ENDIF»
«ENDDEFINE»
«DEFINE domainSourceDefinition FOR model::domain::DomainSource»
/**
* Domain Source for Domain Store '«escapeString(name)»'
*/
class DomainSource_«safeName()» extends DomainSource {
private function __construct() {
$this->schemas = array(
«REM»
The DomainSource API was written with the idea that multiple
DomainIterators can connect to one DomainSource which has one
DomainType; however, without adding an explicit link between
DomainType and DomainIterator in the metamodel, we can't automatically
work out the Schema type of a given DomainIterator.
Thus, we hack DomainSource to always include ALL possible
schemas for the given DomainSource FileReference in all
copies of the schema.
«ENDREM»
«LET getRoot().eAllContents.typeSelect(model::domain::DomainSource)
.select(s|resolveFileReference(s) == resolveFileReference(this) && s.type == type).outSchemas.to AS allSchemas»
«FOREACH allSchemas AS obj»
DomainType_«safeName(obj)»::getInstance(),
«ENDFOREACH»
«ENDLET»
«IF !outSchemas.to.typeSelect(model::users::Role).isEmpty»
/* the root user schema */
DomainType_UserRoot::getInstance(),
«ENDIF»
);
$this->type = '«escapePhpString(type.toString())»';
$this->file = «EXPAND template::domain::Select::getDatabaseStoreString»;
$this->cache = «cache»;
$this->url = '«escapePhpString(url)»';
}
// the current instance
static $instance = null;
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new DomainSource_«safeName()»();
}
return self::$instance;
}
}
«ENDDEFINE»
«DEFINE domainIteratorDefinition(model::domain::DomainType schema, model::domain::DomainSource source) FOR model::domain::DomainIterator»
/**
* Domain Iterator for Domain Iterator '«escapeString(name)»'
*/
class DomainIterator_«safeName()» extends DomainIterator {
«IF query == "new"»
«EXPAND domainIteratorDefNew(schema, source)»
«ELSE»
«EXPAND domainIteratorDefSelect(schema, source)»
«ENDIF»
«EXPAND domainIteratorGetStoredValues FOR this»
// the current instance
static $instance = null;
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new DomainIterator_«safeName()»();
}
return self::$instance;
}
«IF onIterate != null»
/**
* onIterate is defined for this DomainIterator.
*/
public function onIterate() {
«EXPAND template::events::EventCall::callEvent(true) FOR onIterate»
}
«ENDIF»
}
«ENDDEFINE»
«DEFINE domainIteratorSchemas(model::domain::DomainSource source) FOR model::domain::DomainType»
$this->schema = DomainType_«safeName()»::getInstance();
$this->source = DomainSource_«safeName(source)»::getInstance();
«ENDDEFINE»
«DEFINE domainIteratorDefSelect(model::domain::DomainType schema, model::domain::DomainSource source) FOR model::domain::DomainIterator»
// a SelectWire
private function __construct() {
«EXPAND domainIteratorSchemas(source) FOR schema»
«IF orderBy != null»
$this->order_by = DomainAttribute_«safeName(orderBy)»::getInstance();
$this->order_ascending = «orderAscending ? "true" : "false"»;
«ELSE»
$this->order_by = null;
$this->order_ascending = true;
«ENDIF»
$this->query = «EXPAND Select::getQuery»;
$this->is_new = false;
$this->autosave = «autosave ? "true" : "false"»;
$this->limit = «limit»;
}
public function constructArgs() {
return array(«EXPAND template::operations::Parameters::callParameter(true, false, true) FOREACH inParameterEdges SEPARATOR ","»);
}
public function getOffset() {
return get_current_offset_«safeName()»();
}
public function setOffset($value) {
set_current_offset_«safeName()»($value);
}
public function getNewInstanceID($key) {
throw new IamlDomainException("Cannot get the new instance ID for a non-new object: " . get_class($this));
}
public function setNewInstanceID($key, $value) {
throw new IamlDomainException("Cannot set the new instance ID for a non-new object: " . get_class($this));
}
«ENDDEFINE»
«DEFINE domainIteratorDefNew(model::domain::DomainType schema, model::domain::DomainSource source) FOR model::domain::DomainIterator»
// a NewInstanceWire
private function __construct() {
«EXPAND domainIteratorSchemas(source) FOR schema»
$this->order_by = "";
$this->order_ascending = true;
$this->query = "";
$this->is_new = true;
$this->autosave = «autosave ? "true" : "false"»;
}
public function constructArgs() {
return array(
// no args
);
}
public function getOffset() {
throw new IamlDomainException("Cannot get the offset for a new object: " . get_class($this));
}
public function setOffset($value) {
throw new IamlDomainException("Cannot set the offset for a new object: " . get_class($this));
}
public function getNewInstanceID($key) {
return $this->getStoredValue("new_instance_id_$key");
}
public function setNewInstanceID($key, $value) {
$this->setStoredValue("new_instance_id_$key", $value);
}
«ENDDEFINE»
«DEFINE domainIteratorGetStoredValues FOR emf::EObject»
«IF containingSession() != null»
/**
* Note that PHP's <code>is_set()</code> returns <code>false</code> for variables that are set to <code>NULL</code>
*/
public function getStoredValue($key, $default = null) {
$target_key = "stored_value_«safeName()-»_" . $key;
if (has_session($target_key)) {
return require_session($target_key);
}
return $default;
}
public function setStoredValue($key, $value) {
$target_key = "stored_value_«safeName()-»_" . $key;
$_SESSION[$target_key] = $value;
}
«ELSE»
/**
* Note that PHP's <code>is_set()</code> returns <code>false</code> for variables that are set to <code>NULL</code>
*/
public function getStoredValue($key, $default = null) {
$target_key = "stored_value_«safeName()-»_" . $key;
if (get_application_value($target_key, false) !== false) {
return get_application_value($target_key, false);
}
return $default;
}
public function setStoredValue($key, $value) {
$target_key = "stored_value_«safeName()-»_" . $key;
set_application_value($target_key, $value);
}
«ENDIF»
«ENDDEFINE»
/**
* Expand out all domain attribute instances.
*/
«DEFINE domainAttributeDefinitions(Boolean php) FOR model::InternetApplication»
«IF php»
require_once(ROOT_PATH . "domain/all_domain_attributes.php");
«ELSE»
<script language="Javascript" type="application/javascript" src="domain/all_domain_attributes_js.php"></script>
«ENDIF»
«ENDDEFINE»
«DEFINE allDomainAttributeDefinitions FOR model::InternetApplication»
«FILE "output/domain/all_domain_attributes.php"»
<?php
«EXPAND template::Template::phpCheck»
«EXPAND Includes::getInclude FOREACH getAllDomainAttributeInstances()»
«ENDFILE»
«FILE "output/domain/all_domain_attributes_js.php"»
<?php
/**
* This operation needs to be executed by PHP first, to allow
* server-side variables (such as values from databases) to be included.
*/
«EXPAND template::Template::commonHeader("../", "all_domain_attributes (js)")»
«EXPAND template::Template::typeJavascript»
?>
«EXPAND StoreDefinitions::storeDomainAttribute(false) FOREACH getAllDomainAttributeInstances()»
«ENDFILE»
«ENDDEFINE»
«DEFINE exception FOR Object»
«ENDDEFINE»