"use strict";
var EXPORTED_SYMBOLS = ["core"];
function Application() {
var $ = this;
$.xbCore = {
init: function (api) {
$.init(api);
}
,
finalize: function () {
$.finalize();
}
};
$.init = function (api) {
$.api = api;
$.logger = api.logger;
$.controller = $.loadModule("NotificationsController");
}
;
$.finalize = function () {
$.controller.finalize();
$._loadedModules = {
};
}
;
}

Application.prototype = {
constructor: Application,
_commonModules: ["ExternalInterface", "Mailman"],
_loadedModules: {
},
loadModule: function (moduleName) {
var cachedModule = this._loadedModules[moduleName];
if ("undefined" != typeof cachedModule)
{
this.logger.trace("[Loader] Module \"" + moduleName + "\" found in cache.");
return cachedModule;
}

var application = this;
var scope = {
};
const LOCATIONS = [{
path: application.api.Package.resolvePath("modules/" + moduleName + ".jsm")}, {
path: application.api.Package.resolvePath("modules/common/" + moduleName + "/module.js")}];
var moduleLoaded = false;
var i = this._commonModules.indexOf(moduleName) >= 0 ? 1 : 0;
var moduleData = LOCATIONS[i];
var moduleFound = true;
try {
Components.utils.import(moduleData.path,scope);
}
catch (e) {
moduleFound = false;
}

if (moduleFound)
{
moduleLoaded = true;
}

if (! moduleLoaded)
{
let message = "[Loader] No module found with name \"" + moduleName + "\".";
this.logger.error(message);
throw Error(message);
}

var module = scope.module;
if ("function" != typeof module)
{
let message = "[Loader] Module \"" + moduleName + "\" does not export \"module\" function.";
this.logger.error(message);
throw Error(message);
}

this.logger.trace("[Loader] Module \"" + moduleName + "\" has been loaded.");
var appliedModule = module.call(scope,application);
this._loadedModules[moduleName] = appliedModule;
return appliedModule;
}
};
var application = new Application();
var core = application.xbCore;
