Browse Source

Convert plugins to modules.

Bentley James Oakes 7 years ago
parent
commit
c7361bf7f6

+ 1 - 2
__worker.js

@@ -517,8 +517,7 @@ process.on('message',
 							throw 'invalid plugin filename, see user\'s manual';
 
 						p = p.match(/(.*)\.js$/)[1];
-						_plugins[p] = eval(
-							'('+_fs.readFileSync('./plugins/'+p+'.js','utf8')+')');
+						_plugins[p] = require('./plugins/' + p);
 						if( ! ('interfaces' in _plugins[p]) ||
 							 ! ('csworker' in _plugins[p])  ||
 							 ! ('asworker' in _plugins[p]) )

+ 12 - 2
plugins/chat.js

@@ -1,6 +1,16 @@
 /* Chat plugin for collaboration, need to list available users.
 , and notify when the message comes in by flashing chat "Open" link*/
-{
+const {
+    __errorContinuable,
+    __httpReq,
+    __wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+module.exports = {
 	'interfaces'	: [{'method':'POST', 'url=':'/chat'}],
 
 
@@ -40,4 +50,4 @@
 				 'respIndex':resp});
 			
 		}
-}
+};

+ 20 - 4
plugins/codegenerator.js

@@ -1,4 +1,20 @@
-{
+const {
+    __errorContinuable,
+    __httpReq,
+	__wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+const _utils = require('../utils');
+const _mmmk = require("../mmmk");
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+const _fspp	= _do.convert(require('../___fs++'), ['mkdirs']);
+
+module.exports = {
 	'interfaces'	: [{'method':'POST', 'url=':'/generatecode'}],
 
 	'csworker'		: 
@@ -56,7 +72,7 @@
 								if (possibleRoots.size > 1) {
 									 __postInternalErrorMsg(resp,"There can only be 1 root, found " + possibleRoots.size);
 								} else {
-									function generateFolder(key, prefix) {
+									let generateFolder = function(key, prefix) {
 										var dir = prefix + as.nodes[key]['name']['value'] + '/';
 										writeActions = _fspp.mkdirs(dir);
 										_do.chain(writeActions)(
@@ -70,7 +86,7 @@
 										for (var subFolder in subFolders[key]) {
 											generateFolder(subFolders[key][subFolder], dir);
 										}
-									}
+									};
 									generateFolder(possibleRoots[0], './generated_code/' + reqData['root'] + '/');
 									__postMessage({'statusCode':200,
 												   'respIndex':resp});
@@ -93,4 +109,4 @@
 				{'statusCode':200,
 					 'respIndex':resp});	
 		}
-}
+};

+ 21 - 5
plugins/exportM2Ecore.js

@@ -1,4 +1,20 @@
-{
+const {
+    __errorContinuable,
+    __httpReq,
+    __wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+const _utils = require('../utils');
+const _mmmk = require("../mmmk");
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+const _fspp	= _do.convert(require('../___fs++'), ['mkdirs']);
+
+module.exports = {
     'interfaces'
 :
     [{'method': 'POST', 'url=': '/exportM2Ecore'}],
@@ -270,8 +286,8 @@
                             for (var i = 0; i < listContained.length; i++) {
                                 contained += space(deep + 2) + '<' + listContained[i].linkType;
                                 var attributes = '';
-                                if (listContained[i].attributes != null) {
-                                }
+                                // if (listContained[i].attributes != null) {
+                                // }
                                 contained += writeAttributes(listContained[i], deep + 2);
                                 if (listContained[i].contain.length > 0)
                                     contained += writeContained(listContained[i].contain, deep + 2);
@@ -385,7 +401,7 @@
             function (err) {
                 __postInternalErrorMsg(resp, err);
             }
-        )
+        );
     }
 
 ,
@@ -399,4 +415,4 @@
                 'respIndex': resp
             });
     }
-}
+};

+ 20 - 4
plugins/exportMM2Ecore.js

@@ -1,4 +1,20 @@
-{
+const {
+    __errorContinuable,
+    __httpReq,
+    __wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+const _utils = require('../utils');
+const _mmmk = require("../mmmk");
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+const _fspp	= _do.convert(require('../___fs++'), ['mkdirs']);
+
+module.exports = {
     'interfaces'
 :
     [{'method': 'POST', 'url=': '/exportMM2Ecore'}],
@@ -58,7 +74,7 @@
                             'float': 'EFloat',
                             'boolean': 'EBoolean',
                             'code': 'EString'
-                        }
+                        };
 
 
                         /**
@@ -602,7 +618,7 @@
             function (err) {
                 __postInternalErrorMsg(resp, err);
             }
-        )
+        );
     }
 
 ,
@@ -616,4 +632,4 @@
                 'respIndex': resp
             });
     }
-}
+};

+ 25 - 10
plugins/exportmmtomd.js

@@ -1,4 +1,19 @@
-{	
+const {
+    __errorContinuable,
+    __httpReq,
+	__wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+const _utils = require('../utils');
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+const _fspp	= _do.convert(require('../___fs++'), ['mkdirs']);
+
+module.exports = {
 	'interfaces': [{'method':'POST', 'url=':'/exportmmtomd'}],
 	'csworker':
 		function(resp, method, uri, reqData, wcontext) {
@@ -84,7 +99,7 @@
 								} else {
 									edges[as.edges[i].dest] = ([as.edges[i].src, as.edges[i + 1].dest]);
 								}
-							};
+							}
 							// Add superclass Link to all Edges (this is class is not present in AToMPM thus not contained in as.nodes)
 							for (var key in as.nodes) {
 								// console.log(key);
@@ -94,12 +109,12 @@
 								}
 							}
 							
-							file_contents += 'Model ' + reqData['name'] + ' {\n'
+							file_contents += 'Model ' + reqData['name'] + ' {\n';
 							
 							var sorted_nodes = [];
 							var sorted_edges = [];
 							var nodes_no_superclasses = [];
-							var c_to_superclass = {}
+							var c_to_superclass = {};
 							// copy superclasses dictionary
 							for (var key in superclasses_ids) {
 								c_to_superclass[key] = superclasses_ids[key].slice(0);
@@ -119,7 +134,7 @@
 							// get all nodes without any superclasses
 							for (var key in as.nodes) {
 								if (!(key in superclasses_ids)) {
-									nodes_no_superclasses.push(key)
+									nodes_no_superclasses.push(key);
 								}
 							}
 							// topological sort
@@ -211,7 +226,7 @@
 									'list<double>': 'double[*]',
 									'list<real>': 'double[*]',
 									'code': 'String'
-									}
+									};
 									
 									// DEPRECATED: No longer needed after adding the Link Node
 									// if (key in edges) {
@@ -224,8 +239,8 @@
 										file_contents += node.attributes['value'][prop].name + ':' + (t in typemapping ? typemapping[t] : t) + (node.attributes['value'][prop]['default'] != '' ?  ' = ' + (t.search('list') >= 0 ? '[' : '') + node.attributes['value'][prop]['default'] + (t.search('list') >= 0 ? ']' : '') : '') + ';\n';
 									}
 									file_contents += '}\n';	
-								};
-							};
+								}
+							}
 							file_contents += '}\n';
 							_fs.writeFileSync('./exported_to_md/' + reqData['name'] + '.mdepth', file_contents);
 							__postMessage({	'statusCode': 200,
@@ -235,7 +250,7 @@
 					);					
 				},
 				function(err) {__postInternalErrorMsg(resp, err);}
-			)
+			);
 		},
 	'asworker':
 		function(resp, method, uri, reqData, wcontext)
@@ -244,4 +259,4 @@
 				{'statusCode': 200,
 					 'respIndex': resp});	
 		}
-}
+};

+ 25 - 10
plugins/exportmtomd.js

@@ -1,4 +1,19 @@
-{
+const {
+    __errorContinuable,
+    __httpReq,
+	__wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+const _utils = require('../utils');
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+const _fspp	= _do.convert(require('../___fs++'), ['mkdirs']);
+
+module.exports = {
 	
 	'interfaces': [{'method':'POST', 'url=':'/exportmtomd'}],
 	'csworker':
@@ -81,7 +96,7 @@
 							// Import extra metamodels
 							for (var i = mms.length - 1; i >= 0; i--) {
 								file_contents += 'load "' + extract_md_type(mms[i]) + '"\n';
-							};
+							}
 							// FIX: Define an auxiliary metamodel which imports all other metamodels and is then instantiated by the main model
 							var mm = extract_md_type(mms[0]);
 							var modelName = reqData['name'];
@@ -89,16 +104,16 @@
 							file_contents += '\nModel ' + mm + ' imports ';
 							for (var i = 0; i < mms.length - 1; i++) {
 								file_contents += extract_md_type(mms[i]) + ', ';
-							};
-							file_contents += extract_md_type(mms[mms.length - 1])
+							}
+							file_contents += extract_md_type(mms[mms.length - 1]);
 							file_contents += ' {} \n\n';
 							var edges = {};
 							for (var i = 0; i < as.edges.length; i += 2) {
 								if (as.edges[i].dest != as.edges[i + 1].src) console.error('The source and destination of the edge are different!');
 								edges[as.edges[i].dest] = ([as.edges[i].src, as.edges[i + 1].dest]);
-							};
+							}
 							// Model definition
-							file_contents += mm + ' ' + modelName + ' {\n'
+							file_contents += mm + ' ' + modelName + ' {\n';
 							// console.log('------------');
 							// console.log(as.nodes);
 							// console.log('------------');
@@ -168,8 +183,8 @@
 									}
 									file_contents += '}\n';
 								// }
-							};
-							file_contents += '}\n'
+							}
+							file_contents += '}\n';
 							_fs.writeFileSync('./exported_to_md/' + reqData['name'] + '.mdepth', file_contents);
 							__postMessage({	'statusCode': 200,
 											'respIndex': resp});
@@ -178,7 +193,7 @@
 					);					
 				},
 				function(err) {__postInternalErrorMsg(resp, err);}
-			)
+			);
 		},
 	'asworker':
 		function(resp, method, uri, reqData, wcontext)
@@ -187,4 +202,4 @@
 				{'statusCode': 200,
 					 'respIndex': resp});	
 		}
-}
+};

+ 27 - 11
plugins/exportpnml.js

@@ -1,5 +1,21 @@
 /* a simple hello world plugin... it listens for "POST /hello" requests... requests are received by "csworker" and forwarded to "asworker"... both respond with their __worker\'s id and with a counter of the number of handled requests */
-{
+const {
+    __errorContinuable,
+    __httpReq,
+	__wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+const _utils = require('../utils');
+const _mmmk = require("../mmmk");
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+const _fspp	= _do.convert(require('../___fs++'), ['mkdirs']);
+
+module.exports = {
 	'interfaces'	: [{'method':'POST', 'url=':'/pnml'}],
 
 
@@ -34,7 +50,7 @@
 								var cs = _utils.jsonp(res);
 								var as = _utils.jsonp(asdata['data']);
 								
-								function addPlace(name,id,x,y,initial) {
+								let addPlace = function(name,id,x,y,initial) {
 									var file='<place id="'+id+'">\n';
 									file+='<name>\n';
 								    file +='<text>"'+name+'"</text>\n';
@@ -48,22 +64,22 @@
     							    }
                                     file+='</place>\n';
                                     return file;
-								}
-								function addTrans(name,id,x,y) {
+								};
+								let addTrans = function(name,id,x,y) {
 									var file='<transition id="'+id+'">\n <name> <text>'+name+'</text>\n';
 									file+='<graphics>   <offset x="22" y="-14"/>  </graphics>\n';
                                    file+='</name>\n<graphics> <position x="'+x+'" y="'+y+'"/></graphics>\n</transition>\n';
                                    return file;
-								}
-								function addArc(from,to) {
+								};
+								let addArc = function(from,to) {
 									var file='<arc id="'+from+to+'" source="'+from+'" target="'+to+'">\n';
                                     file+='<inscription> <text>1</text> </inscription> </arc>\n';
                                     return file;
-								}
+								};
 								var mData = {
 										'csm':_utils.jsonp(res),
 										'asm':_utils.jsonp(asdata['data'])},
-									 path  = reqData['fname']
+									 path  = reqData['fname'];
 									 dir	 = _path.dirname(path).replace(/"/g,'\\"'),
 									 
 									 writeActions = 
@@ -78,7 +94,7 @@
 											    var x=0;
 											    var y=0;
 											    var initial = 0;
-											    var name = ''
+											    var name = '';
 											    var tokens =  0;
 												if (as.nodes[key]['$type'].indexOf('Transition') != -1) {
 													x = cs.nodes[key]['position']['value'][0];
@@ -117,7 +133,7 @@
 										  _fs.write(fd,head);
 										  _fs.close(fd);
 											});
-											 return true
+											 return true;
 										 }];
 								_do.chain(writeActions)(
 									function()
@@ -151,4 +167,4 @@
 					 'sequence#':__sequenceNumber(),
 					 'respIndex':resp});
 		}
-}
+};

+ 85 - 70
plugins/exporttoppdevs.js

@@ -1,4 +1,19 @@
-{
+const {
+    __errorContinuable,
+    __httpReq,
+	__wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+const _utils = require('../utils');
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+const _fspp	= _do.convert(require('../___fs++'), ['mkdirs']);
+
+module.exports = {
 	
 	'interfaces': [{'method':'POST', 'url=':'/exportmtoppdevs'}],
 	'csworker':
@@ -16,11 +31,11 @@
 								incoming = {},
 								outgoing = {};
 							
-							file_contents += 'import sys\n'
-							file_contents += 'sys.path.append("../../pypdevs/src/")\n\n'
-							file_contents += 'from DEVS import *\n'
-							file_contents += 'from infinity import INFINITY\n'
-							file_contents += 'from util import *\n\n'
+							file_contents += 'import sys\n';
+							file_contents += 'sys.path.append("../../pypdevs/src/")\n\n';
+							file_contents += 'from DEVS import *\n';
+							file_contents += 'from infinity import INFINITY\n';
+							file_contents += 'from util import *\n\n';
 							
 							for (var key in as.nodes) {
 								var node = as.nodes[key];
@@ -47,14 +62,14 @@
 									for (var e_key in as.edges) {
 										var e = as.edges[e_key];
 										if (e['dest'] == key) {
-											safe_add(incoming[key], e['src'])
+											safe_add(incoming[key], e['src']);
 											if (!(e['src'] in outgoing)) {
 												outgoing[e['src']] = [];
 											}
 											safe_add(outgoing[e['src']], key);
 										}
 										if (e['src'] == key) {
-											safe_add(outgoing[key], e['dest'])
+											safe_add(outgoing[key], e['dest']);
 											if (!(e['dest'] in incoming)) {
 												incoming[e['dest']] = [];
 											}
@@ -75,64 +90,64 @@
 							
 							for (var key in type_map['/Formalisms/ParallelDEVS/ParallelDEVS/StateDefinition']) {
 								var node = type_map['/Formalisms/ParallelDEVS/ParallelDEVS/StateDefinition'][key],
-									list_of_params = ['name=""'].concat(node['parameters']['value'].map(function(el) {return el['name'] + '=None'})),
-									list_of_param_names = ['name'].concat(node['parameters']['value'].map(function(el) {return el['name']})),
-									list_of_attrs = [['name', '']].concat(node['attributes']['value'].map(function(el) {return [el['name'], el['default']]}));
+									list_of_params = ['name=""'].concat(node['parameters']['value'].map(function(el) {return el['name'] + '=None';})),
+									list_of_param_names = ['name'].concat(node['parameters']['value'].map(function(el) {return el['name'];})),
+									list_of_attrs = [['name', '']].concat(node['attributes']['value'].map(function(el) {return [el['name'], el['default']];}));
 								file_contents += 'class ' + node['name']['value'] + ':\n';
 								file_contents += '\tdef __init__(self, ' + list_of_params.join(', ') + '):\n';
-                                file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1])}).join('\n') + "\n";
-                                file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line}).join('\n');
+                                file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1]);}).join('\n') + "\n";
+                                file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line;}).join('\n');
 								file_contents += '\n\n';
 							}
 							
 							for (var key in type_map['/Formalisms/ParallelDEVS/ParallelDEVS/Event']) {
 								var node = type_map['/Formalisms/ParallelDEVS/ParallelDEVS/Event'][key],
-									list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None'})),
-									list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name']})),
-									list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']]}));
+									list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None';})),
+									list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name'];})),
+									list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']];}));
 								file_contents += 'class ' + node['name']['value'] + ':\n';
 								file_contents += '\tdef __init__(self, ' + list_of_params.join(', ') + '):\n';
-								file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1])}).join('\n') + "\n";
-                                file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line}).join('\n');
+								file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1]);}).join('\n') + "\n";
+                                file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line;}).join('\n');
 								file_contents += '\n\n';
 								file_contents += '\tdef __str__(self):\n';
-								file_contents += '\t\treturn "' + node['name']['value'] + '(" + ' + list_of_attrs.map(function(el) {return 'str(self.' + el[0] + ')'}).join(' + ", " + ') + ' + ")"';
+								file_contents += '\t\treturn "' + node['name']['value'] + '(" + ' + list_of_attrs.map(function(el) {return 'str(self.' + el[0] + ')';}).join(' + ", " + ') + ' + ")"';
 								file_contents += '\n\n';
 							}
 							
 							for (var idx in type_map['/Formalisms/ParallelDEVS/ParallelDEVS/AtomicDEVS']) {
 								var node = type_map['/Formalisms/ParallelDEVS/ParallelDEVS/AtomicDEVS'][idx],
-									list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None'})),
-									list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name']})),
-									list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']]}));
+									list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None';})),
+									list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name'];})),
+									list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']];}));
 								file_contents += 'class ' + node['name']['value'] + '(AtomicDEVS):\n';
 								file_contents += '\tdef __init__(' + (['self', 'name="' + node['name']['value'] + '"'].concat(list_of_params).join(', ')) + '):\n';
 								file_contents += '\t\tAtomicDEVS.__init__(self, name)\n';
-								file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] + ' if ' + el[0] + ' is not None else ' + el[1] : el[1])}).join('\n');
+								file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] + ' if ' + el[0] + ' is not None else ' + el[1] : el[1]);}).join('\n');
 								file_contents += '\n';
 								key = type_map_keys['/Formalisms/ParallelDEVS/ParallelDEVS/AtomicDEVS'][idx];
-								statedef = as.nodes[outgoing[outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/statedef'})[0]][0]];
-								states = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/states'}).map(function(statesid) {return outgoing[statesid][0]}).map(function(sid) {return as.nodes[sid]});
-								defstate = states.filter(function(el) {return el['initial']['value']})[0]
-								list_of_assigns = ['name="' + defstate['name']['value'] + '"'].concat(statedef['initial_binding']['value'].map(function(el) {return el['name'] + '=' + el['val']}))
+								statedef = as.nodes[outgoing[outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/statedef';})[0]][0]];
+								states = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/states';}).map(function(statesid) {return outgoing[statesid][0];}).map(function(sid) {return as.nodes[sid];});
+								defstate = states.filter(function(el) {return el['initial']['value'];})[0];
+								list_of_assigns = ['name="' + defstate['name']['value'] + '"'].concat(statedef['initial_binding']['value'].map(function(el) {return el['name'] + '=' + el['val'];}));
 								file_contents += '\t\tself.state = ' + statedef['name']['value'] + '(' + list_of_assigns.join(', ') + ')\n';
-                                file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line}).join('\n') + "\n";
-								ports = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports'}).map(function(portsid) {return outgoing[portsid][0]}).map(function(pid) {return as.nodes[pid]});
-								file_contents += '\t\tself.my_ports = {' + ports.map(function(el) {return '"' + el['name']['value'] + '": ' + (el['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/OutputPort' ? 'self.addOutPort("' : 'self.addInPort("') + el['name']['value'] + '")'}).join(', ') + '}\n\n'
-								file_contents += '\tdef timeAdvance(self):\n'
-								file_contents += states.map(function(s) {return '\t\tif self.state.name == "' + s['name']['value'] + '":\n' + s['time_advance']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n')}).join('\n')
+                                file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line;}).join('\n') + "\n";
+								ports = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports';}).map(function(portsid) {return outgoing[portsid][0];}).map(function(pid) {return as.nodes[pid];});
+								file_contents += '\t\tself.my_ports = {' + ports.map(function(el) {return '"' + el['name']['value'] + '": ' + (el['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/OutputPort' ? 'self.addOutPort("' : 'self.addInPort("') + el['name']['value'] + '")';}).join(', ') + '}\n\n';
+								file_contents += '\tdef timeAdvance(self):\n';
+								file_contents += states.map(function(s) {return '\t\tif self.state.name == "' + s['name']['value'] + '":\n' + s['time_advance']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');}).join('\n');
 								file_contents += '\n\n';
-								file_contents += '\tdef outputFnc(self):\n'
-                                file_contents += '\t\tdef subfunc(self):\n'
-                                file_contents += states.map(function(s) {return '\t\t\tif self.state.name == "' + s['name']['value'] + '":\n' + (s['output']['value'] == '' ? ['\t\t\t\treturn {}'] : s['output']['value'].split('\n').map(function(line) {return '\t\t\t\t' + line}).join('\n'))}).join('\n') + "\n";
+								file_contents += '\tdef outputFnc(self):\n';
+                                file_contents += '\t\tdef subfunc(self):\n';
+                                file_contents += states.map(function(s) {return '\t\t\tif self.state.name == "' + s['name']['value'] + '":\n' + (s['output']['value'] == '' ? ['\t\t\t\treturn {}'] : s['output']['value'].split('\n').map(function(line) {return '\t\t\t\t' + line;}).join('\n'));}).join('\n') + "\n";
                                 file_contents += '\t\treturn {self.my_ports[k]: v for k, v in subfunc(self).iteritems()}\n';
 								file_contents += '\n\n';
-								file_contents += '\tdef intTransition(self):\n'
+								file_contents += '\tdef intTransition(self):\n';
 								var content = false;
 								for (var sidx in states) {
 									s = states[sidx];
 									if (outgoing[s['$key']]) {
-										internals = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/InternalTransition'}).map(function(tid) {return as.nodes[tid]});
+										internals = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/InternalTransition';}).map(function(tid) {return as.nodes[tid];});
 										for (var iidx in internals) {
 											content = true;
 											internal = internals[iidx];
@@ -140,9 +155,9 @@
 												cond_name = 'cond_int_' + s['name']['value'] + '_to_' + target['name']['value'],
 												action_name = 'action_int_' + s['name']['value'] + '_to_' + target['name']['value'];
 											file_contents += '\t\t\def ' + cond_name + '():\n';
-											file_contents += internal['condition']['value'] == '' ? '\t\t\treturn True' : internal['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
+											file_contents += internal['condition']['value'] == '' ? '\t\t\treturn True' : internal['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
 											file_contents += '\n\t\t\def ' + action_name + '():\n';
-											file_contents += internal['action']['value'] == '' ? '\t\t\treturn {}' : internal['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
+											file_contents += internal['action']['value'] == '' ? '\t\t\treturn {}' : internal['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
 											file_contents += '\n\t\tif self.state.name == "' + s['name']['value'] + '" and ' + cond_name + '():\n';
 											file_contents += '\t\t\treturn ' + statedef['name']['value'] + '(name="' + target['name']['value'] + '", **' + action_name + '())\n\n';
 										}
@@ -155,23 +170,23 @@
 									file_contents += '\t\t\treturn AtomicDEVS.intTransition(self)\n';
 								}
 								file_contents += '\n';
-								file_contents += '\tdef extTransition(self, my_inputs):\n'
-								file_contents += '\t\tinputs = {k.getPortName(): v for k, v in my_inputs.iteritems()}\n'
+								file_contents += '\tdef extTransition(self, my_inputs):\n';
+								file_contents += '\t\tinputs = {k.getPortName(): v for k, v in my_inputs.iteritems()}\n';
 								content = false;
 								for (var sidx in states) {
 									s = states[sidx];
 									if (outgoing[s['$key']]) {
-										externals = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ExternalTransition'}).map(function(tid) {return as.nodes[tid]});
+										let externals = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ExternalTransition';}).map(function(tid) {return as.nodes[tid];});
 										for (var iidx in externals) {
 											content  = true;
-											external = externals[iidx];
-											var target = as.nodes[outgoing[external['$key']][0]],
+											let extern = externals[iidx];
+											var target = as.nodes[outgoing[extern['$key']][0]],
 												cond_name = 'cond_ext_' + s['name']['value'] + '_to_' + target['name']['value'],
 												action_name = 'action_ext_' + s['name']['value'] + '_to_' + target['name']['value'];
 											file_contents += '\t\t\def ' + cond_name + '():\n';
-											file_contents += external['condition']['value'] == '' ? '\t\t\treturn True' : external['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
+											file_contents += extern['condition']['value'] == '' ? '\t\t\treturn True' : extern['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
 											file_contents += '\n\t\t\def ' + action_name + '():\n';
-											file_contents += external['action']['value'] == '' ? '\t\t\treturn {}' : external['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
+											file_contents += extern['action']['value'] == '' ? '\t\t\treturn {}' : extern['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
 											file_contents += '\n\t\tif self.state.name == "' + s['name']['value'] + '" and ' + cond_name + '():\n';
 											file_contents += '\t\t\treturn ' + statedef['name']['value'] + '(name="' + target['name']['value'] + '", **' + action_name + '())\n\n';
 										}
@@ -183,13 +198,13 @@
 									file_contents += '\t\telse:\n';
 									file_contents += '\t\t\treturn AtomicDEVS.extTransition(self, my_inputs)\n';
 								}
-								file_contents += '\n'
-								file_contents += '\tdef confTransition(self, my_inputs):\n'
-								file_contents += '\t\tinputs = {k.getPortName(): v for k, v in my_inputs.iteritems()}\n'
+								file_contents += '\n';
+								file_contents += '\tdef confTransition(self, my_inputs):\n';
+								file_contents += '\t\tinputs = {k.getPortName(): v for k, v in my_inputs.iteritems()}\n';
 								content = false;
 								for (var sidx in states) {
 									s = states[sidx];
-									confluents = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ConfluentTransition'}).map(function(tid) {return as.nodes[tid]});
+									confluents = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ConfluentTransition';}).map(function(tid) {return as.nodes[tid];});
 									for (var iidx in confluents) {
 										content  = true;
 										confluent = confluents[iidx];
@@ -197,9 +212,9 @@
 											cond_name = 'cond_conf_' + s['name']['value'] + '_to_' + target['name']['value'],
 											action_name = 'action_conf_' + s['name']['value'] + '_to_' + target['name']['value'];
 										file_contents += '\t\t\def ' + cond_name + '():\n';
-										file_contents += confluent['condition']['value'] == '' ? '\t\t\treturn True' : confluent['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
+										file_contents += confluent['condition']['value'] == '' ? '\t\t\treturn True' : confluent['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
 										file_contents += '\n\t\t\def ' + action_name + '():\n';
-										file_contents += confluent['action']['value'] == '' ? '\t\t\treturn {}' : confluent['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
+										file_contents += confluent['action']['value'] == '' ? '\t\t\treturn {}' : confluent['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
 										file_contents += '\n\t\tif self.state.name == "' + s['name']['value'] + '" and ' + cond_name + '():\n';
 										file_contents += '\t\t\treturn ' + statedef['name']['value'] + '(name="' + target['name']['value'] + '", **' + action_name + '())\n\n';
 									}
@@ -210,35 +225,35 @@
 									file_contents += '\t\telse:\n';
 									file_contents += '\t\t\treturn AtomicDEVS.confTransition(self, my_inputs)\n';
 								}
-								file_contents += '\n'
+								file_contents += '\n';
 							}
 							
 							for (var idx in type_map['/Formalisms/ParallelDEVS/ParallelDEVS/CoupledDEVS']) {
 								var node = type_map['/Formalisms/ParallelDEVS/ParallelDEVS/CoupledDEVS'][idx],
-									list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None'})),
-									list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name']})),
-									list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']]}));
+									list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None';})),
+									list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name'];})),
+									list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']];}));
 								file_contents += 'class ' + node['name']['value'] + '(CoupledDEVS):\n';
 								file_contents += '\tdef __init__(' + (['self', 'name="' + node['name']['value'] + '"'].concat(list_of_params).join(', ')) + '):\n';
 								file_contents += '\t\tCoupledDEVS.__init__(self, name)\n';
-								file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1])}).join('\n') + "\n";
-                                file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line}).join('\n') + "\n";
+								file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1]);}).join('\n') + "\n";
+                                file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line;}).join('\n') + "\n";
 								key = type_map_keys['/Formalisms/ParallelDEVS/ParallelDEVS/CoupledDEVS'][idx];
-								ports = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports'}).map(function(portsid) {return outgoing[portsid][0]}).map(function(pid) {return as.nodes[pid]});
-								file_contents += '\t\tself.my_ports = {' + ports.map(function(el) {return '"' + el['name']['value'] + '": ' + (el['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/OutputPort' ? 'self.addOutPort("' : 'self.addInPort("') + el['name']['value'] + '")'}).join(', ') + '}\n'
+								ports = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports';}).map(function(portsid) {return outgoing[portsid][0];}).map(function(pid) {return as.nodes[pid];});
+								file_contents += '\t\tself.my_ports = {' + ports.map(function(el) {return '"' + el['name']['value'] + '": ' + (el['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/OutputPort' ? 'self.addOutPort("' : 'self.addInPort("') + el['name']['value'] + '")';}).join(', ') + '}\n';
 								file_contents += '\t\tself.submodels = {}\n';
-								submodels = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/submodels'}).map(function(submodelsid) {return outgoing[submodelsid][0]}).map(function(mid) {return as.nodes[mid]});
-								file_contents += submodels.map(function(m) {return '\t\tself.submodels["' + m['name']['value'] + '"] = self.addSubModel(' + m['devs_type']['value'] + '(' + ['name="' + m['name']['value'] + '"'].concat(m['parameter_binding']['value'].map(function(pb) {return pb['name'] + '=' + pb['val']})).join(', ') + '))'}).join('\n');
+								submodels = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/submodels';}).map(function(submodelsid) {return outgoing[submodelsid][0];}).map(function(mid) {return as.nodes[mid];});
+								file_contents += submodels.map(function(m) {return '\t\tself.submodels["' + m['name']['value'] + '"] = self.addSubModel(' + m['devs_type']['value'] + '(' + ['name="' + m['name']['value'] + '"'].concat(m['parameter_binding']['value'].map(function(pb) {return pb['name'] + '=' + pb['val'];})).join(', ') + '))';}).join('\n');
 								file_contents += '\n\n';
-								myportkeys = ports.map(function(port) {return port['$key']});
+								myportkeys = ports.map(function(port) {return port['$key'];});
 								port_to_m = {};
 								m_to_ports = {};
 								m_to_ports[key] = ports;
-								ports.forEach(function(p) {port_to_m[p['$key']] = node});
+								ports.forEach(function(p) {port_to_m[p['$key']] = node;});
 								for (var skey in submodels) {
 									var m = submodels[skey];
 									m_to_ports[m['$key']] = [];
-									ports = outgoing[m['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports'}).map(function(portsid) {return outgoing[portsid][0]}).map(function(pid) {return as.nodes[pid]});
+									ports = outgoing[m['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports';}).map(function(portsid) {return outgoing[portsid][0];}).map(function(pid) {return as.nodes[pid];});
 									ports.forEach(function(p) {port_to_m[p['$key']] = m; m_to_ports[m['$key']].push(p);});
 								}
 								for (var mkey in m_to_ports) {
@@ -246,7 +261,7 @@
 										var p = m_to_ports[mkey][pidx],
 											pkey = p['$key'];
 										if (pkey in outgoing) {
-											var conns = outgoing[pkey].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/channel'}).map(function(channelid) {return as.nodes[channelid]})
+											var conns = outgoing[pkey].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/channel';}).map(function(channelid) {return as.nodes[channelid];});
 											for (var cidx in conns) {
 												var conn = conns[cidx],
 													target = as.nodes[outgoing[conn['$key']][0]],
@@ -255,7 +270,7 @@
 													toportstr = (port_to_m[target['$key']]['$key'] == key ? 'self' : 'self.submodels["' + port_to_m[target['$key']]['name']['value'] + '"]') + '.my_ports["' + target['name']['value'] + '"]';
 												if (conn['transfer_function']['value'] != '') {
 													file_contents += '\t\tdef ' + transfname + '(event):\n';
-													file_contents += conn['transfer_function']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
+													file_contents += conn['transfer_function']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
 													file_contents += '\n\n';
 													file_contents += '\t\tself.connectPorts(' + fromportstr + ', ' + toportstr + ', ' + transfname + ')\n\n';
 												} else {
@@ -279,7 +294,7 @@
 
 							file_contents += 'def termination_condition(time, model, transitioned):\n';
 							file_contents += '\ttime = time[0]\n';
-							file_contents += type_map['/Formalisms/ParallelDEVS/ParallelDEVS/Simulation'][0]['end_condition']['value'].split('\n').map(function(line) {return '\t' + line}).join('\n') + '\n';
+							file_contents += type_map['/Formalisms/ParallelDEVS/ParallelDEVS/Simulation'][0]['end_condition']['value'].split('\n').map(function(line) {return '\t' + line;}).join('\n') + '\n';
 							
 							_fs.writeFileSync('./exported_to_pypdevs/experiment.py', file_contents);
 							
@@ -290,7 +305,7 @@
 					);
 				},
 				function(err) {__postInternalErrorMsg(resp, err);}
-			)
+			);
 		},
 	'asworker':
 		function(resp, method, uri, reqData, wcontext)
@@ -299,4 +314,4 @@
 				{'statusCode': 200,
 					 'respIndex': resp});	
 		}
-}
+};

+ 34 - 19
plugins/exporttosccdxml.js

@@ -1,5 +1,20 @@
 /* SCCDXML exporter plugin*/
-{
+const {
+    __errorContinuable,
+    __httpReq,
+	__wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+const _utils = require('../utils');
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+const _fspp	= _do.convert(require('../___fs++'), ['mkdirs']);
+
+module.exports = {
 	'interfaces'	: [{'method':'POST', 'url=':'/exporttosccdxml'}],
 	'csworker'		: 
         function(resp,method,uri,reqData,wcontext)
@@ -41,7 +56,7 @@
 								}
 								
 								function find_initial(state){
-									var substates = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain'}).map(function(tid) {return as.nodes[tid]});
+									var substates = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain';}).map(function(tid) {return as.nodes[tid];});
 									for (var sidx in substates){
 										var substate = as.nodes[outgoing[substates[sidx]['$key']]];
 										if(substate['isStart']['value']){
@@ -51,7 +66,7 @@
 								}
 								
 								function get_full_path(state){
-									var parent_link = incoming[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/containOC' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes'}).map(function(tid) {return as.nodes[tid]})[0];
+									var parent_link = incoming[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/containOC' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes';}).map(function(tid) {return as.nodes[tid];})[0];
 									if (parent_link != undefined){
 										var parent = as.nodes[incoming[parent_link['$key']][0]];
 										return get_full_path(parent).concat([state['name']['value']]);
@@ -106,9 +121,9 @@
 										else{
 											contents += ' scope="' + r['scope'] + '">\n';
 										}
-										arguments = r['arguments'];
-										for (var aidx in arguments){
-											var arg = arguments[aidx];
+										let args = r['arguments'];
+										for (var aidx in args){
+											var arg = args[aidx];
 											if(arg != ""){
 												contents += '<parameter expr="' + xml_safe(arg) + '"/>\n';
 											}
@@ -123,7 +138,7 @@
 									if(outgoing[state['$key']] == undefined){
 										return "";
 									}
-									var transitions = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/transition'}).map(function(tid) {return as.nodes[tid]});
+									var transitions = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/transition';}).map(function(tid) {return as.nodes[tid];});
 									for (var tidx in transitions){
 										var transition = transitions[tidx];
 										contents += "<transition ";
@@ -208,10 +223,10 @@
 											ocContain = [];
 									}
 									else{
-										var containOC = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/containOC'}).map(function(tid) {return as.nodes[tid]});
-										var contain = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain'}).map(function(tid) {return as.nodes[tid]});
-										var ocContain = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain'}).map(function(tid) {return as.nodes[tid]});
-										var history = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes'}).map(function(tid) {return as.nodes[tid]});
+										var containOC = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/containOC';}).map(function(tid) {return as.nodes[tid];});
+										var contain = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain';}).map(function(tid) {return as.nodes[tid];});
+										var ocContain = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain';}).map(function(tid) {return as.nodes[tid];});
+										var history = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes';}).map(function(tid) {return as.nodes[tid];});
 									}
 									var s = as.nodes[state['$key']];
 									if (is_root){
@@ -248,7 +263,7 @@
 										contents += '</state>\n';
 									}
 									else {
-										var history = incoming[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes'}).map(function(tid) {return as.nodes[tid]});
+										var history = incoming[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes';}).map(function(tid) {return as.nodes[tid];});
 										if (history.length > 0){
 											contents += '<history id="' + s['name']['value'] + '" type="' + s['type']['value'].trim() + '"/>\n';
 										}
@@ -270,14 +285,14 @@
 										for (var e_key in as.edges) {
 											var e = as.edges[e_key];
 											if (e['dest'] == key) {
-												safe_add(incoming[key], e['src'])
+												safe_add(incoming[key], e['src']);
 												if (!(e['src'] in outgoing)) {
 													outgoing[e['src']] = [];
 												}
 												safe_add(outgoing[e['src']], key);
 											}
 											if (e['src'] == key) {
-												safe_add(outgoing[key], e['dest'])
+												safe_add(outgoing[key], e['dest']);
 												if (!(e['dest'] in incoming)) {
 													incoming[e['dest']] = [];
 												}
@@ -303,12 +318,12 @@
 									if(!external){
 										file_contents += '<class name="' + node['name']['value'] + '" default="true">\n';
 										file_contents += '\t<relationships>\n';
-										inheritances = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/Inheritance'}).map(function(tid) {return as.nodes[tid]});
+										inheritances = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/Inheritance';}).map(function(tid) {return as.nodes[tid];});
 										for (var iidx in inheritances){
 											target = as.nodes[outgoing[inheritances[iidx]['$key']][0]];
 											file_contents += '\t\t<inheritance class="' + target['name']['value'] + '"/>\n';
 										}
-										associations = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/Association'}).map(function(tid) {return as.nodes[tid]});
+										associations = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/Association';}).map(function(tid) {return as.nodes[tid];});
 										for (var iidx in associations){
 											target = as.nodes[outgoing[associations[iidx]['$key']][0]];
 											file_contents += '\t\t<association name="' + associations[iidx]['name']['value'] + '" class="' + target['name']['value'] + '"/>\n';
@@ -333,7 +348,7 @@
 											file_contents += '\t</method>\n';
 										}
 										
-										var behaviour = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/behaviour'}).map(function(tid) {return as.nodes[tid]});
+										var behaviour = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/behaviour';}).map(function(tid) {return as.nodes[tid];});
 										var statechart = as.nodes[outgoing[behaviour[0]['$key']][0]];
 										file_contents += recursive(statechart, true);
 										file_contents += '</class>\n';
@@ -348,7 +363,7 @@
 					);
 				},
 				function(err) {__postInternalErrorMsg(resp, err);}
-			)
+			);
 		},
 
 	'asworker'		: 
@@ -359,4 +374,4 @@
 					{'statusCode':200, 
 					 'respIndex':resp});
 		}
-}
+};

+ 36 - 20
plugins/exporttosccdxml_debug.js

@@ -1,5 +1,21 @@
 /* SCCDXML exporter plugin*/
-{
+const {
+    __errorContinuable,
+    __httpReq,
+    __wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+const _utils = require('../utils');
+const _mmmk = require("../mmmk");
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+const _fspp	= _do.convert(require('../___fs++'), ['mkdirs']);
+
+module.exports = {
 	'interfaces'	: [{'method':'POST', 'url=':'/exporttosccdxml_debug'}],
 	'csworker'		: 
         function(resp,method,uri,reqData,wcontext)
@@ -41,7 +57,7 @@
 								}
 								
 								function find_initial(state){
-									var substates = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain'}).map(function(tid) {return as.nodes[tid]});
+									var substates = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain';}).map(function(tid) {return as.nodes[tid];});
 									for (var sidx in substates){
 										var substate = as.nodes[outgoing[substates[sidx]['$key']]];
 										if(substate['isStart']['value']){
@@ -51,7 +67,7 @@
 								}
 								
 								function get_full_path(state){
-									var parent_link = incoming[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/containOC' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes'}).map(function(tid) {return as.nodes[tid]})[0];
+									var parent_link = incoming[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/containOC' || as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes';}).map(function(tid) {return as.nodes[tid];})[0];
 									if (parent_link != undefined){
 										var parent = as.nodes[incoming[parent_link['$key']][0]];
 										return get_full_path(parent).concat([state['name']['value']]);
@@ -93,7 +109,7 @@
 								}
 								
 								function write_raise(lst){
-									contents = "";
+									let contents = "";
 									for(var ridx in lst){
 										var r = lst[ridx];
 										contents += '<raise event="' + r['event'] + '"';
@@ -106,9 +122,9 @@
 										else{
 											contents += ' scope="' + r['scope'] + '">\n';
 										}
-										arguments = r['arguments'];
-										for (var aidx in arguments){
-											var arg = arguments[aidx];
+										let args = r['arguments'];
+										for (var aidx in args){
+											var arg = args[aidx];
 											if(arg != ""){
 												contents += '<parameter expr="' + xml_safe(arg) + '"/>\n';
 											}
@@ -123,7 +139,7 @@
 									if(outgoing[state['$key']] == undefined){
 										return "";
 									}
-									var transitions = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/transition'}).map(function(tid) {return as.nodes[tid]});
+									var transitions = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/transition';}).map(function(tid) {return as.nodes[tid];});
 									for (var tidx in transitions){
 										var transition = transitions[tidx];
 										contents += "<transition ";
@@ -238,10 +254,10 @@
 											ocContain = [];
 									}
 									else{
-										var containOC = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/containOC'}).map(function(tid) {return as.nodes[tid]});
-										var contain = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain'}).map(function(tid) {return as.nodes[tid]});
-										var ocContain = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain'}).map(function(tid) {return as.nodes[tid]});
-										var history = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes'}).map(function(tid) {return as.nodes[tid]});
+										var containOC = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/containOC';}).map(function(tid) {return as.nodes[tid];});
+										var contain = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/contain';}).map(function(tid) {return as.nodes[tid];});
+										var ocContain = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/ocContain';}).map(function(tid) {return as.nodes[tid];});
+										var history = outgoing[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes';}).map(function(tid) {return as.nodes[tid];});
 									}
 									var s = as.nodes[state['$key']];
 									if (is_root){
@@ -278,7 +294,7 @@
 										contents += '</state>\n';
 									}
 									else {
-										var history = incoming[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes'}).map(function(tid) {return as.nodes[tid]});
+										var history = incoming[state['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/includes';}).map(function(tid) {return as.nodes[tid];});
 										if (history.length > 0){
 											contents += '<history id="' + s['name']['value'] + '" type="' + s['type']['value'].trim() + '"/>\n';
 										}
@@ -300,14 +316,14 @@
 										for (var e_key in as.edges) {
 											var e = as.edges[e_key];
 											if (e['dest'] == key) {
-												safe_add(incoming[key], e['src'])
+												safe_add(incoming[key], e['src']);
 												if (!(e['src'] in outgoing)) {
 													outgoing[e['src']] = [];
 												}
 												safe_add(outgoing[e['src']], key);
 											}
 											if (e['src'] == key) {
-												safe_add(outgoing[key], e['dest'])
+												safe_add(outgoing[key], e['dest']);
 												if (!(e['dest'] in incoming)) {
 													incoming[e['dest']] = [];
 												}
@@ -333,12 +349,12 @@
 									if(!external){
 										file_contents += '<class name="' + node['name']['value'] + '" default="true">\n';
 										file_contents += '\t<relationships>\n';
-										inheritances = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/Inheritance'}).map(function(tid) {return as.nodes[tid]});
+										inheritances = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/Inheritance';}).map(function(tid) {return as.nodes[tid];});
 										for (var iidx in inheritances){
 											target = as.nodes[outgoing[inheritances[iidx]['$key']][0]];
 											file_contents += '\t\t<inheritance class="' + target['name']['value'] + '"/>\n';
 										}
-										associations = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/Association'}).map(function(tid) {return as.nodes[tid]});
+										associations = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/Association';}).map(function(tid) {return as.nodes[tid];});
 										for (var iidx in associations){
 											target = as.nodes[outgoing[associations[iidx]['$key']][0]];
 											file_contents += '\t\t<association name="' + associations[iidx]['name']['value'] + '" class="' + target['name']['value'] + '"/>\n';
@@ -374,7 +390,7 @@
 											file_contents += '\t</method>\n';
 										}
 										
-										var behaviour = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/behaviour'}).map(function(tid) {return as.nodes[tid]});
+										var behaviour = outgoing[node['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/SCCD/SCCD/behaviour';}).map(function(tid) {return as.nodes[tid];});
 										var statechart = as.nodes[outgoing[behaviour[0]['$key']][0]];
 										file_contents += recursive(statechart, true);
 										file_contents += '</class>\n';
@@ -389,7 +405,7 @@
 					);
 				},
 				function(err) {__postInternalErrorMsg(resp, err);}
-			)
+			);
 		},
 
 	'asworker'		: 
@@ -400,4 +416,4 @@
 					{'statusCode':200, 
 					 'respIndex':resp});
 		}
-}
+};

+ 14 - 2
plugins/helloworld.js

@@ -1,5 +1,17 @@
 /* a simple hello world plugin... it listens for "POST /hello" requests... requests are received by "csworker" and forwarded to "asworker"... both respond with their __worker\'s id and with a counter of the number of handled requests */
-{
+const {
+    __errorContinuable,
+    __httpReq,
+	__wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+
+module.exports = {
 	'interfaces'	: [{'method':'POST', 'url=':'/hello'}],
 
 
@@ -40,4 +52,4 @@
 					 'sequence#':__sequenceNumber(),
 					 'respIndex':resp});
 		}
-}
+};

+ 14 - 2
plugins/helloworld2.js

@@ -1,5 +1,17 @@
 /* a more advanced hello world plugin... it listens for "POST /hello.cs", "POST /hello.as" and "POST /hello" requests... "POST /hello.cs" requests are received and handled by "csworker"... "POST /hello.as" requests are received by "csworker" and forwarded to "asworker" for handling... "POST /hello" requests trigger a misuse error */
-{
+const {
+    __errorContinuable,
+    __httpReq,
+    __wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+
+module.exports = {
 	'interfaces'	: 
 		[{'method':'POST', 'urlm':'^/hello\.[ac]s$'},
 		 {'method':'POST', 'url=':'/hello'}],
@@ -52,5 +64,5 @@
 					 'sequence#':__sequenceNumber(),
 					 'respIndex':resp});
 		}
-}
+};
 

+ 17 - 3
plugins/model_stats.js

@@ -1,5 +1,19 @@
 /* a simple plugin that outputs some general information about a model... the point here is to demo how to use _mmmk from a plugin */
-{
+const {
+    __errorContinuable,
+    __httpReq,
+	__wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("../__worker");
+
+const _do = require("../___do");
+const _utils = require('../utils');
+const _mmmk = require("../mmmk");
+
+module.exports = {
 	'interfaces'	: [{'method':'GET', 'url=':'/stats'}],
 
 
@@ -11,7 +25,7 @@
 		{
 			var model = _utils.jsonp(_mmmk.read()),
 				 t2i	 = {};
-console.warn(model, typeof(model))			
+			console.warn(model, typeof(model));
 			for( var id in model.nodes )
 			{
 				var node = model.nodes[id];
@@ -54,6 +68,6 @@ console.warn(model, typeof(model))
   					 'sequence#':__sequenceNumber(),
 					 'respIndex':resp});
 		}
-}
+};