activate method
- {bool bLog: false}
inherited
Activate the SamModel
after assert validation.
It asserts that the following is true:
- that the
SamModel
is not in theSE.ss_broken
state. - that the
SamModel
is in theSE.ss_virgin
state. - that at least one state has been defined in
SamState
- that all states in the Enums have been defined.
- that all actions in the Enums have a handler
- that all naps in the
SamState
definitions have a handler - that all next, allow and ignore values the
SamState
definitions are valid (The compiler should also report this).
It then moves the SamModel
into the first DefState
defined in the SamState
by issuing a proposal
to SamModel.present (which may execute a nap function).
Implementation
SamModel activate({bool bLog = false}) {
if (_samState != "${SE.ss_virgin}") return broken("non-virgin activation prohibited");
if (_ss.firstState == null) return broken("activation state not defined");
if (_bDebLog) log("SamModel.activate invoked ${_ss.firstState}");
_ss.ssMap['${SE.ss_virgin}'].next(_ss.firstState);
//_ss.addState('${SE.ss_virgin}').next(_ss.firstState);
// at this point all tables must be complete so we validate what we can
String strErr = "";
for(Object e in _enums) {
RegExpMatch rem = reWhat.firstMatch("$e");
if (rem == null) {
strErr += "$e is not a correct format for the enums table\r\n";
} else {
String what = rem.group(1);
bool bDefRender = _sv.svMap.containsKey("defRender");
switch(what) {
case "ss": if (!_ss.ssMap.containsKey("$e")) strErr += "$e not defined in state mapping table\r\n";
if (!bDefRender && !_sv.svMap.containsKey("$e")) strErr += "$e not defined in view mapping table with no defRender\r\n";
break;
case "sa": if (!_sa.fnMap.containsKey("$e")) strErr += "$e not defined in action mapping table\r\n";
break;
}
//log("validate $e ${e.runtimeType} $what $bDefRender");
}
}
for(DefState ds in _ss.ssMap.values) {
if (ds.strNap != null) {
if (_sa.fnMap[ds.strNap] == null) {
strErr += "${ds.strNap} has no processing function defined\r\n";
} else {
ds.fncNap = _sa.fnMap[ds.strNap];
}
}
if (ds.strNext != null) {
for(String str in ds.strNext.split("/")) {
if (!_ss.ssMap.containsKey(str)) {
strErr += "${ds.strState} next.$str function $str state not defined\r\n";
}
}
}
if (ds.strAllow != null) {
for(String s in ds.strAllow.split("/")) {
if (!_sa.fnMap.containsKey(s)) {
strErr += "${ds.strState} allow.$s function $s not defined\r\n";
}
}
}
if (ds.strIgnore != null) {
for(String s in ds.strIgnore.split("/")) {
if (!_sa.fnMap.containsKey(s)) {
strErr += "${ds.strState} ignore.$s function $s not defined\r\n";
}
}
}
}
if (strErr.length > 0) {
broken(strErr);
return this;
}
this.present(this._samState,_ss.firstState,stepParms:{/*'bLog':true*/});
return this;
}