home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
fil992F0B355CFFC8433DA8134B0637E137
< prev
next >
Wrap
Text File
|
2010-07-12
|
26KB
|
761 lines
XB._calcNodes = {};
XB._calcNodes.NodeBase = Base.extend({
$name: "NodeBase",
constructor: function NodeBase_constructor(baseUID) {
if (!baseUID)
throw new Error(XB._base.consts.ERR_UID_REQUIRED);
this._baseUID = baseUID;
},
get baseID() {
return this._baseUID;
},
set debugMode(value) {
return this._debugMode = !!value;
},
_baseUID: undefined,
_storedValue: undefined,
_debugMode: false
});
XB._calcNodes.ConstNodeProto = XB._calcNodes.NodeBase.extend({
$name: "ConstNodeProto",
constructor: function ConstNodeProto_constructor(baseUID, initVal) {
this.base(baseUID);
this._storedValue = initVal;
},
createInstance: function ConstNodeProto_createInstance(widgetInstance) {
var nodeInst = new XB._calcNodes.ConstNode(this._baseUID, widgetInstance, this._storedValue);
return nodeInst;
}
});
XB._calcNodes.VarNodeProto = XB._calcNodes.ConstNodeProto.extend({
$name: "VarNodeProto",
createInstance: function VarNodeProto_createInstance(widgetInstance) {
var nodeInst = new XB._calcNodes.VarNode(this._baseUID, widgetInstance, this._storedValue);
return nodeInst;
}
});
XB._calcNodes.FuncNodeProto = XB._calcNodes.NodeBase.extend({
$name: "FuncNodeProto",
constructor: function FuncNodeProto_constructor(baseUID, instanceClass) {
if ( !instanceClass.inherits(XB._calcNodes.FuncNode) && !instanceClass.inherits(XB._calcNodes.ProcNode) )
throw new TypeError(this._consts.ERR_NODE_CONSTRUCTOR_EXPECTED);
this.base(baseUID);
this._instanceClass = instanceClass;
this._argsMap = { __proto__: null };
},
proposeArgName: function FuncNodeProto_proposeArgName() {
for each (let argName in this._instanceClass.prototype.expectedArgNames) {
if (!this.argumentAttached(argName))
return argName;
}
return "param" + this._argsCount;
},
attachArgument: function FuncNodeProto_attachArgument(argName, argProto) {
if ( !(argProto instanceof XB._calcNodes.NodeBase) || (typeof argProto.createInstance != "function") )
throw new TypeError(this._consts.ERR_FNODE_PROTO_EXPECTED);
this._argsMap[argName] = argProto;
this._argsCount++;
},
argumentAttached: function FuncnodeProto_argumentAttached(argName) {
return !!this._argsMap[argName];
},
createInstance: function FuncNodeProto_createInstance(widgetInstance) {
var nodeInst = new this._instanceClass(this._baseUID, widgetInstance, this._argsMap, this._debugMode);
return nodeInst;
},
_consts: {
ERR_FNODE_PROTO_EXPECTED: "Function node prototype object expected",
ERR_NODE_CONSTRUCTOR_EXPECTED: "Widget node constructor expected"
},
_argsMap: null,
_argsCount: 0,
_instanceClass: null
});
XB._calcNodes.BoundNode = XB._calcNodes.NodeBase.extend({
$name: "BoundNode",
constructor: function BoundNode_constructor(baseUID, widget) {
if ( !(widget instanceof XB._Parser.Unit.WidgetPrototype ||
widget instanceof XB._Parser.Unit.WidgetInstance) )
throw new TypeError(XB._base.consts.ERR_WINST_REQUIRED);
this.base(baseUID);
this._parentWidget = widget;
},
get effectiveID() {
var idParts = [this._parentWidget.id, this._baseUID];
if (this._parentWidget instanceof XB._Parser.Unit.WidgetInstance)
idParts.unshift(this._parentWidget.host.id);
return idParts.join("_");
},
get parentWidget() {
return this._parentWidget;
},
finalize: function BoundNode_finalize() {
},
_parentWidget: null,
_formatRuntimeError: function BoundNode_formatRuntimeError(e) {
return XB._base.consts.ERR_RUNTIME_ERROR + " in node " + this._getHumanReadableID() + ". " + misc.formatError(e);
},
_hasSubscribers: function BoundNode_hasSubscribers() {
return false;
},
_getHumanReadableID: function FuncNode_getHumanReadableID() {
return this.$class.$name + "(" + this.effectiveID + ")";
}
});
XB._calcNodes.ConstNode = XB._calcNodes.BoundNode.extend({
$name: "ConstNode",
constructor: function ConstNode_constructor(baseUID, widget, initVal) {
this.base(baseUID, widget);
this._storedValue = initVal;
if (XB._base.runtime.isXML(initVal))
initVal.owner = this;
},
getValue: function ConstNode_getValue() {
return this._storedValue;
},
unsubscribe: function ConstNode_unsubscribe() {
},
finalize: function ConstNode_finalize() {
if (XB._base.runtime.isXML(this._storedValue))
this._storedValue.dispose();
this._storedValue = undefined;
},
freeze: function ConstNode_freeze() {
throw new Error(XB._calcNodes.ConstNode.ERR_UNSUPPORTED_ACTION);
},
melt: function ConstNode_usedNodeChange() {
throw new Error(XB._calcNodes.ConstNode.ERR_UNSUPPORTED_ACTION);
}
}, {
ERR_UNSUPPORTED_ACTION: "ConstNode does not support this method"
});
XB._calcNodes.DynNode = XB._calcNodes.ConstNode.extend({
$name: "DynNode",
constructor: function DynNode_constructor(baseUID, widget, initVal) {
this.base.apply(this, arguments);
this._dependants = {};
},
getValue: function DynNode_getValue(subscriber) {
if (subscriber)
this._subscribe(subscriber);
return this.base();
},
unsubscribe: function DynNode_unsubscribe(subscriber) {
var subscriberID = subscriber.effectiveID;
if ( !(subscriberID in this._dependants) ) return;
delete this._dependants[subscriberID];
if (!this._hasSubscribers()) {
if (this._debugMode)
this._parentWidget.logger.debug("Node " + this._getHumanReadableID() +
" lost all subscribers. Last one was " + subscriber._getHumanReadableID());
this._setNewVal(undefined);
try {
this._notNeeded();
}
catch (e) {
this._parentWidget.logger.error("Node " + this._getHumanReadableID() + " failed in _notNeeded. " +
this._formatRuntimeError(e));
this._parentWidget.logger.debug(e.stack);
}
}
},
finalize: function DynNode_finalize() {
try {
this._dependants = {};
this._notNeeded();
this._setNewVal(XB.types.empty);
}
finally {
this.base();
}
},
_setNewVal: function DynNode_setNewVal(newVal) {
if (newVal !== undefined && this._storedValue !== undefined) {
var valuesDiffer = (XB._base.runtime.compareValues(newVal, this._storedValue,
XB._base.runtime.cmpModes.CMP_STRICT) != 0);
}
if (this._debugMode && (this._parentWidget.logger.level <= XB._base.application.core.Log4Moz.Level.Debug)) {
this._parentWidget.logger.debug("Node " + this._getHumanReadableID() +
" _setNewVal from " + (this._storedValue === undefined ?
"undefined" : XB._base.runtime.describeValue(this._storedValue)) +
" to " + (newVal === undefined ?
"undefined" : XB._base.runtime.describeValue(newVal)) +
", differ: " + valuesDiffer);
if (XB._base.runtime.isXML(newVal))
this._parentWidget.logger.debug("new value is:" + newVal.toString());
}
if (valuesDiffer || newVal === undefined || this._storedValue === undefined) {
if (XB._base.runtime.isXML(newVal)) {
if (newVal.disposed && this._debugMode)
this._parentWidget.logger.warn(this._getHumanReadableID() + " got disposed XML");
}
if (XB._base.runtime.isXML(this._storedValue) && (this._storedValue.owner === this))
this._storedValue.dispose();
this._storedValue = newVal;
if (XB._base.runtime.isXML(newVal) && !newVal.owner)
newVal.owner = this;
}
else {
if ( XB._base.runtime.isXML(newVal) && (newVal !== this._storedValue) ) {
newVal.dispose();
}
}
return valuesDiffer;
},
_subscribe: function DynNode_subscribe(subscriber) {
this._dependants[subscriber.effectiveID] = subscriber;
},
_notifyDeps: function DynNode_notifyDeps() {
if (this._debugMode)
this._parentWidget.logger.debug("FuncNode " + this._getHumanReadableID() + " notifies dependants");
try {
this._freezeDeps();
}
finally {
this._meltDeps(true);
}
},
_freezeDeps: function DynNode_freezeDeps() {
for each (let dependant in this._dependants)
dependant.freeze();
},
_meltDeps: function DynNode_meltDeps(iChanged) {
for each (let dependant in this._dependants) {
try {
if (this._debugMode || dependant._debugMode)
this._parentWidget.logger.debug(this._getHumanReadableID() + " ++ " + dependant._getHumanReadableID());
dependant.melt(iChanged? this: null);
}
catch (e) {
this._parentWidget.logger.error(this._getHumanReadableID() + " failed melting dependant node " + dependant._getHumanReadableID() +
". " + misc.formatError(e));
this._parentWidget.logger.debug(e.stack);
}
}
},
_hasSubscribers: function DynNode_hasSubscribers() {
return !sysutils.isEmptyObject(this._dependants);
},
_notNeeded: function DynNode_notNeeded() {
},
_dependants: null
});
XB._calcNodes.IVariable = {
$name: "IVariable",
setValue: function IVariable_setValue(newValue) {
if (this._setNewVal(newValue))
this._notifyDeps();
}
};
XB._calcNodes.VarNode = XB._calcNodes.DynNode.extend(XB._calcNodes.IVariable);
XB._calcNodes.IHasArguments = {
constructor: function HasArgs_constructor(baseUID, widget, argsMap) {
this.base(baseUID, widget);
this._argManager = new XB._calcNodes.FuncNode.ArgManager(this);
for (let argName in argsMap) {
var argProto = argsMap[argName];
this._argManager.attachArgument(argName, argProto.createInstance(widget));
}
},
unsubscribe: function HasArgs_unsubscribe(subscriber) {
try {
this.base(subscriber);
}
finally {
if (!this._hasSubscribers())
this._argManager.freeAll();
}
},
finalize: function HasArgs_finalize() {
try {
this.base();
}
finally {
this._argManager.freeAll();
}
},
_argManager: null
};
XB._calcNodes.ProcNodeBase = XB._calcNodes.ConstNode.extend(XB._calcNodes.IHasArguments);
XB._calcNodes.ProcNode = XB._calcNodes.ProcNodeBase.extend({
$name: "ProcNode",
perform: function ProcNode_perform(eventInfo) {
this._proc(eventInfo);
},
getValue: function ProcNode_getValue() {
return this._proc();
}
});
XB._calcNodes.FuncNodeBase = XB._calcNodes.DynNode.extend(XB._calcNodes.IHasArguments);
XB._calcNodes.FuncNode = XB._calcNodes.FuncNodeBase.extend({
$name: "FuncNode",
constructor: function FuncNode_constructor(baseUID, widget, argsMap, debugMode) {
this.base(baseUID, widget, argsMap);
this._changedArgs = [];
this._debugMode = !!debugMode;
},
freeze: function FuncNode_freeze() {
if (!this._hasSubscribers()) {
XB._base.logger.warn("Attempt to freeze " + this._getHumanReadableID() + ", which has no subscribers.");
return;
}
this._freezeLevel++;
if (this._debugMode)
this._parentWidget.logger.debug("Freezing node " + this._getHumanReadableID() + " " + this._freezeLevel);
this._freezeDeps();
},
melt: function FuncNode_melt(changedArgNode) {
if (this._freezeLevel == 0) return;
this._freezeLevel = Math.max(0, this._freezeLevel - 1);
var hasSubscribers = this._hasSubscribers();
if (changedArgNode)
this._changedArgs.push(changedArgNode);
if (this._debugMode)
this._parentWidget.logger.debug("Melting node " + this._getHumanReadableID() + ". Freeze level: " + this._freezeLevel +
", changed args: " + this._changedArgs.length + ", hasSubscribers: " + hasSubscribers);
var iChanged = false;
try {
if ((this._freezeLevel == 0) && (this._changedArgs.length > 0) && hasSubscribers) {
var newVal = this._calculateSafely();
if (this._debugMode)
this._parentWidget.logger.debug("Node " + this._getHumanReadableID() + " recalculated to " +
XB._base.runtime.describeValue(newVal));
iChanged = this._setNewVal(newVal);
}
}
finally {
this._changedArgs = [];
this._meltDeps(iChanged);
}
},
unsubscribe: function FuncNode_unsubscribe(subscriber) {
if ( !(subscriber.effectiveID in this._dependants) ) return;
try {
this.base(subscriber);
if (!this._hasSubscribers())
this._freezeLevel = 0;
}
finally {
for (let i = this._freezeLevel; i > 0; i--)
subscriber.melt(null);
}
},
getValue: function FuncNode_getValue(subscriber) {
var prevValue = this.base(subscriber);
if (prevValue === undefined) {
var newVal = this._calculateSafely();
if (this._hasSubscribers())
this._setNewVal(newVal);
return newVal;
}
return prevValue;
},
_freezeLevel: 0,
_changedArgs: null,
_debugMode: false,
_subscribe: function FuncNode_subscribe(subscriber) {
try {
this.base(subscriber);
}
finally {
for (let i = this._freezeLevel; i > 0; i--)
subscriber.freeze();
}
},
_calculateSafely: function FuncNode_calculateSafely() {
var val;
this._argManager.resetUseStat();
try {
val = this._calculate(this._changedArgs);
}
catch (e) {
if (e instanceof XB.types.Exception)
val = e;
else {
val = XB._base.runtime.createXBExceptionFromRTError(this.effectiveID, e);
this._parentWidget.logger.error(this._formatRuntimeError(e));
if (this._debugMode)
this._parentWidget.logger.debug(e.stack);
}
}
finally {
this._argManager.freeUnused();
}
return val;
}
});
XB._calcNodes.FuncNode.ArgManager = function FNArgManager_constructor(managedNode) {
if ( !(managedNode instanceof XB._calcNodes.FuncNode || managedNode instanceof XB._calcNodes.ProcNode) )
throw new TypeError(this._consts.ERR_FP_NODE_EXPECTED);
this._managedNode = managedNode;
this._namedArgs = {};
this._orderedArgs = [];
};
XB._calcNodes.FuncNode.ArgManager.prototype = {
constructor: XB._calcNodes.FuncNode.ArgManager,
attachArgument: function ArgMan_AttachArgument(argName, argNode) {
if (argName == "")
throw new Error(ERR_NAME_REQUIRED);
if ( !(argNode instanceof XB._calcNodes.BoundNode) )
throw new TypeError(XB._base.consts.ERR_FUNC_NODE_EXPECTED);
var argInfo = {
node: argNode,
used: false
};
this._argsCount = this._orderedArgs.push(argInfo);
this._namedArgs[argName] = argInfo;
},
detachArgument: function ArgMan_DetachArgument(argName) {
var argInfo = this._getArgInfoByName(argName);
argInfo.used = false;
argInfo.node.unsubscribe(this._managedNode);
delete this._namedArgs[argName];
},
resetUseStat: function ArgMan_ResetUseStat() {
for each (let argInfo in this._namedArgs)
argInfo.used = false;
},
freeUnused: function ArgMan_FreeUnused() {
for each (let argInfo in this._namedArgs) {
if (!argInfo.used)
argInfo.node.unsubscribe(this._managedNode);
}
},
freeAll: function ArgMan_FreeAll() {
for each (let argInfo in this._namedArgs) {
argInfo.used = false;
argInfo.node.unsubscribe(this._managedNode);
}
},
argExists: function ArgMan_ArgExists(argName) {
return (argName in this._namedArgs) && (this._namedArgs[argName] instanceof Object);
},
get argsNames() {
var names = [];
for (let name in this._namedArgs)
names.push(name);
return names;
},
getValByName: function ArgMan_GetValByName(argName, preferedType) {
return this._processArgInfo(this._getArgInfoByName(argName), preferedType);
},
getValByIndex: function ArgMan_GetValByIndex(argIndex, preferedType) {
return this._processArgInfo(this._getArgInfoByIndex(argIndex), preferedType);
},
getValByNameDef: function ArgMan_GetValByNameDef(argName, preferedType, defaultValue) {
if ( !this.argExists(argName) )
return defaultValue;
return this._processArgInfo(this._getArgInfoByName(argName), preferedType, defaultValue);
},
getValByIndexDef: function ArgMan_GetValByIndexDef(argIndex, preferedType, defaultValue) {
if ( !(argIndex in this._orderedArgs) )
return defaultValue;
return this._processArgInfo(this._getArgInfoByIndex(argIndex), preferedType, defaultValue);
},
findNodeByName: function ArgMan_GetNodeByName(argName) {
var argInfo = this._namedArgs[argName];
if (argInfo) {
argInfo.used = true;
return argInfo.node;
}
return null;
},
findNodeByIndex: function ArgMan_GetNodeByIndex(argIndex) {
var argInfo = this._orderedArgs[argIndex];
if (argInfo) {
argInfo.used = true;
return argInfo.node;
}
return null;
},
get argsCount() {
return this._argsCount;
},
argInArray: function (argName, array) {
if (!(array instanceof Array))
throw new TypeError("Array expected");
var argNode = this.findNodeByName(argName);
if (!argNode)
return false;
for each (let item in array) {
if (item === argNode)
return true;
}
return false;
},
_consts: {
ERR_FP_NODE_EXPECTED: "FuncNode or ProcNode instance expected",
ERR_NO_ARG: "No such argument"
},
_managedNode: null,
_namedArgs: null,
_orderedArgs: null,
_argsCount: 0,
_getArgInfoByName: function ArgMan_getArgInfoByName(argName) {
if ( !(argName in this._namedArgs) )
throw new Error(this._consts.ERR_NO_ARG + ": \"" + argName + "\"");
return this._namedArgs[argName];
},
_getArgInfoByIndex: function ArgMan_getArgInfoByName(argIndex) {
if ( !(argIndex in this._orderedArgs) )
throw new Error(this._consts.ERR_NO_ARG + ": " + argIndex);
return this._orderedArgs[argIndex];
},
_processArgInfo: function ArgMan_processArgInfo(argInfo, preferedType, defaultValue) {
if (argInfo == undefined)
throw new Error(this._consts.ERR_NO_ARG);
argInfo.used = true;
var argVal = argInfo.node.getValue(this._managedNode._hasSubscribers()? this._managedNode: null);
if (argVal instanceof XB.types.Exception)
throw argVal;
try {
switch(preferedType) {
case "Number":
return XB._base.runtime.xToNumber(argVal);
case "String":
return XB._base.runtime.xToString(argVal);
case "Bool":
return XB._base.runtime.xToBool(argVal);
case "XML":
return XB._base.runtime.xToXML(argVal);
case "RequestData":
return XB._base.runtime.xToRequestData(argVal);
default:
return argVal;
}
}
catch (e) {
if ((e instanceof XB.types.Exception) || (defaultValue == undefined))
throw e;
return defaultValue;
}
}
};
XB._calcNodes.Persistent = XB._calcNodes.DynNode.extend({
$name: "Persistent",
constructor: function FPersistentNode_constructor(baseUID, widgetInstance, persistCategory, persistKey, defaultValue) {
this._defaultValue = defaultValue || XB.types.empty;
this.base(baseUID, widgetInstance, this._defaultValue);
if (!persistCategory)
throw new Error(this._consts.ERR_PCATEGORY_EXPECTED);
this._persistCategory = persistCategory;
if (!persistKey)
throw new Error(this._consts.ERR_PKEY_EXPECTED);
this._persistKey = persistKey;
this._widgetProtoID = (widgetInstance instanceof XB._Parser.Unit.WidgetInstance)?
widgetInstance.prototype.id:
widgetInstance.id;
this._prefsModule = XB._base.application.core.Preferences;
let storedPref = this._prefsModule.get(this._prefFullPath);
if (storedPref !== undefined) {
this._dontWrite = true;
try {
this._setNewVal(storedPref);
}
finally {
this._dontWrite = false;
}
}
this._prefsModule.observe(this._prefFullPath, this);
},
finalize: function FPersistentNode_finalize() {
this._prefsModule.ignore(this._prefFullPath, this);
this._dontWrite = true;
this.base();
},
get defaultValue() {
return this._defaultValue;
},
erase: function FPersistentNode_erase() {
this._erasing = true;
try {
this._prefsModule.reset(this._prefFullPath);
}
finally {
this._erasing = false;
}
},
observe: function FPersistentNode_observe(subject, topic, data) {
if (this._erasing) return;
var prefPath = data;
this._parentWidget.logger.debug("Persistent node " + prefPath + " observes " + topic);
var value = this._prefsModule.get(prefPath, this._defaultValue);
this._dontWrite = true;
try {
if (this._setNewVal(value))
this._notifyDeps();
}
finally {
this._dontWrite = false;
}
},
_consts: {
ERR_PCATEGORY_EXPECTED: "Persist category expected",
ERR_PKEY_EXPECTED: "Persist key expected"
},
_prefsModule: null,
_persistCategory: undefined,
_persistKey: undefined,
_dontWrite: false,
_erasing: false,
_setNewVal: function FPersistentNode_set(value) {
if (value === undefined)
return undefined;
var reset = (typeof this._storedValue) !== (typeof value);
var changed = this.base(value);
if (changed && !this._dontWrite) {
this._parentWidget.logger.debug("Persistent node " + this._prefFullPath + " writes new value " + value);
this._prefsModule.ignore(this._prefFullPath, this);
try {
if (reset)
this._prefsModule.reset(this._prefFullPath);
if (!XB._base.runtime.isXML(value))
this._prefsModule.set(this._prefFullPath, value);
}
finally {
this._prefsModule.observe(this._prefFullPath, this);
}
}
return changed;
},
get _prefFullPath() {
let prefPath = XB._base.application.name + ".xbwidgets." + this._widgetProtoID + ".";
if (this._parentWidget instanceof XB._Parser.Unit.WidgetInstance) {
prefPath += (this._parentWidget.id + ".");
}
else
prefPath += "all.";
prefPath += (this._persistCategory + "." + this._persistKey);
delete this._fullPrefPath;
this._fullPrefPath = prefPath;
return prefPath;
}
});
XB._calcNodes.Persistent.implement(XB._calcNodes.IVariable);
XB._calcNodes.SettingNode = XB._calcNodes.Persistent.extend({
constructor: function FSettingNode_constructor(baseUID, widgetInstance, prefName, defaultValue) {
this.base(baseUID, widgetInstance, "settings", prefName, defaultValue);
}
});
XB._calcNodes.PersistentVarNode = XB._calcNodes.Persistent.extend({
constructor: function FPersistentVarNode_constructor(baseUID, widgetInstance, varName, defaultValue) {
this.base(baseUID, widgetInstance, "variables", varName, defaultValue);
}
});