| orion.Export = function(header, exportingBundle) { |
| if (header === null) |
| throw "header cannot be null"; |
| |
| if (exportingBundle === null) |
| throw "exportingBundle cannot be null"; |
| |
| this._name = null; |
| this._version = orion.Version.EMPTY_VERSION; |
| this._attributes = {}; |
| this._mandatory = []; |
| this._exportingBundle = exportingBundle; |
| |
| this._parseExport(header); |
| }; |
| |
| orion.Export.prototype = { |
| _parseExport : function(header) { |
| if (typeof header == "string") { |
| this._name = header; |
| return; |
| } |
| |
| this._name = header.name; |
| if (header.version) |
| this._version = orion.Version.parseVersion(header.version); |
| |
| if (header.mandatory) |
| this._parseMandatory(header.mandatory); |
| |
| var attributeName; |
| for (attributeName in header) { |
| if (header.hasOwnProperty(attributeName)) |
| this._attributes[attributeName] = header[attributeName]; |
| } |
| }, |
| _parseMandatory : function(mandatory) { |
| for ( var i = 0; i < mandatory.length; i++) { |
| this._mandatory.push(mandatory[i]); |
| } |
| }, |
| getName : function() { |
| return this._name; |
| }, |
| getVersion : function() { |
| return this._version; |
| }, |
| getBundleId : function() { |
| return this._exportingBundle.getBundleId(); |
| }, |
| getBundleName : function() { |
| return this._exportingBundle.getName(); |
| }, |
| getBundleVersion : function() { |
| return this._exportingBundle.getVersion(); |
| }, |
| getAttributes : function() { |
| return this._attributes; |
| }, |
| getExportingBundle : function() { |
| return this._exportingBundle; |
| }, |
| getMandatory : function() { |
| return this._mandatory; |
| }, |
| addToScope : function (scope) { |
| var value = this._exportingBundle.load(this._name); |
| var tokens = this._name.split("."); |
| var _Wrapper = function() {}; |
| var i = 0; |
| while (true) { |
| var token = tokens[i++]; |
| var current = null; |
| if (scope.hasOwnProperty(token)) { |
| current = scope[token]; |
| } |
| if (i === tokens.length) { |
| if (current === null || current === undefined) { |
| if (typeof value === "object") { |
| _Wrapper.prototype = value; |
| value = new _Wrapper(); |
| } |
| scope[token]= value; |
| return; |
| } |
| throw "Resolve error: " + this._name + " already exists for " + this.toString(); |
| } |
| if (current === null || current === undefined) { |
| current = scope[token]; |
| if (current === null || current === undefined) { |
| current = {}; |
| } else if (typeof current === "object") { |
| _Wrapper.prototype = current; |
| current = new _Wrapper(); |
| } else |
| throw "Resolve error: " + this._name + "-" + token + " already exists for " + this.toString(); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ |
| scope[token] = current; |
| } |
| scope = current; |
| } |
| } |
| }; |