blob: 677800390613e57f0fd63cf19b3b5a8830fee918 [file] [log] [blame]
orion.Require = function(header) {
if (header === null)
throw "header cannot be null";
this._name = null;
this._attributes = {};
this._optional = false;
this._bundleVersionRange = orion.VersionRange.emptyRange;
this._wiredBundle = null;
this._parseRequire(header);
};
orion.Require.prototype = {
_parseRequire : function(header) {
if (typeof header == "string") {
this._name = header;
return;
}
this._name = header.name;
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;
},
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;
this._wiredBundle = candidate;
return true;
},
_checkAttributes : function(candidate) {
for ( var key in this._attributes) {
if (key === "bundleVersion") {
if (!this._bundleVersionRange.isIncluded(candidate.getVersion()))
return false;
}
}
return true;
},
getWiredBundle : function() {
return this._wiredBundle;
},
unwire : function() {
this._wiredBundle = null;
}
};