summaryrefslogtreecommitdiff
path: root/js/src/Ice/Properties.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/Ice/Properties.js')
-rw-r--r--js/src/Ice/Properties.js815
1 files changed, 408 insertions, 407 deletions
diff --git a/js/src/Ice/Properties.js b/js/src/Ice/Properties.js
index d30588b1f20..71c1753d492 100644
--- a/js/src/Ice/Properties.js
+++ b/js/src/Ice/Properties.js
@@ -7,497 +7,498 @@
//
// **********************************************************************
-(function(global){
- require("Ice/Class");
- require("Ice/StringUtil");
- require("Ice/HashMap");
- require("Ice/Promise");
- require("Ice/PropertyNames");
- require("Ice/Debug");
- require("Ice/ProcessLogger");
- require("Ice/ProcessLogger");
- require("Ice/LocalException");
-
- var Ice = global.Ice || {};
-
- var StringUtil = Ice.StringUtil;
- var HashMap = Ice.HashMap;
- var Promise = Ice.Promise;
- var PropertyNames = Ice.PropertyNames;
- var Debug = Ice.Debug;
- var ProcessLogger = Ice.ProcessLogger;
- var getProcessLogger = Ice.getProcessLogger;
- var InitializationException = Ice.InitializationException;
- var ParseStateKey = 0;
- var ParseStateValue = 1;
- //
- // Ice.Properties
- //
- var Properties = Ice.Class({
- __init__: function(args, defaults)
- {
- this._properties = new HashMap();
+var Ice = require("../Ice/ModuleRegistry").Ice;
+Ice.__M.require(module, "Ice",
+ [
+ "../Ice/Class",
+ "../Ice/StringUtil",
+ "../Ice/HashMap",
+ "../Ice/Promise",
+ "../Ice/PropertyNames",
+ "../Ice/Debug",
+ "../Ice/ProcessLogger",
+ "../Ice/ProcessLogger",
+ "../Ice/LocalException"
+ ]);
+
+var StringUtil = Ice.StringUtil;
+var HashMap = Ice.HashMap;
+var Promise = Ice.Promise;
+var PropertyNames = Ice.PropertyNames;
+var Debug = Ice.Debug;
+var ProcessLogger = Ice.ProcessLogger;
+var getProcessLogger = Ice.getProcessLogger;
+var InitializationException = Ice.InitializationException;
- if(defaults !== undefined && defaults !== null)
+var ParseStateKey = 0;
+var ParseStateValue = 1;
+//
+// Ice.Properties
+//
+var Properties = Ice.Class({
+ __init__: function(args, defaults)
+ {
+ this._properties = new HashMap();
+
+ if(defaults !== undefined && defaults !== null)
+ {
+ //
+ // NOTE: we can't just do a shallow copy of the map as the map values
+ // would otherwise be shared between the two PropertiesI object.
+ //
+ //_properties = new HashMap(pi._properties);
+ for(var e = defaults._properties.entries; e !== null; e = e.next)
{
- //
- // NOTE: we can't just do a shallow copy of the map as the map values
- // would otherwise be shared between the two PropertiesI object.
- //
- //_properties = new HashMap(pi._properties);
- for(var e = defaults._properties.entries; e !== null; e = e.next)
- {
- this._properties.set(e.key, { 'value': e.value.value, 'used': false });
- }
+ this._properties.set(e.key, { 'value': e.value.value, 'used': false });
}
+ }
- if(args !== undefined && args !== null)
+ if(args !== undefined && args !== null)
+ {
+ var v = this.parseIceCommandLineOptions(args);
+ args.length = 0;
+ for(var i = 0; i < v.length; ++i)
{
- var v = this.parseIceCommandLineOptions(args);
- args.length = 0;
- for(var i = 0; i < v.length; ++i)
- {
- args.push(v[i]);
- }
+ args.push(v[i]);
}
- },
- getProperty: function(key)
+ }
+ },
+ getProperty: function(key)
+ {
+ return this.getPropertyWithDefault(key, "");
+ },
+ getPropertyWithDefault: function(key, value)
+ {
+ var pv = this._properties.get(key);
+ if(pv !== undefined)
{
- return this.getPropertyWithDefault(key, "");
- },
- getPropertyWithDefault: function(key, value)
+ pv.used = true;
+ return pv.value;
+ }
+ else
{
- var pv = this._properties.get(key);
- if(pv !== undefined)
- {
- pv.used = true;
- return pv.value;
- }
- else
- {
- return value;
- }
- },
- getPropertyAsInt: function(key)
+ return value;
+ }
+ },
+ getPropertyAsInt: function(key)
+ {
+ return this.getPropertyAsIntWithDefault(key, 0);
+ },
+ getPropertyAsIntWithDefault: function(key, value)
+ {
+ var pv = this._properties.get(key);
+ if(pv !== undefined)
{
- return this.getPropertyAsIntWithDefault(key, 0);
- },
- getPropertyAsIntWithDefault: function(key, value)
+ pv.used = true;
+ return parseInt(pv.value);
+ }
+ else
{
- var pv = this._properties.get(key);
- if(pv !== undefined)
- {
- pv.used = true;
- return parseInt(pv.value);
- }
- else
- {
- return value;
- }
- },
- getPropertyAsList: function(key)
+ return value;
+ }
+ },
+ getPropertyAsList: function(key)
+ {
+ return this.getPropertyAsListWithDefault(key, 0);
+ },
+ getPropertyAsListWithDefault: function(key, value)
+ {
+ if(value === undefined || value === null)
{
- return this.getPropertyAsListWithDefault(key, 0);
- },
- getPropertyAsListWithDefault: function(key, value)
+ value = [];
+ }
+
+ var pv = this._properties.get(key);
+ if(pv !== undefined)
{
- if(value === undefined || value === null)
- {
- value = [];
- }
+ pv.used = true;
- var pv = this._properties.get(key);
- if(pv !== undefined)
- {
- pv.used = true;
-
- var result = StringUtil.splitString(pv.value, ", \t\r\n");
- if(result === null)
- {
- getProcessLogger().warning("mismatched quotes in property " + key + "'s value, returning default value");
- return value;
- }
- if(result.length === 0)
- {
- result = value;
- }
- return result;
- }
- else
+ var result = StringUtil.splitString(pv.value, ", \t\r\n");
+ if(result === null)
{
+ getProcessLogger().warning("mismatched quotes in property " + key + "'s value, returning default value");
return value;
}
- },
- getPropertiesForPrefix: function(prefix)
- {
- var result = new HashMap();
- for(var e = this._properties.entries; e !== null; e = e.next)
+ if(result.length === 0)
{
- if(prefix === undefined || prefix === null || e.key.indexOf(prefix) === 0)
- {
- e.value.used = true;
- result.set(e.key, e.value.value);
- }
+ result = value;
}
return result;
- },
- setProperty: function(key, value)
+ }
+ else
{
- //
- // Trim whitespace
- //
- if(key !== null && key !== undefined)
+ return value;
+ }
+ },
+ getPropertiesForPrefix: function(prefix)
+ {
+ var result = new HashMap();
+ for(var e = this._properties.entries; e !== null; e = e.next)
+ {
+ if(prefix === undefined || prefix === null || e.key.indexOf(prefix) === 0)
{
- key = key.trim();
+ e.value.used = true;
+ result.set(e.key, e.value.value);
}
+ }
+ return result;
+ },
+ setProperty: function(key, value)
+ {
+ //
+ // Trim whitespace
+ //
+ if(key !== null && key !== undefined)
+ {
+ key = key.trim();
+ }
- //
- // Check if the property is legal.
- //
- var logger = getProcessLogger();
- if(key === null || key === undefined || key.length === 0)
- {
- throw new InitializationException("Attempt to set property with empty key");
- }
+ //
+ // Check if the property is legal.
+ //
+ var logger = getProcessLogger();
+ if(key === null || key === undefined || key.length === 0)
+ {
+ throw new InitializationException("Attempt to set property with empty key");
+ }
- var dotPos = key.indexOf(".");
- if(dotPos !== -1)
+ var dotPos = key.indexOf(".");
+ if(dotPos !== -1)
+ {
+ var prefix = key.substr(0, dotPos);
+ for(var i = 0; i < PropertyNames.validProps.length; ++i)
{
- var prefix = key.substr(0, dotPos);
- for(var i = 0; i < PropertyNames.validProps.length; ++i)
+ var pattern = PropertyNames.validProps[i][0].pattern;
+ dotPos = pattern.indexOf(".");
+ //
+ // Each top level prefix describes a non-empty namespace. Having a string without a
+ // prefix followed by a dot is an error.
+ //
+ Debug.assert(dotPos != -1);
+ var propPrefix = pattern.substring(0, dotPos - 1);
+ if(propPrefix != prefix)
{
- var pattern = PropertyNames.validProps[i][0].pattern;
- dotPos = pattern.indexOf(".");
- //
- // Each top level prefix describes a non-empty namespace. Having a string without a
- // prefix followed by a dot is an error.
- //
- Debug.assert(dotPos != -1);
- var propPrefix = pattern.substring(0, dotPos - 1);
- if(propPrefix != prefix)
- {
- continue;
- }
-
- var found = false;
- var mismatchCase = false;
- var otherKey;
- for(var j = 0; j < PropertyNames.validProps[i][j].length && !found; ++j)
- {
- pattern = PropertyNames.validProps[i][j].pattern();
- var pComp = new RegExp(pattern);
- found = pComp.test(key);
+ continue;
+ }
+
+ var found = false;
+ var mismatchCase = false;
+ var otherKey;
+ for(var j = 0; j < PropertyNames.validProps[i][j].length && !found; ++j)
+ {
+ pattern = PropertyNames.validProps[i][j].pattern();
+ var pComp = new RegExp(pattern);
+ found = pComp.test(key);
- if(found && PropertyNames.validProps[i][j].deprecated)
- {
- logger.warning("deprecated property: " + key);
- if(PropertyNames.validProps[i][j].deprecatedBy !== null)
- {
- key = PropertyNames.validProps[i][j].deprecatedBy;
- }
- }
-
- if(found)
+ if(found && PropertyNames.validProps[i][j].deprecated)
+ {
+ logger.warning("deprecated property: " + key);
+ if(PropertyNames.validProps[i][j].deprecatedBy !== null)
{
- break;
- }
- else
- {
- pComp = new RegExp(pattern.toUpperCase());
- found = pComp.test(key.toUpperCase());
- if(found)
- {
- mismatchCase = true;
- otherKey = pattern.substr(2);
- otherKey = otherKey.substr(0, otherKey.length -1);
- otherKey = otherKey.replace(/\\/g, "");
- break;
- }
+ key = PropertyNames.validProps[i][j].deprecatedBy;
}
}
- if(!found)
+ if(found)
{
- logger.warning("unknown property: " + key);
+ break;
}
- else if(mismatchCase)
+ else
{
- logger.warning("unknown property: `" + key + "'; did you mean `" + otherKey + "'");
+ pComp = new RegExp(pattern.toUpperCase());
+ found = pComp.test(key.toUpperCase());
+ if(found)
+ {
+ mismatchCase = true;
+ otherKey = pattern.substr(2);
+ otherKey = otherKey.substr(0, otherKey.length -1);
+ otherKey = otherKey.replace(/\\/g, "");
+ break;
+ }
}
}
- }
-
- //
- // Set or clear the property.
- //
- if(value !== undefined && value !== null && value.length > 0)
- {
- var pv = this._properties.get(key);
- if(pv !== undefined)
+
+ if(!found)
{
- pv.value = value;
+ logger.warning("unknown property: " + key);
}
- else
+ else if(mismatchCase)
{
- this._properties.set(key, { 'value': value, 'used': false });
+ logger.warning("unknown property: `" + key + "'; did you mean `" + otherKey + "'");
}
}
- else
- {
- this._properties.delete(key);
- }
- },
- getCommandLineOptions: function()
+ }
+
+ //
+ // Set or clear the property.
+ //
+ if(value !== undefined && value !== null && value.length > 0)
{
- var result = [];
- for(var e = this._properties.entries; e !== null; e = e.next)
+ var pv = this._properties.get(key);
+ if(pv !== undefined)
{
- result.push("--" + e.key + "=" + e.pv.value);
+ pv.value = value;
}
- return result;
- },
- parseCommandLineOptions: function(pfx, options)
- {
- if(pfx.length > 0 && pfx.charAt(pfx.length - 1) != ".")
+ else
{
- pfx += ".";
+ this._properties.set(key, { 'value': value, 'used': false });
}
- pfx = "--" + pfx;
+ }
+ else
+ {
+ this._properties.delete(key);
+ }
+ },
+ getCommandLineOptions: function()
+ {
+ var result = [];
+ for(var e = this._properties.entries; e !== null; e = e.next)
+ {
+ result.push("--" + e.key + "=" + e.pv.value);
+ }
+ return result;
+ },
+ parseCommandLineOptions: function(pfx, options)
+ {
+ if(pfx.length > 0 && pfx.charAt(pfx.length - 1) != ".")
+ {
+ pfx += ".";
+ }
+ pfx = "--" + pfx;
- var result = [];
-
- var self = this;
- options.forEach(
- function(opt)
+ var result = [];
+
+ var self = this;
+ options.forEach(
+ function(opt)
+ {
+ if(opt.indexOf(pfx) === 0)
{
- if(opt.indexOf(pfx) === 0)
+ if(opt.indexOf('=') === -1)
{
- if(opt.indexOf('=') === -1)
- {
- opt += "=1";
- }
-
- self.parseLine(opt.substring(2));
- }
- else
- {
- result.push(opt);
+ opt += "=1";
}
- });
- return result;
- },
- parseIceCommandLineOptions: function(options)
- {
- var args = options.slice();
- for(var i = 0; i < PropertyNames.clPropNames.length; ++i)
- {
- args = this.parseCommandLineOptions(PropertyNames.clPropNames[i], args);
- }
- return args;
- },
- parse: function(data)
+
+ self.parseLine(opt.substring(2));
+ }
+ else
+ {
+ result.push(opt);
+ }
+ });
+ return result;
+ },
+ parseIceCommandLineOptions: function(options)
+ {
+ var args = options.slice();
+ for(var i = 0; i < PropertyNames.clPropNames.length; ++i)
{
- var lines = data.match(/[^\r\n]+/g);
-
- var line;
-
- while((line = lines.shift()))
- {
- this.parseLine(line);
- }
- },
- parseLine: function(line)
+ args = this.parseCommandLineOptions(PropertyNames.clPropNames[i], args);
+ }
+ return args;
+ },
+ parse: function(data)
+ {
+ var lines = data.match(/[^\r\n]+/g);
+
+ var line;
+
+ while((line = lines.shift()))
{
- var key = "";
- var value = "";
+ this.parseLine(line);
+ }
+ },
+ parseLine: function(line)
+ {
+ var key = "";
+ var value = "";
- var state = ParseStateKey;
+ var state = ParseStateKey;
- var whitespace = "";
- var escapedspace = "";
- var finished = false;
-
- for(var i = 0; i < line.length; ++i)
+ var whitespace = "";
+ var escapedspace = "";
+ var finished = false;
+
+ for(var i = 0; i < line.length; ++i)
+ {
+ var c = line.charAt(i);
+ switch(state)
{
- var c = line.charAt(i);
- switch(state)
+ case ParseStateKey:
{
- case ParseStateKey:
+ switch(c)
{
- switch(c)
- {
- case '\\':
- if(i < line.length - 1)
+ case '\\':
+ if(i < line.length - 1)
+ {
+ c = line.charAt(++i);
+ switch(c)
{
- c = line.charAt(++i);
- switch(c)
- {
- case '\\':
- case '#':
- case '=':
- key += whitespace;
- whitespace = "";
- key += c;
- break;
+ case '\\':
+ case '#':
+ case '=':
+ key += whitespace;
+ whitespace = "";
+ key += c;
+ break;
- case ' ':
- if(key.length !== 0)
- {
- whitespace += c;
- }
- break;
+ case ' ':
+ if(key.length !== 0)
+ {
+ whitespace += c;
+ }
+ break;
- default:
- key += whitespace;
- whitespace = "";
- key += '\\';
- key += c;
- break;
- }
- }
- else
- {
- key += whitespace;
- key += c;
+ default:
+ key += whitespace;
+ whitespace = "";
+ key += '\\';
+ key += c;
+ break;
}
- break;
+ }
+ else
+ {
+ key += whitespace;
+ key += c;
+ }
+ break;
- case ' ':
- case '\t':
- case '\r':
- case '\n':
- if(key.length !== 0)
- {
- whitespace += c;
- }
- break;
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ if(key.length !== 0)
+ {
+ whitespace += c;
+ }
+ break;
- case '=':
- whitespace = "";
- state = ParseStateValue;
- break;
+ case '=':
+ whitespace = "";
+ state = ParseStateValue;
+ break;
- case '#':
- finished = true;
- break;
+ case '#':
+ finished = true;
+ break;
- default:
- key += whitespace;
- whitespace = "";
- key += c;
- break;
- }
- break;
+ default:
+ key += whitespace;
+ whitespace = "";
+ key += c;
+ break;
}
+ break;
+ }
- case ParseStateValue:
+ case ParseStateValue:
+ {
+ switch(c)
{
- switch(c)
- {
- case '\\':
- if(i < line.length - 1)
+ case '\\':
+ if(i < line.length - 1)
+ {
+ c = line.charAt(++i);
+ switch(c)
{
- c = line.charAt(++i);
- switch(c)
- {
- case '\\':
- case '#':
- case '=':
- value += value.length === 0 ? escapedspace : whitespace;
- whitespace = "";
- escapedspace = "";
- value += c;
- break;
+ case '\\':
+ case '#':
+ case '=':
+ value += value.length === 0 ? escapedspace : whitespace;
+ whitespace = "";
+ escapedspace = "";
+ value += c;
+ break;
- case ' ':
- whitespace += c;
- escapedspace += c;
- break;
+ case ' ':
+ whitespace += c;
+ escapedspace += c;
+ break;
- default:
- value += value.length === 0 ? escapedspace : whitespace;
- whitespace = "";
- escapedspace = "";
- value += '\\';
- value += c;
- break;
- }
+ default:
+ value += value.length === 0 ? escapedspace : whitespace;
+ whitespace = "";
+ escapedspace = "";
+ value += '\\';
+ value += c;
+ break;
}
- else
- {
- value += value.length === 0 ? escapedspace : whitespace;
- value += c;
- }
- break;
+ }
+ else
+ {
+ value += value.length === 0 ? escapedspace : whitespace;
+ value += c;
+ }
+ break;
- case ' ':
- case '\t':
- case '\r':
- case '\n':
- if(value.length !== 0)
- {
- whitespace += c;
- }
- break;
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ if(value.length !== 0)
+ {
+ whitespace += c;
+ }
+ break;
- case '#':
- finished = true;
- break;
+ case '#':
+ finished = true;
+ break;
- default:
- value += value.length === 0 ? escapedspace : whitespace;
- whitespace = "";
- escapedspace = "";
- value += c;
- break;
- }
- break;
+ default:
+ value += value.length === 0 ? escapedspace : whitespace;
+ whitespace = "";
+ escapedspace = "";
+ value += c;
+ break;
}
- }
- if(finished)
- {
break;
}
}
- value += escapedspace;
-
- if((state === ParseStateKey && key.length !== 0) ||
- (state == ParseStateValue && key.length === 0))
+ if(finished)
{
- getProcessLogger().warning("invalid config file entry: \"" + line + "\"");
- return;
+ break;
}
- else if(key.length === 0)
- {
- return;
- }
-
- this.setProperty(key, value);
- },
- clone: function()
+ }
+ value += escapedspace;
+
+ if((state === ParseStateKey && key.length !== 0) ||
+ (state == ParseStateValue && key.length === 0))
{
- return new Properties(null, this);
- },
- getUnusedProperties: function()
+ getProcessLogger().warning("invalid config file entry: \"" + line + "\"");
+ return;
+ }
+ else if(key.length === 0)
{
- var unused = [];
- for(var e = this._properties.entries; e !== null; e = e.next)
+ return;
+ }
+
+ this.setProperty(key, value);
+ },
+ clone: function()
+ {
+ return new Properties(null, this);
+ },
+ getUnusedProperties: function()
+ {
+ var unused = [];
+ for(var e = this._properties.entries; e !== null; e = e.next)
+ {
+ if(!e.pv.used)
{
- if(!e.pv.used)
- {
- unused.push(e.key);
- }
+ unused.push(e.key);
}
- return unused;
}
- });
-
- Properties.createProperties = function(args, defaults)
- {
- return new Properties(args, defaults);
- };
-
- Ice.Properties = Properties;
- global.Ice = Ice;
-}(typeof (global) === "undefined" ? window : global));
+ return unused;
+ }
+});
+
+Properties.createProperties = function(args, defaults)
+{
+ return new Properties(args, defaults);
+};
+
+Ice.Properties = Properties;
+module.exports.Ice = Ice;