blob: 8a90859094f2b4690d3b97aa8a3aff3022803a5d [file] [log] [blame]
orion.Import = function(header) {
if (header === null)
throw "header cannot be null";
this._name = null;
this._versionRange = orion.VersionRange.EMPTY_RANGE;
this._bundleName = null;
this._bundleVersionRange = orion.VersionRange.EMPTY_RANGE;
this._optional = false;
this._attributes = {};
this._wiredExport = null;
this._parseImport(header);
};
orion.Import.prototype = {
_parseImport : function(header) {
if (typeof header == "string") {
this._name = header;
return;
}
this._name = header.name;
if (header.version)
this._versionRange = orion.VersionRange.parseVersionRange(header.version);
if (header.bundleName)
this._bundleName = header.bundleName;
if (header.bundleVersion)
this._bundleVersionRange = orion.VersionRange.parseVersionRange(header.bundleVersion);
if (header.resolution)
this._optional = (header.resolution === "optional");
var attributeName;
for (attributeName in header) {
if (header.hasOwnProperty(attributeName))
this._attributes[attributeName] = header[attributeName];
}
},
getName : function() {
return this._name;
},
getVersionRange : function() {
return this._versionRange;
},
getBundleName : function() {
return this._bundleName;
},
getBundleVersionRange : function() {
return this._bundleVersionRange;
},
isOptional : function() {
return this._optional;
},
getAttributes : function() {
this._attributes;
},
wire : function(candidate) {
if (this._name !== candidate.getName())
return false;
if (!this._checkAttributes(candidate))
return false;
if (!this._checkMandatory(candidate))
return false;
this._wiredExport = candidate;
return true;
},
_checkAttributes : function(candidate) {
for ( var key in this._attributes) {
if (key === "version") {
if (!this._versionRange.isIncluded(candidate.getVersion()))
return false;
} else if (key === "bundleName") {
if (this._bundleName !== candidate.getBundleName())
return false;
} else if (key === "bundleVersion") {
if (!this._bundleVersionRange.isIncluded(candidate.getBundleVersion()))
return false;
} else {
var value = this._attributes[key];
var attributeValue = candidate.getAttributes()[key];
if (attributeValue !== value)
return false;
}
}
return true;
},
_checkMandatory : function(candidate) {
for ( var i = 0; i < candidate.getMandatory().length; i++) {
var key = candidate.getMandatory()[i];
var mandatoryValue = candidate.getAttributes()[key];
var value = this._attributes[key];
if (value !== mandatoryValue)
return false;
}
return true;
},
getWiredExport : function() {
return this._wiredExport;
},
unwire : function() {
this._wiredExport = null;
}
};